-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (107 loc) · 4.16 KB
/
cicd-release.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
name: Release Deploy
on:
push:
branches:
- 'release-**'
env:
REGISTRY: ghcr.io
REPOSITORY: ${{ github.repository }}
GITHUB_ACTOR: ${{ github.actor }}
jobs:
releaseDeploy:
name: Deploy to Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.TOKEN_GITHUB }}
submodules: recursive
- name: Git Submodule Update
run: |
git submodule update --remote --recursive
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.GITHUB_ACTOR }}
password: ${{ secrets.TOKEN_GITHUB }}
- name: lowercase the image tag & repository
run: |
echo "REPOSITORY=$(echo $REPOSITORY | tr '[:upper:]' '[:lower:]')" >> ${GITHUB_ENV}
- name: Get Version
run: |
echo "VERSION=$( echo ${{ github.ref_name }} | cut -c 9- )" >> ${GITHUB_ENV}
- name: Set Spring Image Environment Variable
run: |
echo "SPRING_IMAGE=${{ env.REGISTRY }}/${{ env.REPOSITORY }}-release:${{ env.VERSION }}" >> ${GITHUB_ENV}
- name: Write Version
run: |
echo -e "\nserver-version: ${{ env.VERSION }}" >> config/application-release.yml
- name: Build Image
run: docker build --no-cache -t ${{ env.SPRING_IMAGE }} -f Dockerfile-deploy .
- name: Push
run: docker push ${{ env.SPRING_IMAGE }}
- name: Write Docker Image Tag Information to .env File
run: |
echo -e "\nSPRING_IMAGE=${{ env.SPRING_IMAGE }}" >> config/env/release.env
- name: Copy docker-compose.yml
uses: appleboy/scp-action@master
with:
host: ${{ secrets.RELEASE_SSH_HOST }}
port: ${{ secrets.RELEASE_SSH_PORT }}
username: ${{ secrets.RELEASE_SSH_USERNAME }}
key: ${{ secrets.RELEASE_SSH_PRIVATE_KEY }}
source: "docker-compose.release.yml, config/env/release.env"
target: /home/ec2-user
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.RELEASE_SSH_HOST }}
port: ${{ secrets.RELEASE_SSH_PORT }}
username: ${{ secrets.RELEASE_SSH_USERNAME }}
key: ${{ secrets.RELEASE_SSH_PRIVATE_KEY }}
script: |
cd /home/ec2-user
sudo docker login ${{ env.REGISTRY }} -u ${{ env.GITHUB_ACTOR }} -p ${{ secrets.TOKEN_GITHUB }}
sudo docker container stop spring
sudo docker container rm spring
sudo docker image rm ${{ env.SPRING_IMAGE }}
sudo docker-compose --env-file=config/env/release.env -f docker-compose.release.yml -p backend up -d
sudo docker image prune -af
releaseExport:
name: Export Release Jar
runs-on: ubuntu-latest
needs: releaseDeploy
steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.GITHUB_ACTOR }}
password: ${{ secrets.TOKEN_GITHUB }}
- name: lowercase the image tag & repository
run: |
echo "REPOSITORY=$(echo $REPOSITORY | tr '[:upper:]' '[:lower:]')" >> ${GITHUB_ENV}
- name: Get Version
run: |
echo "VERSION=$( echo ${{ github.ref_name }} | cut -c 9- )" >> ${GITHUB_ENV}
- name: Set Spring Image Environment Variable
run: |
echo "SPRING_IMAGE=${{ env.REGISTRY }}/${{ env.REPOSITORY }}-release:${{ env.VERSION }}" >> ${GITHUB_ENV}
- name: Run Container
run: docker run -d --name container-capple ${{ env.SPRING_IMAGE }}
- name: Extract .jar File From Container
run: docker cp container-capple:/app/app.jar .
- name: Stop Container
run: docker rm -f container-capple
- name: Rename Jar
run: mv app.jar capple-${{ env.VERSION }}.jar
- name: Extract .jar File
uses: actions/upload-artifact@v4
with:
name: capple-${{ env.VERSION }}
path: ./*.jar
compression-level: 9
retention-days: 1
overwrite: true