Skip to content

Commit

Permalink
[.github] - feat(workflows): regional build args (#9386)
Browse files Browse the repository at this point in the history
* [.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
  • Loading branch information
JulesBelveze authored Dec 16, 2024
1 parent 43eea9e commit 0a06d78
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .github/configs/europe-west1.yaml
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 4 additions & 0 deletions .github/configs/us-central1.yaml
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 2 additions & 3 deletions .github/workflows/deploy-front-edge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
69 changes: 69 additions & 0 deletions k8s/cloud-build_tmp.sh
Original file line number Diff line number Diff line change
@@ -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[@]}"
30 changes: 30 additions & 0 deletions k8s/cloudbuild_tmp.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0a06d78

Please sign in to comment.