-
Notifications
You must be signed in to change notification settings - Fork 3
160 lines (134 loc) · 5.55 KB
/
be_cd-production.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: Coduo Backend Production Server CD
on:
push:
branches: [ "production" ]
jobs:
build:
environment: production
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./backend
steps:
- name: checkout
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'corretto'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
cache-write-only: true
- name: Grant Execute Permission For Gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew bootJar
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_ID }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Image build and push
run: |
docker build --build-arg PROFILE=prod --build-arg DEPENDENCY=build/dependency -t ${{ secrets.DOCKER_REPO_NAME }}/springboot-app:test-latest --platform linux/arm64 .
docker push ${{ secrets.DOCKER_REPO_NAME }}/springboot-app:test-latest
- name: Upload docker-compose yaml script to artifact
uses: actions/upload-artifact@v4
with:
name: docker-compose
path: ${{ github.workspace }}/backend/be_app-docker-compose.yml
deployA:
environment: production
runs-on: production-ec2-A-runner
needs: build
defaults:
run:
working-directory: ./backend
steps:
- name: Set docker-compose YAML script to runner
uses: actions/download-artifact@v4
with:
name: docker-compose
path: ${{ github.workspace }}/backend
- name: Move docker-compose YAML
run: |
sudo mv be_app-docker-compose.yml ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/
- name: Extract secrets as .be_app-env file
run: |
cat <<EOF > ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env
# Docker Hub info from Github Secrets
DOCKER_REPO_NAME=${{ secrets.DOCKER_REPO_NAME }}
# DB Configuration secrets info from Github Secrets
MYSQL_DB_NAME=${{ secrets.MYSQL_DB_NAME }}
MYSQL_TIME_ZONE=${{ secrets.MYSQL_TIME_ZONE }}
DB_BINDING_PORT=${{ secrets.DB_BINDING_PORT }}
DOCKER_DATA_PATH=${{ secrets.DOCKER_DATA_PATH }}
DB_URL=${{ secrets.DB_URL }}
DB_USERNAME=${{ secrets.DB_USERNAME }}
DB_PASSWORD=${{ secrets.DB_PASSWORD }}
DDL_AUTO=${{ secrets.DDL_AUTO }}
# OAUTH & JWT
CLIENT_ID=${{ secrets.CLIENT_ID }}
CLIENT_SECRET=${{ secrets.CLIENT_SECRET }}
CLIENT_REDIRECT_URI=${{ secrets.CLIENT_REDIRECT_URI }}
JWT_KEY=${{ secrets.JWT_KEY}}
# Server App
SERVER_BINDING_PORT=${{ secrets.SERVER_BINDING_PORT }}
SERVER_LOGS_PATH=${{ secrets.SERVER_LOGS_PATH }}
EOF
- name: Stop and remove existing containers
run: |
sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml down --rmi all
- name: Deploy docker container
run: |
sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml up -d
deployB:
environment: production
runs-on: coduo_runner_production-server
needs: deployA
defaults:
run:
working-directory: ./backend
steps:
- name: Set docker-compose YAML script to runner
uses: actions/download-artifact@v4
with:
name: docker-compose
path: ${{ github.workspace }}/backend
- name: Move docker-compose YAML
run: |
sudo mv be_app-docker-compose.yml ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/
- name: waiting deployA complete
run: |
sudo ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/scheduler.sh
- name: Extract secrets as .be_app-env file
run: |
cat <<EOF > ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env
# Docker Hub info from Github Secrets
DOCKER_REPO_NAME=${{ secrets.DOCKER_REPO_NAME }}
# DB Configuration secrets info from Github Secrets
MYSQL_DB_NAME=${{ secrets.MYSQL_DB_NAME }}
MYSQL_TIME_ZONE=${{ secrets.MYSQL_TIME_ZONE }}
DB_BINDING_PORT=${{ secrets.DB_BINDING_PORT }}
DOCKER_DATA_PATH=${{ secrets.DOCKER_DATA_PATH }}
DB_URL=${{ secrets.DB_URL }}
DB_USERNAME=${{ secrets.DB_USERNAME }}
DB_PASSWORD=${{ secrets.DB_PASSWORD }}
DDL_AUTO=${{ secrets.DDL_AUTO }}
# OAUTH & JWT
CLIENT_ID=${{ secrets.CLIENT_ID }}
CLIENT_SECRET=${{ secrets.CLIENT_SECRET }}
CLIENT_REDIRECT_URI=${{ secrets.CLIENT_REDIRECT_URI }}
JWT_KEY=${{ secrets.JWT_KEY}}
# Server App
SERVER_BINDING_PORT=${{ secrets.SERVER_BINDING_PORT }}
SERVER_LOGS_PATH=${{ secrets.SERVER_LOGS_PATH }}
EOF
- name: Stop and remove existing containers
run: |
sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml down --rmi all
- name: Deploy docker container
run: |
sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml up -d