-
Notifications
You must be signed in to change notification settings - Fork 2
77 lines (66 loc) · 3.28 KB
/
cicd.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
name: DockerCompose With Gradle
on:
push:
branches:
- main
- dev
permissions: write-all
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'corretto'
- name: Add permission
run: chmod +x gradlew
- name: Clean before Build
run: ./gradlew clean
- name: Inject Secret values into application-test.yml
run: |
sed -i "s|# MYSQL_URL|url: '${{ secrets.DB_URL }}'|" src/main/resources/application-test.yml
sed -i "s|# MYSQL_USERNAME|username: '${{ secrets.DB_USERNAME }}'|" src/main/resources/application-test.yml
sed -i "s|# MYSQL_PASSWORD|password: '${{ secrets.DB_PASSWORD }}'|" src/main/resources/application-test.yml
sed -i "s|# SMTP_EMAIL|username: '${{ secrets.SMTP_EMAIL }}'|" src/main/resources/application-test.yml
sed -i "s|# SMTP_PASSWORD|password: '${{ secrets.SMTP_PASSWORD }}'|" src/main/resources/application-test.yml
sed -i "s|# SMTP_HOST|host: '${{ secrets.SMTP_HOST }}'|" src/main/resources/application-test.yml
sed -i "s|# SMTP_PORT|port: '${{ secrets.SMTP_PORT }}'|" src/main/resources/application-test.yml
sed -i "s|# REDIS_HOST|host: '${{ secrets.REDIS_HOST }}'|" src/main/resources/application-test.yml
sed -i "s|# REDIS_PORT|port: '${{ secrets.REDIS_PORT }}'|" src/main/resources/application-test.yml
sed -i "s|# S3_BUCKET_NAME|bucket: '${{ secrets.S3_BUCKET_NAME }}'|" src/main/resources/application-test.yml
sed -i "s|# S3_ACCESS_KEY|access-key: '${{ secrets.S3_ACCESS_KEY }}'|" src/main/resources/application-test.yml
sed -i "s|# S3_SECRET_KEY|secret-key: '${{ secrets.S3_SECRET_KEY }}'|" src/main/resources/application-test.yml
sed -i "s|# S3_BUCKET_REGION|static: '${{ secrets.S3_BUCKET_REGION }}'|" src/main/resources/application-test.yml
sed -i "s|# JWT_SECRET|secret-key: '${{ secrets.JWT_SECRET }}'|" src/main/resources/application-test.yml
shell: bash
env:
JAVA_HOME: /opt/hostedtoolcache/Java_Corretto_jdk/17.0.11-9.1/x64
JAVA_HOME_17_X64: /opt/hostedtoolcache/Java_Corretto_jdk/17.0.11-9.1/x64
- name: Docker Build & Push
run: |
docker login -u ${{ secrets.DOCKER_ID }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build --platform linux/amd64 -t ${{ secrets.DOCKER_REPO }} .
docker push ${{ secrets.DOCKER_REPO }}
- name: SSH Connection & Deploy
uses: appleboy/ssh-action@master
env:
APP: "docker-project"
COMPOSE: "/home/ubuntu/compose/docker-compose.yml"
S3_ACCESS_KEY: ${{ secrets.S3_ACCESS_KEY }}
S3_SECRET_KEY: ${{ secrets.S3_SECRET_KEY }}
with:
username: ubuntu
host: ${{ secrets.EC2_HOST }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
envs: APP, COMPOSE, S3_ACCESS_KEY, S3_SECRET_KEY
script_stop: true
script: |
sudo docker-compose -f $COMPOSE down
sudo docker pull ${{ secrets.DOCKER_REPO }}
sudo docker-compose -f $COMPOSE up -d
timeout: 30s
command_timeout: 10m
debug: true