-
Notifications
You must be signed in to change notification settings - Fork 2
96 lines (81 loc) · 2.75 KB
/
Copy pathdeploy-server.yml
File metadata and controls
96 lines (81 loc) · 2.75 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
name: deploy CI/CD on branch 'main'
on:
push:
branches: [ main ]
jobs:
# Ticketing API Module CI
build-api-module:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: temurin
java-version: '17'
- name: Build API module
run: ./gradlew build -x test
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build & Push API image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/codin-ticketing-api:latest
# Ticketing SSE Module CI
build-sse-module:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: temurin
java-version: '17'
- name: Build SSE module
working-directory: codin-ticketing-sse
run: ./gradlew build -x test
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build & Push SSE image
uses: docker/build-push-action@v5
with:
context: codin-ticketing-sse
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/codin-ticketing-sse:latest
# Ticketing (API + SSE) CD
deploy:
needs: [build-api-module, build-sse-module]
runs-on: ubuntu-22.04
steps:
- name: Deploy to server via SSH
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
passphrase: ${{ secrets.SSH_KEY_PASSPHRASE }}
port: ${{ secrets.PORT }}
script: |
echo ${{ secrets.PASSWORD }} | sudo -S su -c "
docker ps -a
cd /opt/project/codin-ticketing
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/codin-ticketing-api:latest
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/codin-ticketing-sse:latest
docker rm -f codin-ticketing-api || true
docker rm -f codin-ticketing-sse || true
docker compose -f ticketing-docker-compose.yml up -d
docker images -f "dangling=true" -q | xargs sudo docker rmi || true
docker ps -a
"