Merge pull request #15 from With-Mate/fix/journey/sh #45
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: Deploy using GitHub Actions | |
# event trigger | |
# develop/main 브랜치에 push 혹은 pull_request가 되었을 때 실행 | |
on: | |
push: | |
branches: [ "develop/main" ] | |
pull_request: | |
branches: [ "develop/main" ] | |
env: | |
GITHUB_SHA: ${{ github.sha }} | |
PROJECT_ID: ${{secrets.PROJECT_ID}} | |
GCE_INSTANCE: ${{secrets.GCE_INSTANCE}} | |
GCE_INSTANCE_ZONE: ${{secrets.GCE_INSTANCE_ZONE}} | |
jobs: | |
setup-build-publish-deploy: | |
name: Setup, Build, Publish, and Deploy | |
runs-on: ubuntu-latest | |
steps: | |
# 기본 체크아웃 | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# Gradlew 실행 허용 | |
- name: Run chmod to make gradlew executable | |
run: | | |
chmod +x ./withmate/gradlew | |
# JDK 17 세팅 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# prod 설정 | |
- name: make application-prod.yml | |
run: | | |
cd ./withmate/src/main/resources | |
touch ./application-prod.yml | |
echo "${{ secrets.YML_PROD }}" > ./application-prod.yml | |
shell: bash | |
# GCP Setup | |
- id: 'auth' | |
uses: 'google-github-actions/auth@v2' | |
with: | |
credentials_json: '${{ secrets.GCP_CREDENTIALS }}' | |
- name: 'Set up Cloud SDK' | |
uses: 'google-github-actions/setup-gcloud@v2' | |
with: | |
version: '>= 363.0.0' | |
- name: 'Use gcloud CLI' | |
run: 'gcloud info' | |
# Configure Docker to use the gcloud command-line tool as a credential | |
# helper for authentication | |
- run: |- | |
gcloud --quiet auth configure-docker | |
# Build the Docker image | |
- name: Build | |
run: |- | |
docker build --tag "gcr.io/$PROJECT_ID/$GCE_INSTANCE-image:$GITHUB_SHA" -f ./withmate/Dockerfile ./withmate | |
# Push the Docker image to Google Container Registry | |
- name: Publish | |
run: |- | |
docker push "gcr.io/$PROJECT_ID/$GCE_INSTANCE-image:$GITHUB_SHA" | |
- name: Deploy | |
run: |- | |
gcloud compute instances update-container "$GCE_INSTANCE" \ | |
--zone "$GCE_INSTANCE_ZONE" \ | |
--container-image "gcr.io/$PROJECT_ID/$GCE_INSTANCE-image:$GITHUB_SHA" |