From 458a1f346221142e4717a277f8d29c5ef2754944 Mon Sep 17 00:00:00 2001 From: Kattyan Date: Tue, 12 Nov 2024 15:59:49 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=87=E3=83=97=E3=83=AD=E3=82=A4=E7=94=A8?= =?UTF-8?q?=E3=81=AEGitHub=20Actions=E3=82=92=E6=95=B4=E5=82=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 59 ++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..01d43b5 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,59 @@ +name: Build and Deploy + +on: push +env: + PROJECT_ID: ${{ secrets.GOOGLE_CLOUD_PROJECT_ID }} + REGION: ${{ secrets.GOOGLE_CLOUD_REGION }} + REPOSITORY: ${{ secrets.ARTIFACT_REGISTRY_REPOSITORY }} + IMAGE: ${{ secrets.DOCKER_IMAGE }} + +jobs: + build-and-push: + runs-on: ubuntu-24.04 + permissions: + contents: read + id-token: write + + steps: + - uses: actions/checkout@v4 + + - id: auth + uses: google-github-actions/auth@v2 + with: + token_format: access_token + workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }} + service_account: ${{ secrets.SERVICE_ACCOUNT }} + + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@v2 + + - name: Login to GAR + uses: docker/login-action@v3 + with: + registry: ${{ env.REGION }}-docker.pkg.dev + username: oauth2accesstoken + password: ${{ steps.auth.outputs.access_token }} + + - name: Configure Docker for Artifact Registry + run: | + gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev + + - name: Build and push Docker image + env: + LITESTREAM_BUCKET: ${{ secrets.LITESTREAM_BUCKET }} + run: | + docker build \ + --build-arg LITESTREAM_BUCKET=$LITESTREAM_BUCKET \ + -t ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE }}:${{ github.sha }} \ + . + docker push ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE }}:${{ github.sha }} + + - name: Deploy to Cloud Run + run: | + gcloud run deploy ${{ env.IMAGE }} \ + --image ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE }}:${{ github.sha }} \ + --port="3000" \ + --region ${{ env.REGION }} \ + --max-instances=1 \ + --allow-unauthenticated \ + --set-env-vars=LITESTREAM_BUCKET=${{ secrets.LITESTREAM_BUCKET }}