From 2f1ddc0d0f704d0ad343b67df50397d2cfd16928 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 21 Oct 2022 15:50:14 -0700 Subject: [PATCH] Improve deploy scripts --- crates/collab/k8s/migrate.template.yml | 1 + script/deploy | 15 ++++++++++----- script/deploy-migration | 22 ++++++++++++++-------- script/lib/deploy-helpers.sh | 23 ++++++++++------------- script/what-is-deployed | 26 ++++++++++++++++++++++---- 5 files changed, 57 insertions(+), 30 deletions(-) diff --git a/crates/collab/k8s/migrate.template.yml b/crates/collab/k8s/migrate.template.yml index 3a848da85a..c890d7b330 100644 --- a/crates/collab/k8s/migrate.template.yml +++ b/crates/collab/k8s/migrate.template.yml @@ -9,6 +9,7 @@ spec: restartPolicy: Never containers: - name: migrator + imagePullPolicy: Always image: ${ZED_IMAGE_ID} args: - migrate diff --git a/script/deploy b/script/deploy index f7da274841..f675da6a99 100755 --- a/script/deploy +++ b/script/deploy @@ -7,11 +7,16 @@ if [[ $# < 2 ]]; then echo "Usage: $0 " exit 1 fi -export ZED_KUBE_NAMESPACE=$1 -COLLAB_VERSION=$2 +environment=$1 +version=$2 + +export_vars_for_environment ${environment} +image_id=$(image_id_for_version ${version}) + +export ZED_KUBE_NAMESPACE=${environment} +export ZED_IMAGE_ID=${image_id} -export_vars_for_environment $ZED_KUBE_NAMESPACE -export ZED_IMAGE_ID=$(image_id_for_version $COLLAB_VERSION) target_zed_kube_cluster - envsubst < crates/collab/k8s/manifest.template.yml | kubectl apply -f - + +echo "deployed collab v${version} to ${environment}" \ No newline at end of file diff --git a/script/deploy-migration b/script/deploy-migration index 6812be3217..a6b1574c04 100755 --- a/script/deploy-migration +++ b/script/deploy-migration @@ -7,14 +7,20 @@ if [[ $# < 2 ]]; then echo "Usage: $0 " exit 1 fi -export ZED_KUBE_NAMESPACE=$1 -COLLAB_VERSION=$2 +environment=$1 +version=$2 + +export_vars_for_environment ${environment} +image_id=$(image_id_for_version ${version}) + +export ZED_KUBE_NAMESPACE=${environment} +export ZED_IMAGE_ID=${image_id} +export ZED_MIGRATE_JOB_NAME=zed-migrate-${version} -export_vars_for_environment $ZED_KUBE_NAMESPACE -export ZED_IMAGE_ID=$(image_id_for_version ${COLLAB_VERSION}) -export ZED_MIGRATE_JOB_NAME=zed-migrate-${COLLAB_VERSION} target_zed_kube_cluster - envsubst < crates/collab/k8s/migrate.template.yml | kubectl apply -f - -pod=$(kubectl --namespace=${ZED_KUBE_NAMESPACE} get pods --selector=job-name=${ZED_MIGRATE_JOB_NAME} --output=jsonpath='{.items[*].metadata.name}') -echo "pod:" $pod + +pod=$(kubectl --namespace=${environment} get pods --selector=job-name=${ZED_MIGRATE_JOB_NAME} --output=jsonpath='{.items[0].metadata.name}') + +echo "Job pod:" $pod +kubectl --namespace=${environment} logs -f ${pod} \ No newline at end of file diff --git a/script/lib/deploy-helpers.sh b/script/lib/deploy-helpers.sh index 78ffa22671..705ae6e80c 100644 --- a/script/lib/deploy-helpers.sh +++ b/script/lib/deploy-helpers.sh @@ -1,14 +1,8 @@ -# Prerequisites: -# -# - Log in to the DigitalOcean API, either interactively, by running -# `doctl auth init`, or by setting the `DIGITALOCEAN_ACCESS_TOKEN` -# environment variable. - function export_vars_for_environment { local environment=$1 local env_file="crates/collab/k8s/environments/${environment}.sh" if [[ ! -f $env_file ]]; then - echo "Invalid environment name '${environment}'" + echo "Invalid environment name '${environment}'" >&2 exit 1 fi export $(cat $env_file) @@ -16,15 +10,18 @@ function export_vars_for_environment { function image_id_for_version { local version=$1 + + # Check that version is valid if [[ ! ${version} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "Invalid version number '${version}'" + echo "Invalid version number '${version}'" >&2 exit 1 fi - TAG_NAMES=$(doctl registry repository list-tags collab --no-header --format Tag) - if ! $(echo "${TAG_NAMES}" | grep -Fqx v${version}); then - echo "No such image tag: 'zed/collab:v${version}'" - echo "Found tags" - echo "${TAG_NAMES}" + + # Check that image exists for version + tag_names=$(doctl registry repository list-tags collab --no-header --format Tag) + if ! $(echo "${tag_names}" | grep -Fqx v${version}); then + echo "No docker image tagged for version '${version}'" >&2 + echo "Found images with these tags:" ${tag_names} >&2 exit 1 fi diff --git a/script/what-is-deployed b/script/what-is-deployed index 384686493f..6df2449b90 100755 --- a/script/what-is-deployed +++ b/script/what-is-deployed @@ -7,11 +7,29 @@ if [[ $# < 1 ]]; then echo "Usage: $0 " exit 1 fi -ZED_KUBE_NAMESPACE=$1 +environment=$1 -export_vars_for_environment $ZED_KUBE_NAMESPACE +export_vars_for_environment ${environment} target_zed_kube_cluster -IMAGE_ID=$(kubectl --namespace=${ZED_KUBE_NAMESPACE} get deployment collab -o 'jsonpath={.spec.template.spec.containers[0].image}') +deployed_image_id=$( + kubectl \ + --namespace=${environment} \ + get deployment collab \ + -o 'jsonpath={.spec.template.spec.containers[0].image}' \ + | cut -d: -f2 +) -echo "Deployed image on ${ZED_KUBE_NAMESPACE}:" $(version_for_image_id $IMAGE_ID) \ No newline at end of file +job_image_ids=$( + kubectl \ + --namespace=${environment} \ + get jobs \ + -o 'jsonpath={range .items[0:5]}{.spec.template.spec.containers[0].image}{"\n"}{end}' +) + +echo "Deployed image version:" +echo "$deployed_image_id" +echo +echo "Migration job image versions:" +echo "$job_image_ids" +echo