Merge Master 2024년 8월 29일 #63
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker Image CI | |
on: | |
push: | |
branches: [ "master" ] | |
pull_request: | |
branches: [ "master" ] | |
jobs: | |
# 1. CI - 통합(build) | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# 저장소의 커밋된 master브랜치 내려받기 | |
- name : Checkout | |
uses: actions/checkout@v3 | |
with: | |
ref: master | |
# JDK 17 설치 (원하는 버젼 및 배포판 (corretto | zulu | temurin 지정) | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# Gradle 실행 권한 부여 | |
- name: Grant permission for gradlew | |
run: chmod +x ./gradlew | |
# Gradle Build (테스트 생략) | |
- name: Build with Gradle | |
run: ./gradlew clean build -x test | |
# 빌드된 jar파일을 도커 이미지로 빌드 및 도커 허브에 발행(푸시) | |
- name: Docker build and publish | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ vars.APP_NAME }} . | |
docker push ${{ secrets.DOCKER_USERNAME }}/${{ vars.APP_NAME }} | |
# 2. CD 배포 | |
deploy: | |
# needs를 통해 build job이 수행성공시에만 작업하도록 설정 | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
# NCP SSH 접속 / docker image pull & run | |
- name: NCP SSH Login and Docker Image pull and run | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.NCP_HOST }} | |
username: ${{ secrets.NCP_USERNAME }} | |
password: ${{ secrets.NCP_PASSWORD }} | |
key: ${{ secrets.NCP_KEY }} | |
port: ${{ secrets.NCP_PORT }} | |
script: | | |
sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
sudo docker stop $(sudo docker ps -a -q) | |
sudo docker rm -f $(sudo docker ps -a -q) | |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ vars.APP_NAME }} | |
sudo docker run -d -p 8080:8080 \ | |
-e "SPRING_PROFILES_ACTIVE=prod" \ | |
-e "PROD_DB_URL=${{ secrets.PROD_DB_URL }}" \ | |
-e "PROD_DB_USERNAME=${{ secrets.PROD_DB_USERNAME }}" \ | |
-e "PROD_DB_PASSWORD=${{ secrets.PROD_DB_PASSWORD }}" \ | |
-e "SPRING_S3_ACCESSKEY=${{ secrets.SPRING_S3_ACCESSKEY }}" \ | |
-e "SPRING_S3_SECRETKEY=${{ secrets.SPRING_S3_SECRETKEY }}" \ | |
-e "REDIS_HOST=${{ secrets.REDIS_HOST }}" \ | |
-e "REDIS_PASSWORD=${{ secrets.REDIS_PASSWORD }}" \ | |
-e "REDIS_PORT=${{ secrets.REDIS_PORT }}" \ | |
--name ${{ vars.APP_NAME }} \ | |
${{ secrets.DOCKER_USERNAME }}/${{ vars.APP_NAME }} | |
sudo docker image prune -f |