add sitemap (#33) #10
This file contains hidden or 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: nextjs-cloud-run | |
| # 工作流程將在將代碼推送到 master 或 main 分支時觸發。 | |
| on: | |
| push: | |
| branches: | |
| - cloudrun | |
| # 定義環境變數,用於設定 Cloud Run 相關的項目 | |
| env: | |
| CLOUD_RUN_PROJECT_ID: ${{ secrets.CLOUD_RUN_PROJECT_NAME }} | |
| CLOUD_RUN_REGION: asia-east1 | |
| REPO_NAME: mpizza-blog | |
| # 定義了一個名為 build-and-deploy 的工作,這個工作將運行在 ubuntu-latest 環境上。 | |
| jobs: | |
| build-and-deploy: | |
| name: Setup, Build, and Deploy | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 步驟:從 GitHub 倉庫中檢出代碼。 | |
| - name: Checkout | |
| uses: actions/checkout@v2 | |
| # 步驟:使用 Google Cloud Actions 設置 gcloud 並驗證服務帳戶。 | |
| - uses: google-github-actions/setup-gcloud@v0.2.0 | |
| with: | |
| project_id: ${{ secrets.CLOUD_RUN_PROJECT_NAME }} | |
| service_account_key: ${{ secrets.CLOUD_RUN_SERVICE_ACCOUNT }} | |
| service_account_email: ${{ secrets.CLOUD_RUN_SERVICE_ACCOUNT_EMAIL }} | |
| # 步驟:啟用 Container Registry 和 Cloud Run API,並設置 Docker 認證。 | |
| - name: Enable the necessary APIs and enable docker auth | |
| run: |- | |
| gcloud services enable containerregistry.googleapis.com | |
| gcloud services enable run.googleapis.com | |
| gcloud --quiet auth configure-docker | |
| # 構建映像,並為鏡像添加標籤。 | |
| - name: Build and tag image | |
| run: |- | |
| docker build . --tag "gcr.io/$CLOUD_RUN_PROJECT_ID/$REPO_NAME:$GITHUB_SHA" | |
| # 將映像推送到 Google Container Registry。 | |
| - name: Push image to GCR | |
| run: |- | |
| docker push gcr.io/$CLOUD_RUN_PROJECT_ID/$REPO_NAME:$GITHUB_SHA | |
| # 部署 | |
| - name: Deploy | |
| run: |- | |
| gcloud components install beta --quiet | |
| gcloud beta run deploy $REPO_NAME --image gcr.io/$CLOUD_RUN_PROJECT_ID/$REPO_NAME:$GITHUB_SHA \ | |
| --project $CLOUD_RUN_PROJECT_ID \ | |
| --platform managed \ | |
| --region $CLOUD_RUN_REGION \ | |
| --allow-unauthenticated \ | |
| --quiet |