-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (80 loc) ยท 2.83 KB
/
deploy.yml
File metadata and controls
97 lines (80 loc) ยท 2.83 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
name: Deploy screenwiper_back
on:
push:
branches: [ 'main' ]
jobs:
ci:
runs-on: ubuntu-20.04
outputs:
docker-tag: ${{ steps.set-docker-tag.outputs.DOCKER_TAG }}
defaults:
run:
working-directory: screenwiper
steps:
- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.GIT_TOKEN }}
submodules: true
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: 21
distribution: 'temurin'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew clean build -x test
- name: Get current time
id: current-time
uses: josStorer/get-current-time@v2.0.2
with:
format: YYYY-MM-DDTHH-mm-ss
utcOffset: "+09:00"
- name: Docker build
run: |
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }}
docker build -f ./Dockerfile -t yusiny/screenwiper_back:${{ steps.current-time.outputs.formattedTime }} .
docker push yusiny/screenwiper_back:${{ steps.current-time.outputs.formattedTime }}
- name: Set Docker Tag Output
id: set-docker-tag
run: echo 'DOCKER_TAG=${{ steps.current-time.outputs.formattedTime }}' >> $GITHUB_OUTPUT
cd:
runs-on: ubuntu-20.04
needs: [ci]
env:
DOCKER_TAG: ${{ needs.ci.outputs.docker-tag }}
steps:
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
# Check docker tags
echo "๐ณ Docker Tag: ${{ env.DOCKER_TAG }}"
# Pull the new image
echo "๐ณ Docker Image Pull"
docker pull yusiny/screenwiper_back:${{ env.DOCKER_TAG }}
# Stop & Remove existing container if exists
if [ $(docker ps -aq -f name=screenwiper_back) ]; then
echo "๐ณ Docker Stop"
docker stop screenwiper_back || true
echo "๐ณ Docker Remove"
docker rm screenwiper_back || true
fi
# Start new container
echo "๐ณ Docker Run"
docker run -d --name screenwiper_back \
-p 8080:8080 \
--log-driver json-file \
--log-opt max-size=10m \
--log-opt max-file=3 \
yusiny/screenwiper_back:${{ env.DOCKER_TAG }}
# Check
echo "๐ณ Docker ps"
docker ps
# Cleanup old images
echo "๐งน Cleaning up old Docker images"
docker rmi -f $(docker images -q) || true