-
Notifications
You must be signed in to change notification settings - Fork 0
103 lines (89 loc) · 3.39 KB
/
dev_deploy.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
name: dev deployment
on:
push:
branches:
- develop
jobs:
application_build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: java setting
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '17'
- name: gradle setting
run: |
chmod +x gradlew
./gradlew build
- name: upload artifact
uses: actions/upload-artifact@v2
with:
name: application
path: build/libs/*.jar
push_to_docker_hub:
needs: application_build
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.generate_version.outputs.new_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: application
path: build/libs
- name: Generate Version
id: generate_version
run: |
current_date=$(date -d "9 hours" +%Y-%m-%d)
current_date_short_year=$(date -d "9 hours" +%y-%m-%d)
runs_this_month=$(curl -H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$GITHUB_REPOSITORY/actions/runs?event=push&status=success&per_page=1&created=cats+created:<=$current_date"\
| jq '.total_count')
echo "new version is $current_date_short_year.$runs_this_month"
echo "new_version=$current_date_short_year.$runs_this_month" >> "$GITHUB_OUTPUT"
- name: Login to Docker
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: ${{ secrets.DOCKER_REGISTRY }}
- name: Docker build
env:
VERSION: ${{ steps.generate_version.outputs.new_version }}
DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
IMAGE_NAME: ${{ secrets.IMAGE_NAME }}
run: |
docker build -t $DOCKER_REGISTRY/$IMAGE_NAME:$VERSION .
docker tag $DOCKER_REGISTRY/$IMAGE_NAME:$VERSION $DOCKER_REGISTRY/$IMAGE_NAME:latest
docker push $DOCKER_REGISTRY/$IMAGE_NAME:$VERSION
docker push $DOCKER_REGISTRY/$IMAGE_NAME:latest
run_application:
runs-on: ubuntu-latest
needs: push_to_docker_hub
steps:
- name: Run Docker container
uses: appleboy/ssh-action@master
env:
VERSION: ${{ needs.push_to_docker_hub.outputs.new_version }}
DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
IMAGE_NAME: ${{ secrets.IMAGE_NAME }}
with:
host: ${{ secrets.NCP_HOST }}
username: ${{ secrets.NCP_USERNAME }}
password: ${{ secrets.NCP_PASSWORD }}
key: ${{ secrets.NCP_SSH_KEY }}
script: |
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY
docker pull $DOCKER_REGISTRY/$IMAGE_NAME:$VERSION
docker stop $IMAGE_NAME || true
docker rm $IMAGE_NAME || true
docker run -d --name $IMAGE_NAME -p 8080:8080 $DOCKER_REGISTRY/$IMAGE_NAME:$VERSION