Skip to content

Commit

Permalink
[.github] - feature: add manual workflow dispatch for deploying infra…
Browse files Browse the repository at this point in the history
…structure

 - Introduce workflow_dispatch trigger with a configurable input for deploying to the 'us-central1' region
 - Implement concurrency control to manage deployment processes and prevent collisions
 - Authenticate with Google Cloud and set up the Cloud SDK for deployment tasks
 - Build a Docker image using Cloud Build and a custom script, with parameters for image name and Dockerfile path
 - Generate a GitHub App token dynamically for use in the workflow
 - Enable triggering of a downstream repository's workflow using a repository dispatch event with a custom payload including the region and image tag
  • Loading branch information
JulesBelveze committed Nov 15, 2024
1 parent 448a5a2 commit 3be13ac
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/deploy-connectors-infra.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Deploy Infra

on:
workflow_dispatch:
inputs:
us-central1:
description: "Deploy to us-central1"
type: boolean
default: true

concurrency:
group: deploy_infra
cancel-in-progress: false

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

jobs:
build-and-deploy:
runs-on: ubuntu-latest

if: github.ref == 'refs/heads/main'

steps:
- name: Checkout code
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
run: |
chmod +x ./k8s/cloud-build.sh
./k8s/cloud-build.sh \
--image-name=connectors \
--dockerfile-path=./connectors/Dockerfile \
--working-dir=. \
--dust-client-facing-url=https://dust.tt
- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}


- name: Trigger dust-infra workflow
uses: actions/github-script@v6
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
with:
github-token: ${{ secrets.GH_TOKEN }}
script: |
await github.rest.repos.createDispatchEvent({
owner: 'dust-tt',
repo: 'dust-infra',
event_type: 'trigger-component-deploy',
client_payload: {
us_central1: ${{ inputs.us-central1 }},
component: 'connectors',
image_tag: '${{ steps.short_sha.outputs.short_sha }}'
}
});

0 comments on commit 3be13ac

Please sign in to comment.