-
Notifications
You must be signed in to change notification settings - Fork 6
78 lines (68 loc) · 2.22 KB
/
prod-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
74
75
76
77
78
name: prod CI&CD to Cloud
on:
push:
branches:
- prod
env:
HOST: ${{ secrets.AWS_PROD_HOST }}
KEY: ${{ secrets.AWS_PROD_KEY }}
DOCKERHUB_REPO: ${{ secrets.DOCKERHUB_PROD_REPO }}
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ DOCKERHUB_PASSWORD }}
APPLICATION_DIR: src/main/resources
APPLICATION_PROD: ${{ secrets.APPLICATION_PROD }}
jobs:
build:
name: CI & CD
runs-on: ubuntu-latest
steps:
# (0) 시간 출력
- name: Get Current Time
uses: 1466587594/get-current-time@v2
id: current-time
with:
format: YYYY-MM-DDTHH:mm:ss
timezone: 'Asia/Seoul'
- name: Print Current Time
run: echo "Current Time=${{steps.current-time.outputs.formattedTime}}"
shell: bash
# (1) 기본 체크아웃
- name: Checkout
uses: actions/checkout@v3
# (2) JDK 11 세팅
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'temurin'
# (3) 환경변수 파일 생성
- name: Copy properties
run: echo $APPLICATION_PROD | base64 --decode > $APPLICATION_DIR/application-prod.yml
# (4) gradlew 권한 설정
- name: Grant execute permission for gradlew
run: chmod +x gradlew
# (5) Gradle build (Test 제외)
- name: Build with Gradle
uses: gradle/gradle-build-action@0d13054264b0bb894ded474f08ebb30921341cee
with:
arguments: clean build -x test
# (6) Docker 이미지 빌드
- name: Docker build & push to docker repo
run: |
docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD
docker build -f Dockerfile -t $DOCKERHUB_REPO/ssafsound-app .
docker push $DOCKERHUB_REPO/ssafsound-app
# (7) ssh 접속 후 docker compose up
- name: Deploy to server
uses: appleboy/ssh-action@master
id: deploy
with:
host: $HOST
username: ubuntu
key: $KEY
envs: GITHUB_SHA
script: |
sudo docker rm -f $(docker ps -qa)
sudo docker pull $DOCKERHUB_REPO/ssafsound-app
docker-compose up -d
docker image prune -f