-
Notifications
You must be signed in to change notification settings - Fork 1
188 lines (166 loc) · 6.3 KB
/
CD.yml
File metadata and controls
188 lines (166 loc) · 6.3 KB
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
name: Code Delivery
on:
push:
branches:
- develop
- release
jobs:
deploy-ci:
runs-on: ubuntu-latest
env:
working-directory: .
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '21'
- name: Create application-dev.yml (develop)
if: ${{ github.ref_name == 'develop' }}
env:
APPLICATION_DEV_YML: ${{ secrets.APPLICATION_DEV_YML }}
run: |
python3 - <<'PY'
import os, pathlib
p = pathlib.Path("src/main/resources/application-dev.yml")
p.parent.mkdir(parents=True, exist_ok=True)
p.write_text(os.environ["APPLICATION_DEV_YML"], encoding="utf-8")
PY
- name: Create gradle.properties (develop)
if: ${{ github.ref_name == 'develop' }}
env:
GRADLE_DEV_PROPERTIES: ${{ secrets.GRADLE_DEV_PROPERTIES }}
run: |
python3 - <<'PY'
import os, pathlib
p = pathlib.Path("gradle.properties")
p.write_text(os.environ["GRADLE_DEV_PROPERTIES"], encoding="utf-8")
PY
- name: Create application-prod.yml (release)
if: ${{ github.ref_name == 'release' }}
env:
APPLICATION_PROD_YML: ${{ secrets.APPLICATION_PROD_YML }}
run: |
python3 - <<'PY'
import os, pathlib
p = pathlib.Path("src/main/resources/application-prod.yml")
p.parent.mkdir(parents=True, exist_ok=True)
p.write_text(os.environ["APPLICATION_PROD_YML"], encoding="utf-8")
PY
- name: Create gradle.properties (release)
if: ${{ github.ref_name == 'release' }}
env:
GRADLE_PROD_PROPERTIES: ${{ secrets.GRADLE_PROD_PROPERTIES }}
run: |
python3 - <<'PY'
import os, pathlib
p = pathlib.Path("gradle.properties")
p.write_text(os.environ["GRADLE_PROD_PROPERTIES"], encoding="utf-8")
PY
- name: Build with Gradle
run: |
chmod +x gradlew
./gradlew build -x test
working-directory: ${{ env.working-directory }}
- name: docker buildx setup
uses: docker/setup-buildx-action@v2.9.1
- name: Docker Hub Login
uses: docker/login-action@v2.2.0
with:
username: ${{ secrets.DOCKERHUB_LOGIN_USERNAME }}
password: ${{ secrets.DOCKERHUB_LOGIN_ACCESSTOKEN }}
- name: Build and Push Docker Image (develop -> dev-latest)
if: ${{ github.ref_name == 'develop' }}
uses: docker/build-push-action@v4
with:
context: .
file: ./docker/Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_LOGIN_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:dev-latest
- name: Build and Push Docker Image (release -> prod-latest)
if: ${{ github.ref_name == 'release' }}
uses: docker/build-push-action@v4
with:
context: .
file: ./docker/Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_LOGIN_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:prod-latest
deploy-cd:
needs: deploy-ci
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Upload nginx config to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SERVER_PUBLIC_IP }}
username: ubuntu
key: ${{ secrets.EC2_ACCESS_KEY }}
source: ./nginx
target: /home/ubuntu/solply-server/
- name: Upload observability files
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SERVER_PUBLIC_IP }}
username: ubuntu
key: ${{ secrets.EC2_ACCESS_KEY }}
source: docker/observability
target: /home/ubuntu/solply-server/
- name: Upload edge compose file
uses: appleboy/ssh-action@master
with:
username: ubuntu
host: ${{ secrets.SERVER_PUBLIC_IP }}
key: ${{ secrets.EC2_ACCESS_KEY }}
script: |
set -e
mkdir -p /home/ubuntu/solply-server/env/edge
echo "${{ secrets.DOCKER_COMPOSE_EDGE_YML_BASE64 }}" | base64 -d > /home/ubuntu/solply-server/env/edge/docker-compose.yml
- name: Bring up edge and reload nginx
uses: appleboy/ssh-action@master
with:
username: ubuntu
host: ${{ secrets.SERVER_PUBLIC_IP }}
key: ${{ secrets.EC2_ACCESS_KEY }}
script: |
set -e
EDGE_FILE=/home/ubuntu/solply-server/env/edge/docker-compose.yml
docker compose -p solply-edge -f $EDGE_FILE up -d
docker compose -p solply-edge -f $EDGE_FILE exec -T nginx nginx -s reload || true
- name: Upload deploy.sh to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SERVER_PUBLIC_IP }}
username: ubuntu
key: ${{ secrets.EC2_ACCESS_KEY }}
source: ./scripts/deploy.sh
target: /home/ubuntu/solply-server/
- name: Deploy to EC2 (dev)
if: ${{ github.ref_name == 'develop' }}
uses: appleboy/ssh-action@master
with:
username: ubuntu
host: ${{ secrets.SERVER_PUBLIC_IP }}
key: ${{ secrets.EC2_ACCESS_KEY }}
script: |
set -e
mkdir -p /home/ubuntu/solply-server/env/dev
echo "${{ secrets.DOCKER_COMPOSE_DEV_YML_BASE64 }}" | base64 -d > /home/ubuntu/solply-server/env/dev/docker-compose.yml
chmod +x /home/ubuntu/solply-server/scripts/deploy.sh
/home/ubuntu/solply-server/scripts/deploy.sh dev up
- name: Deploy to EC2 (prod)
if: ${{ github.ref_name == 'release' }}
uses: appleboy/ssh-action@master
with:
username: ubuntu
host: ${{ secrets.SERVER_PUBLIC_IP }}
key: ${{ secrets.EC2_ACCESS_KEY }}
script: |
set -e
mkdir -p /home/ubuntu/solply-server/env/prod
echo "${{ secrets.DOCKER_COMPOSE_PROD_YML_BASE64 }}" | base64 -d > /home/ubuntu/solply-server/env/prod/docker-compose.yml
chmod +x /home/ubuntu/solply-server/scripts/deploy.sh
/home/ubuntu/solply-server/scripts/deploy.sh prod up