-
Notifications
You must be signed in to change notification settings - Fork 1
99 lines (85 loc) · 3.3 KB
/
api-deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Street Drop CI/CD
on:
push:
branches: [ "main" ]
paths:
- "backend/streetdrop-api/**"
- "backend/streetdrop-domain/**"
- "backend/streetdrop-common/**"
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set up JDK 19
uses: actions/setup-java@v3
with:
java-version: '19'
distribution: 'temurin'
- name: Grant execute permission for gradlew
working-directory: ./backend
run: chmod +x gradlew
- name: Build with Gradle
working-directory: ./backend
run: ./gradlew clean build --exclude-task test
- name: Cache Gradle package
uses: actions/cache@v1
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Login To DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push Docker image
uses: docker/[email protected]
with:
context: .
file: ./backend/streetdrop-api/Dockerfile
push: true
build-args: |
DB_URL=${{ secrets.DB_URL }}
DB_USERNAME=${{ secrets.DB_USERNAME }}
DB_PASSWORD=${{ secrets.DB_PASSWORD }}
SWAGGER_SERVER_URL=${{ secrets.SWAGGER_SERVER_URL }}
AWS_ACCESS_KEY=${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_KEY=${{ secrets.AWS_SECRET_KEY }}
AWS_BUCKET_NAME=${{ secrets.AWS_BUCKET_NAME }}
AWS_REGION=${{ secrets.AWS_REGION }}
SLACK_TOEKN=${{ secrets.SLACK_TOKEN }}
tags: |
${{ secrets.DOCKER_REPO }}/street-drop-api-server:latest
- name: Get Github IP
id: ip
uses: haythem/[email protected]
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2
- name: Add GitHub IP to AWS
run: |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
password: ${{ secrets.EC2_PASSWORD }}
port: ${{ secrets.EC2_SSH_PORT }}
timeout: 60s
script: |
cd street-drop-server/
sudo docker rm - f $(docker ps -qa)
sudo docker pull ${{ secrets.DOCKER_REPO }}/street-drop-api-server:latest
sudo docker stop $(sudo docker ps -aq)
sudo docker run -d ${{ secrets.DOCKER_REPO }}/street-drop-api-server:latest \
--name street-drop-api \
-p 8080:8080 street-drop-api \
- name: Remove IP FROM security group
run: |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32