diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4b82fb1 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +# Exclure tout par défaut +* + +# Autoriser uniquement les dossiers/fichiers spécifiques +!src/ +!poetry.lock +!pyproject.toml +!conf/base/ +!.env diff --git a/main.tf b/main.tf index a707ecf..a0b503f 100644 --- a/main.tf +++ b/main.tf @@ -335,11 +335,10 @@ resource "google_cloudbuild_trigger" "gcp_build_trigger" { name = "build-base-image" filename = ".cloudbuild/build_image.yaml" service_account = google_service_account.gcp_sa["gcp_ml_sa"].id - repository_event_config { + source_to_build { repository = google_cloudbuildv2_repository.github_repo.id - push { - branch = "^main$" - } + ref = "refs/heads/main" + repo_type = "GITHUB" } substitutions = { _DEVICE = "gpu", diff --git a/scripts/trigger.sh b/scripts/trigger.sh new file mode 100644 index 0000000..ca7616d --- /dev/null +++ b/scripts/trigger.sh @@ -0,0 +1,58 @@ +#!/bin/bash +usage() { + echo "Usage: $0 -p -r -t [-b ] [-s ]" + exit 1 +} + +while getopts "p:r:t:b:s:" opt; do + case $opt in + p) project="$OPTARG";; + r) region="$OPTARG";; + t) trigger="$OPTARG";; + b) branch="$OPTARG";; + s) substitutions="$OPTARG";; + *) usage;; + esac +done + +# Check if mandatory parameters are provided +if [ -z "$project" ] || [ -z "$region" ] || [ -z "$trigger" ]; then + usage +fi + +export CLOUDSDK_CORE_DISABLE_PROMPTS=1 + +# Set the project +gcloud config set project "$project" + +# Run the gcloud command based on whether the branch and substitutions are provided +if [ -z "$substitutions" ]; then + if [ -z "$branch" ]; then + BUILD_ID=$(gcloud beta builds triggers run "$trigger" --region="$region" --quiet --format="value(metadata.build.id)") + else + BUILD_ID=$(gcloud beta builds triggers run "$trigger" --region="$region" --branch="$branch" --quiet --format="value(metadata.build.id)") + fi +else + if [ -z "$branch" ]; then + BUILD_ID=$(gcloud beta builds triggers run "$trigger" --region="$region" --substitutions="$substitutions" --quiet --format="value(metadata.build.id)") + else + BUILD_ID=$(gcloud beta builds triggers run "$trigger" --region="$region" --substitutions="$substitutions" --branch="$branch" --quiet --format="value(metadata.build.id)") + fi +fi + +# Output the BUILD_ID +echo "BUILD_ID = $BUILD_ID" + +# Stream the logs +gcloud beta builds log --stream "$BUILD_ID" --region="$region" + +# Get the build status +BUILD_STATUS=$(gcloud beta builds describe "$BUILD_ID" --format="value(status)" --region="$region") +echo "Build status = $BUILD_STATUS" + +# Exit based on build status +if [ "$BUILD_STATUS" == "SUCCESS" ]; then + exit 0 +else + exit 1 +fi