diff --git a/bin/container b/bin/container index 137bf72cb7..5dbe79a2f8 100755 --- a/bin/container +++ b/bin/container @@ -4,9 +4,7 @@ ROOT=$(dirname $0)/.. function usage { echo Error: $* - echo Usage: $0 target { prep, build } [--no-check] [repo] - echo Project: $GCP_PROJECT - echo Try starting with: $0 build + echo Usage: $0 target { prep, build, push, apply } [--no-check] [repo] exit 1 } @@ -30,6 +28,7 @@ git_repo=${git_prefix#*.com:} GCP_PROJECT=$(gcloud config get project) REPOSITORY=ghcr.io/${git_repo} +TEMPLATES=$(cd etc; ls k8s_*.yaml) if [[ $1 == "--no-check" ]]; then NOCHECK=1 @@ -77,7 +76,21 @@ version=`git describe` RUNARGS="--rm -ti -v $PWD/var:/udmi -v $HOME/.config:/root/.config --tmpfs /tmp" -if [[ $cmd == prep || $cmd == build ]]; then +prep= +build= +push= +apply= + +[[ $cmd == apply ]] && apply=y +[[ $cmd == push || -n $apply ]] && push=y +[[ $cmd == build || -n $push ]] && build=y +[[ $cmd == prep || -n $build ]] && prep=y + +if [[ -z $prep ]]; then + usage Unknown command $cmd +fi + +if [[ -n $prep ]]; then rm -rf var tmp && mkdir -p var tmp cp -f etc/*.json var/ || true @@ -97,14 +110,13 @@ EOF more var/deployed_version.json | cat fi -if [[ $cmd == build ]]; then +if [[ -n $build ]]; then echo Building Dockerfile.$target docker build -f Dockerfile.$target -t $target . + docker tag $target $udmi_ref fi -TEMPLATES=$(cd etc; ls k8s_*.yaml) -if [[ $cmd == build && $REPOSITORY != local ]]; then - docker tag $target $udmi_ref +if [[ -n $push ]]; then docker push $udmi_ref hash=$(docker images --digests ${udmi_ref%:*} | fgrep $udmi_tag | awk '{print $3}') ihash=$udmi_ref@$hash @@ -120,15 +132,14 @@ if [[ $cmd == build && $REPOSITORY != local ]]; then echo Customized output in tmp/$file fi done + echo Done with container build. + for file in tmp/k8s_*.yaml; do + echo " kubectl apply -f $target/$file" + done fi -if [[ $cmd == prep ]]; then - echo Done with container prep. -elif [[ $cmd == build ]]; then - echo Done with container build. +if [[ -n $apply ]]; then for file in tmp/k8s_*.yaml; do - echo kubectl apply -f $target/$file + kubectl apply -f ../$target/$file done -else - fail Unknown container command $cmd fi diff --git a/bin/set_project b/bin/set_project index 557d25c49b..f6574ec407 100755 --- a/bin/set_project +++ b/bin/set_project @@ -2,6 +2,9 @@ if [[ $# != 1 ]]; then echo Usage: $0 gcp_project[/udmi_namespace] + echo + echo Current context/project is $(kubectl config current-context) + echo false fi diff --git a/validator/bin/automate b/validator/bin/automate index 4301b7d188..8edbc78271 100755 --- a/validator/bin/automate +++ b/validator/bin/automate @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/bin/bash -ex # # Automation of tools using PubSub triggers. # @@ -8,7 +8,8 @@ UDMI_PREFIX=${UDMI_NAMESPACE}~ PUBSUB_FILE=pubsub.json MESSAGE_FILE=message.json RETRY_DELAY_SEC=60 -MODEL_DIR=source_model +CLONE_DIR=source_model/ +MODEL_SUBDIR=udmi/ CONFIG_FILE=registrar_config.json REGISTRAR_TRIGGER=run-registrar @@ -60,14 +61,14 @@ while true; do repo_url=$(jq -r .url $MESSAGE_FILE) repo_name=${repo_url##*/} - echo Cloning repo $repo_name from $repo_url into $MODEL_DIR + echo Cloning repo $repo_name from $repo_url into $CLONE_DIR - rm -rf $MODEL_DIR + rm -rf $CLONE_DIR - echo gcloud source repos clone $repo_name $MODEL_DIR --project=$GCP_PROJECT - gcloud source repos clone $repo_name $MODEL_DIR --project=$GCP_PROJECT || true + echo gcloud source repos clone $repo_name $CLONE_DIR --project=$GCP_PROJECT + gcloud source repos clone $repo_name $CLONE_DIR --project=$GCP_PROJECT || true - if [[ ! -d $MODEL_DIR ]]; then + if [[ ! -d $CLONE_DIR ]]; then echo echo Error cloning repo, try again! echo @@ -75,14 +76,39 @@ while true; do fi ( - cd $MODEL_DIR + cd $CLONE_DIR git checkout main || true pwd ls -l ) - if [[ ! -f $MODEL_DIR/$REGISTRAR_TRIGGER ]]; then - echo Missing $MODEL_DIR/$REGISTRAR_TRIGGER trigger file, doing nothing! + if [[ ! -f $CLONE_DIR/$REGISTRAR_TRIGGER ]]; then + echo Missing $CLONE_DIR/$REGISTRAR_TRIGGER trigger file, doing nothing! + continue + fi + + MODEL_DIR=$(realpath $CLONE_DIR/$MODEL_SUBDIR/) + HISTORY_DIR=$MODEL_DIR/history + SUMMARY_FILE=$MODEL_DIR/out/registration_summary.json + + TIMESTAMP=$(date --utc +%y%m%d%H%M%S) + mkdir -p $HISTORY_DIR + HISTORY_FILE=$HISTORY_DIR/registration_summary_${TIMESTAMP}.json + touch $HISTORY_FILE + rm -f $CLONE_DIR/$REGISTRAR_TRIGGER $SUMMARY_FILE + + echo + echo Updating site model with start-of-action: + ( + cd $CLONE_DIR + git add . + git status + git commit -m "Starting registration run $HISTORY_FILE on $HOSTNAME" + git push || touch failed + ) + + if [[ -f $CLONE_DIR/failed ]]; then + echo Run start push failed, aborting. continue fi @@ -92,7 +118,7 @@ while true; do "project_id": "$GCP_PROJECT", "udmi_namespace": "$UDMI_NAMESPACE", "bridge_host": "${host_suffix}", - "site_model": "$MODEL_DIR/udmi" + "site_model": "$MODEL_DIR" } EOF echo Registrar config $CONFIG_FILE: @@ -102,14 +128,15 @@ EOF echo validator/bin/registrar $CONFIG_FILE validator/bin/registrar $CONFIG_FILE || true + cp $SUMMARY_FILE $HISTORY_FILE + echo - echo Site model status: + echo Updating site model with completion results: ( - cd $MODEL_DIR - rm -f $REGISTRAR_TRIGGER - git status + cd $CLONE_DIR git add . - git commit -F udmi/out/registration_summary.json + git status + git commit -F $SUMMARY_FILE git push || true ) done