-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (72 loc) ยท 3.21 KB
/
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
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
name: Deploy
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest # ์คํ๋ ์ธ์คํด์ค OS์ ๋ฒ์
steps:
# ๊ธฐ๋ณธ ์ฒดํฌ์์
# ์ง์ ํ ์ ์ฅ์(ํ์ฌ REPO)์์ ์ฝ๋๋ฅผ ์ํฌํ๋ก์ฐ ํ๊ฒฝ์ผ๋ก ๊ฐ์ ธ์ค๋๋ก ํ๋ github action
- name: Checkout
uses: actions/checkout@v3
# Gradlew ์คํ ํ์ฉ
- name: Run chmod to make gradlew executable
run: chmod +x ./gradlew
# JDK 11 ์ธํ
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
# ํ๊ฒฝ ๋ณ์ ์ค์
- name: Make application.properties
run: |
cd ./src/main/resources
touch ./application.properties
echo "${{ secrets.APPLICATION }}" > ./application.properties
shell: bash
# Gradle build (Test ์ ์ธ)
- name: Build with Gradle
run: |
./gradlew clean bootJar -x test
# Docker login
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
# Docker build
- name: Docker build & push to docker repo
run: |
docker build -t ${{ secrets.DOCKERHUB_REPOSITORY }} .
docker tag ${{ secrets.DOCKERHUB_REPOSITORY }} ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:${GITHUB_SHA::7}
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:${GITHUB_SHA::7}
# Deploy
# appleboy/ssh-action@master ์ก์
์ ์ฌ์ฉํ์ฌ ์ง์ ํ ์๋ฒ์ ssh๋ก ์ ์ํ๊ณ , script๋ฅผ ์คํํฉ๋๋ค.
# script์ ๋ด์ฉ์ ๋์ปค์ ๊ธฐ์กด ํ๋ก์ธ์ค๋ค์ ์ ๊ฑฐํ๊ณ , docker repo๋ก๋ถํฐ ๋ฐฉ๊ธ ์์์ pushํ ๋ด์ฉ์ pull ๋ฐ์ ์คํํ๋ ๊ฒ์
๋๋ค.
# ์คํ ์, docker-compose๋ฅผ ์ฌ์ฉํฉ๋๋ค.
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }} # EC2 ์ธ์คํด์ค ํผ๋ธ๋ฆญ DNS
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }} # pem ํค
#passphrase: ${{ secrets.SSH_PASSPHRASE }}
envs: GITHUB_SHA
script: |
echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:${GITHUB_SHA::7}
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:${GITHUB_SHA::7} gc_spring
docker-compose -p grocery up -d
debug: true