Skip to content

Commit

Permalink
Merge pull request #39 from CedrickArmel/chore/trigger
Browse files Browse the repository at this point in the history
chore: cb manual trigger in gha and trigger update
  • Loading branch information
CedrickArmel authored Oct 11, 2024
2 parents 892fd9a + d1388e2 commit c568b6b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Exclure tout par défaut
*

# Autoriser uniquement les dossiers/fichiers spécifiques
!src/
!poetry.lock
!pyproject.toml
!conf/base/
!.env
7 changes: 3 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
58 changes: 58 additions & 0 deletions scripts/trigger.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash
usage() {
echo "Usage: $0 -p <project> -r <region> -t <trigger> [-b <branch>] [-s <substitutions>]"
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

0 comments on commit c568b6b

Please sign in to comment.