Skip to content

Update README.md

Update README.md #39

# github repository actions ํŽ˜์ด์ง€์— ๋‚˜ํƒ€๋‚  ์ด๋ฆ„
name: CI/CD using github actions & docker
# event trigger
# main์ด๋‚˜ develop ๋ธŒ๋žœ์น˜์— push๊ฐ€ ๋˜์—ˆ์„ ๋•Œ ์‹คํ–‰
on:
push:
branches: [ "main" ]
permissions:
contents: read
jobs:
CI-CD:
runs-on: ubuntu-latest
steps:
# JDK setting - github actions์—์„œ ์‚ฌ์šฉํ•  JDK ์„ค์ • (ํ”„๋กœ์ ํŠธ๋‚˜ AWS์˜ java ๋ฒ„์ „๊ณผ ๋‹ฌ๋ผ๋„ ๋ฌด๋ฐฉ)
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
# gradle caching - ๋นŒ๋“œ ์‹œ๊ฐ„ ํ–ฅ์ƒ
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
# ํ™˜๊ฒฝ๋ณ„ yml ํŒŒ์ผ ์ƒ์„ฑ - application.yml
- name: make application.yml
if: |
contains(github.ref, 'main')
run: |
mkdir ./planfit/src/main/resources # resources ํด๋” ์ƒ์„ฑ
cd ./planfit/src/main/resources # resources ํด๋”๋กœ ์ด๋™
touch ./application.yml # application.yml ์ƒ์„ฑ
echo "${{ secrets.YML }}" > ./application.yml # github actions์—์„œ ์„ค์ •ํ•œ ๊ฐ’์„ application.yml ํŒŒ์ผ์— ์“ฐ๊ธฐ
shell: bash
# gradle build
- name: Build with Gradle
run: |
./planfit/gradlew build --project-dir ./planfit -x test
# docker login
- name: Docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
# docker build & push to production
- name: Docker build & push to prod
if: contains(github.ref, 'main')
run: |
pwd
docker build -f ./planfit/Dockerfile -t ${{ secrets.DOCKERHUB_USERNAME }}/planfit .
docker push ${{ secrets.DOCKERHUB_USERNAME }}/planfit
## deploy to production
- name: Deploy to prod
uses: appleboy/ssh-action@master
id: deploy-prod
if: contains(github.ref, 'main')
with:
host: ${{ secrets.HOST_PROD }} # EC2 ํผ๋ธ”๋ฆญ IPv4 DNS
username: ubuntu
key: ${{ secrets.PEM_KEY }}
envs: GITHUB_SHA
script: |
sudo docker ps -q --filter ancestor=${{ secrets.DOCKERHUB_USERNAME }}/planfit | xargs -r sudo docker stop | xargs -r sudo docker rm
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/planfit
sudo docker run -d --name planfit_container -p 8081:8081 ${{ secrets.DOCKERHUB_USERNAME }}/planfit
sudo docker image prune -f