-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (71 loc) · 2.94 KB
/
prod-deploy-aws.yaml
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
name: Deploy EC2
on:
push:
branches: [ master ]
env:
DOCKER_REPO_NAME: ${{ secrets.DOCKER_REPO_NAME }}
SHA: ${{ github.sha }}
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17
- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: ${{ runner.os }}-gradle-
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Create application-prod.properties
run: |
touch src/main/resources/application-prod.properties
echo "$PROD_SPRING_PROPERTIES" > application-prod.properties.b64
base64 -d -i application-prod.properties.b64 > src/main/resources/application-prod.properties
env:
PROD_SPRING_PROPERTIES: ${{ secrets.PROD_SPRING_PROPERTIES }}
- name: Build with Gradle
run: |
./gradlew clean build -Pprofile=prod --exclude-task test
- name: Docker Build
run: |
docker build --tag boo10500/$DOCKER_REPO_NAME:jmt-image-$GITHUB_SHA . -f Dockerfile-prod
- name: Docker Push
run: |
docker login --username=boo10500 --password=${{ secrets.DOCKER_USER_PW }}
docker push boo10500/$DOCKER_REPO_NAME:jmt-image-$GITHUB_SHA
# - name: Create SSH Private Key
# run: |
# touch gdsc-dju-jmt.pem
# echo "$EC2_SSH_KEY" > gdsc-dju-jmt.pem
# chmod 400 gdsc-dju-jmt.pem
# env:
# EC2_SSH_KEY: ${{ secrets.EC2_SSH_KEY }}
# - name: EC2 Docker Deploy and Run
# run: |
# ssh -t -i ./gdsc-dju-jmt.pem -o UserKnownHostsFile=/github/home/.ssh/known_hosts ubuntu@${{ secrets.EC2_HOST }} '
# sudo docker ps -aq --filter "name=jmt" | xargs docker stop | xargs docker rm &&
# sudo docker image prune -a -f &&
# sudo docker pull boo10500/"'$DOCKER_REPO_NAME'":jmt-image-"'$GITHUB_SHA'" &&
# sudo docker run -d -p 8080:8080 --name jmt boo10500/"'$DOCKER_REPO_NAME'":jmt-image-"'$GITHUB_SHA'"
# '
- name: EC2 Docker Deploy and Run
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
envs: DOCKER_REPO_NAME, SHA
script: |
sudo docker ps -aq --filter "name=jmt-prod" | xargs sudo docker stop | xargs sudo docker rm
sudo docker image prune -a -f
sudo docker pull boo10500/$DOCKER_REPO_NAME:jmt-image-$SHA
sudo docker run -d -p 8080:8080 --name jmt-prod boo10500/$DOCKER_REPO_NAME:jmt-image-$SHA