test: docker hub name 수정 #13
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: CI/CD for Spring Boot Application | |
# Push가 발생할 때 트리거 설정 | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# 1. 리포지토리 체크아웃 | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# 2. JDK 설정 (Spring Boot 빌드) | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
# 3. Gradlew 실행 권한 부여 | |
- name: Grant execute permission for Gradlew | |
working-directory: ./2024-UCD_WEB_SERVER # Spring Boot 프로젝트 폴더 경로 | |
run: chmod +x gradlew | |
# 4. Spring Boot 애플리케이션 빌드 | |
- name: Build with Gradle | |
working-directory: ./2024-UCD_WEB_SERVER # Spring Boot 프로젝트 폴더로 이동 | |
run: ./gradlew clean build -x test | |
# 5. Docker 이미지 빌드 | |
- name: Build Docker image | |
working-directory: ./2024-UCD_WEB_SERVER # Docker 빌드를 위해 동일 경로 설정 | |
run: | | |
docker build -t eotaegyu/keynote.app:latest . | |
# 6. Docker Hub 로그인 (GitHub Secrets 사용) | |
- name: Log in to Docker Hub | |
run: echo "${{ secrets.DOCKERHUB_USERNAME }}:${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin | |
# 7. Docker Hub에 이미지 푸시 | |
- name: Push Docker image to Docker Hub | |
run: | | |
docker push eotaegyu/keynote.app:latest | |
# GCP 인스턴스에서 Docker 이미지를 풀링하고 업데이트하는 단계. | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: SSH to GCP instance and pull new Docker image | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.GCP_INSTANCE_IP }} | |
username: ${{ secrets.GCP_INSTANCE_USER }} | |
key: ${{ secrets.GCP_SSH_PRIVATE_KEY }} | |
port: 22 | |
script: | | |
docker pull eotaegyu/keynote.app:latest | |
docker-compose down | |
docker-compose up -d |