Update main.yml #6
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 to Google Compute Engine | |
on: | |
push: | |
branches: | |
- main | |
env: | |
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} | |
GCE_INSTANCE: server-instance-name | |
GCE_INSTANCE_ZONE: instance-zone | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
# 인증 과정은 동일합니다. | |
- name: Setup gcloud CLI | |
uses: google-github-actions/setup-gcloud@v2 | |
with: | |
project_id: ${{ env.PROJECT_ID }} | |
- name: Auth to Google Cloud | |
uses: google-github-actions/[email protected] | |
with: | |
credentials_json: ${{ secrets.GCP_SA_KEY }} | |
# 소스 코드 압축 | |
- name: Archive Source | |
run: tar -czvf source.tar.gz . | |
# Cloud Storage에 소스 코드 업로드 | |
- name: Upload Source to Cloud Storage | |
run: | | |
gsutil cp source.tar.gz gs://your-bucket-name/${{ github.run_id }}/source.tar.gz | |
# GCE 인스턴스에서 소스 코드 다운로드 및 배포 스크립트 실행 | |
- name: Deploy to GCE | |
run: | | |
gcloud compute ssh ${{ env.GCE_INSTANCE }} --zone ${{ env.GCE_INSTANCE_ZONE }} --command "\ | |
wget https://storage.googleapis.com/your-bucket-name/${{ github.run_id }}/source.tar.gz -O /tmp/source.tar.gz && \ | |
tar -xzvf /tmp/source.tar.gz -C /path/to/deployment/directory && \ | |
sudo systemctl restart your-service-name" |