Skip to content

Commit

Permalink
[.github/workflows] - feat: enhance prodbox deployment with regional …
Browse files Browse the repository at this point in the history
…options (#9360)

- Add capability to select deployment regions via workflow dispatch inputs
 - Implement a job matrix to run builds in multiple regions conditionally
 - Enhance Slack notifications to include start of deployment process
 - Separate build and deploy job for better clarity and parallel execution
 - Ensure build information is shared between jobs via outputs
 - Adjust deployment trigger payload to include the selected region
  • Loading branch information
JulesBelveze authored Dec 13, 2024
1 parent 47c8f03 commit 4150b0b
Showing 1 changed file with 58 additions and 10 deletions.
68 changes: 58 additions & 10 deletions .github/workflows/deploy-prodbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ name: Deploy Prodbox
on:
workflow_dispatch:
inputs:
regions:
description: "Regions to deploy to"
required: true
default: "us-central1"
type: choice
options:
- "us-central1"
- "europe-west1"
- "all"
check_deployment_blocked:
description: "Check #deployment locks or force deploy"
required: true
Expand All @@ -18,10 +27,13 @@ concurrency:

env:
GCLOUD_PROJECT_ID: ${{ secrets.GCLOUD_PROJECT_ID }}
IMAGE_NAME: prodbox

jobs:
build-and-deploy:
notify-start:
runs-on: ubuntu-latest
outputs:
thread_ts: ${{ steps.build_message.outputs.thread_ts }}

steps:
- name: Checkout code
Expand Down Expand Up @@ -53,25 +65,61 @@ jobs:
channel: ${{ secrets.SLACK_CHANNEL_ID }}
slack_token: ${{ secrets.SLACK_BOT_TOKEN }}

create-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- id: set-matrix
run: |
if [ "${{ github.event.inputs.regions }}" = "all" ]; then
echo "matrix=[\"us-central1\",\"europe-west1\"]" >> $GITHUB_OUTPUT
else
echo "matrix=[\"${{ github.event.inputs.regions }}\"]" >> $GITHUB_OUTPUT
fi
build:
needs: [ notify-start, create-matrix ]
runs-on: ubuntu-latest
strategy:
matrix:
region: ${{ fromJson(needs.create-matrix.outputs.matrix) }}
fail-fast: true

steps:
- uses: actions/checkout@v3
- name: Get short sha
id: short_sha
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: "Authenticate with Google Cloud"
uses: "google-github-actions/auth@v1"
with:
credentials_json: "${{ secrets.GCLOUD_SA_KEY }}"

- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v1"

- name: Build the image on Cloud Build
- name: Build image for ${{ matrix.region }}
run: |
chmod +x ./k8s/cloud-build.sh
./k8s/cloud-build.sh \
--image-name=prodbox \
--image-name=$IMAGE_NAME \
--dockerfile-path=./prodbox.Dockerfile \
--working-dir=./ \
--gcloud-ignore-file=.gcloudignore-prodbox \
--dust-client-facing-url=https://dust.tt \
--region=us-central1
--region=${{ matrix.region }}
deploy:
needs: [ notify-start, build ]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
ssh-key: "${{ secrets.PRODBOX_PRIVATE_DEPLOY_KEY }}"

- name: Get short sha
id: short_sha
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@v1
Expand All @@ -92,10 +140,10 @@ jobs:
repo: 'dust-infra',
event_type: 'trigger-component-deploy',
client_payload: {
regions: 'us-central1',
regions: '${{ github.event.inputs.regions }}',
component: 'prodbox',
image_tag: '${{ steps.short_sha.outputs.short_sha }}',
slack_thread_ts: "${{ steps.build_message.outputs.thread_ts }}",
slack_thread_ts: "${{ needs.notify-start.outputs.thread_ts }}",
slack_channel: '${{ secrets.SLACK_CHANNEL_ID }}'
}
});
Expand All @@ -110,4 +158,4 @@ jobs:
image_tag: ${{ steps.short_sha.outputs.short_sha }}
channel: ${{ secrets.SLACK_CHANNEL_ID }}
slack_token: ${{ secrets.SLACK_BOT_TOKEN }}
thread_ts: "${{ steps.build_message.outputs.thread_ts }}"
thread_ts: "${{ needs.notify-start.outputs.thread_ts }}"

0 comments on commit 4150b0b

Please sign in to comment.