From 8eff04e7c9d073f9429506dc739adb727cf62481 Mon Sep 17 00:00:00 2001 From: Liam Considine Date: Mon, 12 Aug 2024 17:27:51 -0400 Subject: [PATCH] A sketch for deploying the frontend --- .github/workflows/gcp-deploy.yml | 46 ++++++++++++++++++++++++++++++++ cloudbuild.yaml | 23 ++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 .github/workflows/gcp-deploy.yml create mode 100644 cloudbuild.yaml diff --git a/.github/workflows/gcp-deploy.yml b/.github/workflows/gcp-deploy.yml new file mode 100644 index 0000000..e785966 --- /dev/null +++ b/.github/workflows/gcp-deploy.yml @@ -0,0 +1,46 @@ +name: Deploy to Google Cloud Run + +on: + push: + branches: + - main + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: '22.5' + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ~/.npm + key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.OS }}-node- + + - name: Install dependencies + run: npm ci + + - name: Run tests + run: npm test + + - name: Setup Google Cloud SDK + uses: google-github-actions/setup-gcloud@v0.2.0 + with: + project_id: ${{ secrets.GCP_PROJECT_ID }} + service_account_key: ${{ secrets.GCP_SA_KEY }} + + - name: Configure Docker + run: gcloud auth configure-docker + + - name: Build and Deploy + run: | + gcloud builds submit --config cloudbuild.yaml \ No newline at end of file diff --git a/cloudbuild.yaml b/cloudbuild.yaml new file mode 100644 index 0000000..2421c38 --- /dev/null +++ b/cloudbuild.yaml @@ -0,0 +1,23 @@ +steps: + # Build the container image + - name: 'gcr.io/cloud-builders/docker' + args: ['build', '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA', '.'] + # Push the container image to Container Registry + - name: 'gcr.io/cloud-builders/docker' + args: ['push', 'gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA'] + # Deploy container image to Cloud Run + - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk' + entrypoint: gcloud + args: + - 'run' + - 'deploy' + - '$REPO_NAME' + - '--image' + - 'gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA' + - '--region' + - 'us-central1' + - '--platform' + - 'managed' + - '--allow-unauthenticated' +images: + - 'gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA' \ No newline at end of file