-
Notifications
You must be signed in to change notification settings - Fork 0
73 lines (59 loc) · 2.32 KB
/
cd.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
name: Backend Server CD
on:
push:
branches:
- main
- develop
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Execute Gradle build
run: ./gradlew clean build
- name: List JAR Files
run: |
ls -la build/libs/
- name: Set up Docker Build
uses: docker/setup-buildx-action@v2
- name : Set up SSH Key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.EC2_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
- name : Copy docker-compose.yml and deploy.sh to EC2
run: |
scp -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ./docker-compose.yml [email protected]:/home/ec2-user
scp -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ./deploy.sh [email protected]:/home/ec2-user
- name: Docker build and push to Docker Hub and copy docker-compose.yml to server
run: |
sudo docker login -u ${{ secrets.DOCKER_ID }} -p ${{ secrets.DOCKER_PASSWORD }}
cd ./api-server
sudo docker buildx build --push --platform linux/amd64 -t ${{ secrets.DOCKER_USERNAME }}/server .
sudo docker push ${{ secrets.DOCKER_USERNAME }}/server
cd ../batch
sudo docker buildx build --push --platform linux/amd64 -t ${{ secrets.DOCKER_USERNAME }}/batch .
sudo docker push ${{ secrets.DOCKER_USERNAME }}/batch
- name: Deploy to Prod
uses: appleboy/ssh-action@master
with:
key: ${{ secrets.EC2_PRIVATE_KEY }}
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
port: 22
script: |
sudo docker login -u ${{ secrets.DOCKER_ID }} -p ${{ secrets.DOCKER_PASSWORD }}
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/server
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/batch
sudo chmod +x deploy.sh
sudo chmod +x docker-compose.yml
sudo ./deploy.sh
sudo docker image prune -f