-
Notifications
You must be signed in to change notification settings - Fork 1
103 lines (90 loc) · 3.41 KB
/
build-push-prod.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: 'build-push-prod'
on:
push:
branches: [ "main" ]
# pull_request:
# types:
# - closed
# branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
name: build
steps:
# 코드 저장소로 부터 CI 서버로 코드 pull
- name: checkout
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
# gradle 빌드 실행을 위한 권한을 부여
- name: grant execute permission for gradlew
run: chmod +x gradlew
- name: gradle build
run: ./gradlew clean build
# private 저장소일경우 로그인 필요
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: build docker
run: ./gradlew bootBuildImage --imageName=${{ secrets.DOCKER_REPO }}
- name: Docker push
run: |
docker tag ${{secrets.DOCKER_REPO}}:latest ${{secrets.DOCKERHUB_USERNAME}}/${{secrets.DOCKER_REPO}}:latest
docker push ${{secrets.DOCKERHUB_USERNAME}}/${{secrets.DOCKER_REPO}}
- name: action-slack
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
author_name: build & docker push # default: 8398a7@action-slack
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
if: always() # Pick up events even if the job fails or is canceled.
deploy:
needs: build
name: deploy
runs-on: [ self-hosted, api-server, prod ]
steps:
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{secrets.DOCKERHUB_USERNAME}}
password: ${{secrets.DOCKERHUB_TOKEN}}
- name: docker-compose.yml run
run: |
cd /home/prod-server/api-server
docker-compose down
if [ -z $(docker images -qf reference='${{secrets.DOCKERHUB_USERNAME}}/${{secrets.DOCKER_REPO}}') ]; then
echo "not search docker images"
exit 1
else
docker rmi -f ${{secrets.DOCKERHUB_USERNAME}}/${{secrets.DOCKER_REPO}}
echo "docker images remove success"
docker-compose up --build -d
echo "api-server docker-compose start success"
fi
cd /home/prod-server/api-server2
docker-compose down
if [ -z $(docker images -qf reference='${{secrets.DOCKERHUB_USERNAME}}/${{secrets.DOCKER_REPO}}') ]; then
echo "not search docker images"
exit 1
else
docker rmi -f ${{secrets.DOCKERHUB_USERNAME}}/${{secrets.DOCKER_REPO}}
echo "docker images remove success"
docker-compose up --build -d
echo "api-server2 docker-compose start success"
fi
- name: action-slack
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
author_name: docker pull & deploy # default: 8398a7@action-slack
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
if: always() # Pick up events even if the job fails or is canceled.