Merge pull request #224 from Moadong/refactor/#210-payload-field #27
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
# .github/workflows/server_cd_develop.yml | |
name: Release Server CD | |
on: | |
push: | |
branches: | |
- 'main' | |
paths: | |
- 'backend/**' | |
- '.github/workflows/**' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
cache: gradle # Gradle 캐싱 활성화 | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 | |
- name: Cache Gradle dependencies | |
uses: actions/cache@v4 # Gradle 의존성 캐시 설정 | |
with: | |
path: ~/.gradle/caches # Gradle 캐시 경로 | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} # Gradle 파일 해시값 기반 키 | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: make application.properties | |
run: | | |
cd ./backend/src/main/resources | |
echo "${{ secrets.APPLICATION_PROD_RELEASE }}" > ./application.properties | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./backend/gradlew | |
- name: Build with Gradle | |
run: | | |
cd backend | |
./gradlew clean build -x test | |
- id: 'auth' | |
uses: 'google-github-actions/auth@v2' | |
with: | |
credentials_json: ${{ secrets.GCE_SA_KEY }} | |
# GCloud SDK 캐시 설정 | |
- name: Cache Google Cloud SDK | |
uses: actions/cache@v4 | |
with: | |
path: ~/.cache | |
key: gcloud-sdk-${{ runner.os }} | |
restore-keys: | | |
gcloud-sdk- | |
# Google Cloud CLI 설정 | |
- name: Set up Google Cloud SDK | |
uses: google-github-actions/setup-gcloud@v2 | |
with: | |
project_id: ${{ secrets.GCE_PROJECT }} | |
# Docker 인증 | |
- name: Authenticate Docker to Google Cloud Container Registry (GCR) | |
run: | | |
gcloud auth configure-docker asia-northeast3-docker.pkg.dev | |
# Docker 이미지 빌드 및 GCR 업로드 | |
- name: Build and Push Docker Image | |
run: | | |
cd backend | |
docker build -t ${{ secrets.DOCKER_IMAGE_RELEASE }}:${{ github.sha }} -t ${{ secrets.DOCKER_IMAGE_RELEASE }}:latest . | |
docker push -a ${{ secrets.DOCKER_IMAGE_RELEASE }} | |
deploy: | |
name: Deploy | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
needs: build | |
steps: | |
# gcloud-setup workflow 호출 | |
- id: 'auth' | |
uses: 'google-github-actions/auth@v2' | |
with: | |
credentials_json: ${{ secrets.GCE_SA_KEY }} | |
# Google Cloud CLI 설정 | |
- name: Set up Google Cloud SDK | |
uses: google-github-actions/setup-gcloud@v2 | |
with: | |
project_id: ${{ secrets.GCE_PROJECT }} | |
- name: Update Container on VM | |
run: | | |
gcloud compute ssh ${{ secrets.GCE_INSTANCE_RELEASE }} --zone=${{ secrets.GCP_REGION }} --command=" | |
gcloud auth configure-docker asia-northeast3-docker.pkg.dev | |
gcloud auth activate-service-account --key-file=/home/g11_27_proro/gce_sa_key.json | |
sudo usermod -aG docker $USER | |
newgrp docker | |
docker pull ${{ secrets.DOCKER_IMAGE_RELEASE }}:latest | |
export DOCKER_APP_IMAGE=${{ secrets.DOCKER_IMAGE_RELEASE }}:latest | |
sudo chmod +x /home/g11_27_proro/deploy.sh # 실행 권한 부여 | |
sudo -E /home/g11_27_proro/deploy.sh # su권한으로 환경 변수 유지 및 실행 | |
docker image prune -af | |
docker ps -a" |