-
Notifications
You must be signed in to change notification settings - Fork 0
125 lines (106 loc) · 3.52 KB
/
be-cd-dev.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
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
name: Backend CD Develop
on:
push:
branches:
- be/dev
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
environment: test
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
cache: gradle
- name: Cache Gradle
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/build.gradle') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Add execute permissions
working-directory: ./backend
run: chmod +x ./gradlew
- name: Build
working-directory: ./backend
run: ./gradlew build -x test -x bootJar
- name: Test and Create OAS
env:
JASYPT_PASSWORD: ${{ secrets.JASYPT_PASSWORD }}
working-directory: ./backend
run: ./gradlew copyOasToSwagger
- name: Create bootJar
working-directory: ./backend
run: ./gradlew bootJar
- name: Build Docker image
working-directory: ./backend
run: |
docker build \
-f Dockerfile-dev \
-t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }}:dev \
.
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push Docker image
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }}:dev
deploy:
needs: build
runs-on: ubuntu-latest
environment: dev
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Send docker compose
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
strip_components: 2
source: backend/docker/docker-compose-dev.yaml
target: ~/${{ github.event.repository.name }}
- name: Rename docker compose file
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
cd ~/${{ github.event.repository.name }}
mv docker-compose-dev.yaml docker-compose.yaml
- name: Set up environment variables
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
cd ~/${{ github.event.repository.name }}
echo "MYSQL_DATABASE=${{ secrets.MYSQL_DATABASE }}" > .env
echo "MYSQL_ROOT_PASSWORD=${{ secrets.MYSQL_ROOT_PASSWORD }}" >> .env
echo "JASYPT_PASSWORD=${{ secrets.JASYPT_PASSWORD }}" >> .env
- name: Run new docker compose
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
cd ~/${{ github.event.repository.name }}
docker compose pull
docker compose down
docker compose up -d
docker image prune -af