From 0a06d789a1df43f73adc55c41e26ff9ff785986a Mon Sep 17 00:00:00 2001 From: Jules Belveze <32683010+JulesBelveze@users.noreply.github.com> Date: Mon, 16 Dec 2024 08:19:45 +0100 Subject: [PATCH] [.github] - feat(workflows): regional build args (#9386) * [.github/k8s] - feature: regional configuration and deployment workflow update - Add Europe and US regional-specific configurations for the front-end - Refactor the front-edge deployment workflow to use a temporary cloud build script - Remove the dust-client-facing-url argument in the deployment script as it's now region-specific * [k8s] - refactor: streamline substitutions in cloud build script - Remove _CONFIG_FILE substitution as it's no longer needed - Update env variable extraction to use a region-specific config file in build step --- .github/configs/europe-west1.yaml | 4 ++ .github/configs/us-central1.yaml | 4 ++ .github/workflows/deploy-front-edge.yml | 5 +- k8s/cloud-build_tmp.sh | 69 +++++++++++++++++++++++++ k8s/cloudbuild_tmp.yaml | 30 +++++++++++ 5 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 .github/configs/europe-west1.yaml create mode 100644 .github/configs/us-central1.yaml create mode 100644 k8s/cloud-build_tmp.sh create mode 100644 k8s/cloudbuild_tmp.yaml diff --git a/.github/configs/europe-west1.yaml b/.github/configs/europe-west1.yaml new file mode 100644 index 000000000000..1bf9ccaf7e7a --- /dev/null +++ b/.github/configs/europe-west1.yaml @@ -0,0 +1,4 @@ +env: + NEXT_PUBLIC_VIZ_URL: "https://viz.dust.tt" + NEXT_PUBLIC_GA_TRACKING_ID: "G-K9HQ2LE04G" + NEXT_PUBLIC_DUST_CLIENT_FACING_URL: "https://eu-front-edge.dust.tt" \ No newline at end of file diff --git a/.github/configs/us-central1.yaml b/.github/configs/us-central1.yaml new file mode 100644 index 000000000000..2d567c488a3f --- /dev/null +++ b/.github/configs/us-central1.yaml @@ -0,0 +1,4 @@ +env: + NEXT_PUBLIC_VIZ_URL: "https://viz.dust.tt" + NEXT_PUBLIC_GA_TRACKING_ID: "G-K9HQ2LE04G" + NEXT_PUBLIC_DUST_CLIENT_FACING_URL: "https://front-edge.dust.tt" \ No newline at end of file diff --git a/.github/workflows/deploy-front-edge.yml b/.github/workflows/deploy-front-edge.yml index ca1f08fea9c3..f3b8fe0fc8ba 100644 --- a/.github/workflows/deploy-front-edge.yml +++ b/.github/workflows/deploy-front-edge.yml @@ -92,12 +92,11 @@ jobs: - name: Build image for ${{ matrix.region }} run: | - chmod +x ./k8s/cloud-build.sh - ./k8s/cloud-build.sh \ + chmod +x ./k8s/cloud-build_tmp.sh + ./k8s/cloud-build_tmp.sh \ --image-name=$IMAGE_NAME \ --dockerfile-path=./front/Dockerfile \ --working-dir=./ \ - --dust-client-facing-url=https://front-edge.dust.tt \ --region=${{ matrix.region }} deploy: diff --git a/k8s/cloud-build_tmp.sh b/k8s/cloud-build_tmp.sh new file mode 100644 index 000000000000..56eb5604c993 --- /dev/null +++ b/k8s/cloud-build_tmp.sh @@ -0,0 +1,69 @@ +#!/bin/bash +set -e + +# Default values +SCRIPT_DIR="$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd)" +WORKING_DIR="" +IMAGE_NAME="" +DOCKERFILE_PATH="" +REGION="" +GCLOUD_IGNORE_FILE="" + +# Parse command-line arguments +while [[ $# -gt 0 ]]; do + case $1 in + --working-dir=*) + WORKING_DIR="${1#*=}" + shift + ;; + --image-name=*) + IMAGE_NAME="${1#*=}" + shift + ;; + --dockerfile-path=*) + DOCKERFILE_PATH="${1#*=}" + shift + ;; + --region=*) + REGION="${1#*=}" + shift + ;; + --gcloud-ignore-file=*) + GCLOUD_IGNORE_FILE="${1#*=}" + shift + ;; + *) + echo "Error: Unknown argument $1" + exit 1 + ;; + esac +done + +# Validate required arguments +if [ -z "$WORKING_DIR" ] || [ -z "$IMAGE_NAME" ] || [ -z "$DOCKERFILE_PATH" ] || [ -z "$REGION" ]; then + echo "Error: --working-dir, --image-name, --region and --dockerfile-path are required" + exit 1 +fi + +# Change to working directory +cd "$WORKING_DIR" + +# Load region-specific config +CONFIG_FILE=".github/config/${REGION}.yaml" +if [ ! -f "$CONFIG_FILE" ]; then + echo "Error: Config file not found: $CONFIG_FILE" + exit 1 +fi + +# Prepare the build command +BUILD_CMD=(gcloud builds submit --quiet --config "${SCRIPT_DIR}/cloudbuild_tmp.yaml") + +if [ -n "$GCLOUD_IGNORE_FILE" ]; then + BUILD_CMD+=(--ignore-file="$GCLOUD_IGNORE_FILE") +fi + +# Add substitutions +BUILD_CMD+=(--substitutions="_REGION=$REGION,_IMAGE_NAME=$IMAGE_NAME,_DOCKERFILE_PATH=$DOCKERFILE_PATH,SHORT_SHA=$(git rev-parse --short HEAD)" .) + +# Execute the build +"${BUILD_CMD[@]}" diff --git a/k8s/cloudbuild_tmp.yaml b/k8s/cloudbuild_tmp.yaml new file mode 100644 index 000000000000..671b238b80bb --- /dev/null +++ b/k8s/cloudbuild_tmp.yaml @@ -0,0 +1,30 @@ +steps: + - id: 'Build Container Image' + name: 'ghcr.io/depot/cli:latest' + script: | + # Extract env variables for build args + yq e '.env' .github/config/${_REGION}.yaml > build-args.env + + depot build \ + --project 3vz0lnf16v \ + --provenance=false \ + -t ${_REGION}-docker.pkg.dev/${PROJECT_ID}/dust-images/${_IMAGE_NAME}:${SHORT_SHA} \ + -t ${_REGION}-docker.pkg.dev/${PROJECT_ID}/dust-images/${_IMAGE_NAME}:latest \ + -f ${_DOCKERFILE_PATH} \ + --build-arg COMMIT_HASH=${SHORT_SHA} \ + --build-arg-file=build-args.env \ + --push \ + . + secretEnv: + - "DEPOT_TOKEN" + +timeout: 1200s + +availableSecrets: + secretManager: + - versionName: projects/$PROJECT_ID/secrets/DEPOT_TOKEN/versions/latest + env: DEPOT_TOKEN + +options: + automapSubstitutions: true + logging: CLOUD_LOGGING_ONLY \ No newline at end of file