Deploy collab like nightly (#7174)
After this change we'll be able to push a tag to github to deploy to collab. The advantages of this are that there's no longer a separate step to first build the image, and then deploy it. In the future I'd like to make this happen more automatically (maybe as part of bump nightly). Release Notes: - N/A
This commit is contained in:
parent
5424c8bfd5
commit
7b9d51929d
9 changed files with 188 additions and 115 deletions
|
@ -1,8 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [[ $# < 1 ]]; then
|
||||
echo "Missing version increment (major, minor, or patch)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exec script/lib/bump-version.sh collab collab-v '' $1
|
|
@ -3,22 +3,19 @@
|
|||
set -eu
|
||||
source script/lib/deploy-helpers.sh
|
||||
|
||||
if [[ $# < 2 ]]; then
|
||||
echo "Usage: $0 <production|staging> <tag-name>"
|
||||
if [[ $# != 1 ]]; then
|
||||
echo "Usage: $0 <production|staging>"
|
||||
exit 1
|
||||
fi
|
||||
environment=$1
|
||||
version=$2
|
||||
tag="$(tag_for_environment $environment)"
|
||||
|
||||
export_vars_for_environment ${environment}
|
||||
image_id=$(image_id_for_version ${version})
|
||||
branch=$(git rev-parse --abbrev-ref HEAD)
|
||||
if [ "$branch" != "main" ]; then
|
||||
echo "You must be on main to run this script"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export ZED_DO_CERTIFICATE_ID=$(doctl compute certificate list --format ID --no-header)
|
||||
export ZED_KUBE_NAMESPACE=${environment}
|
||||
export ZED_IMAGE_ID=${image_id}
|
||||
|
||||
target_zed_kube_cluster
|
||||
envsubst < crates/collab/k8s/collab.template.yml | kubectl apply -f -
|
||||
kubectl -n "$environment" rollout status deployment/collab --watch
|
||||
|
||||
echo "deployed collab v${version} to ${environment}"
|
||||
echo git pull --ff-only origin main
|
||||
echo git tag -f $tag
|
||||
echo git push -f origin $tag
|
||||
|
|
|
@ -8,33 +8,30 @@ function export_vars_for_environment {
|
|||
export $(cat $env_file)
|
||||
}
|
||||
|
||||
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}'" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 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
|
||||
|
||||
echo "registry.digitalocean.com/zed/collab:v${version}"
|
||||
}
|
||||
|
||||
function version_for_image_id {
|
||||
local image_id=$1
|
||||
echo $image_id | cut -d: -f2
|
||||
}
|
||||
|
||||
function target_zed_kube_cluster {
|
||||
if [[ $(kubectl config current-context 2> /dev/null) != do-nyc1-zed-1 ]]; then
|
||||
doctl kubernetes cluster kubeconfig save zed-1
|
||||
fi
|
||||
}
|
||||
|
||||
function tag_for_environment {
|
||||
if [[ "$1" == "production" ]]; then
|
||||
echo "collab-production"
|
||||
elif [[ "$1" == "staging" ]]; then
|
||||
echo "collab-staging"
|
||||
else
|
||||
echo "Invalid environment name '${environment}'" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function url_for_environment {
|
||||
if [[ "$1" == "production" ]]; then
|
||||
echo "https://collab.zed.dev"
|
||||
elif [[ "$1" == "staging" ]]; then
|
||||
echo "https://collab-staging.zed.dev"
|
||||
else
|
||||
echo "Invalid environment name '${environment}'" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
|
|
@ -3,13 +3,15 @@
|
|||
set -eu
|
||||
source script/lib/deploy-helpers.sh
|
||||
|
||||
if [[ $# < 1 ]]; then
|
||||
if [[ $# != 1 ]]; then
|
||||
echo "Usage: $0 <production|staging>"
|
||||
exit 1
|
||||
fi
|
||||
environment=$1
|
||||
|
||||
export_vars_for_environment ${environment}
|
||||
environment=$1
|
||||
url="$(url_for_environment $environment)"
|
||||
tag="$(tag_for_environment $environment)"
|
||||
|
||||
target_zed_kube_cluster
|
||||
|
||||
deployed_image_id=$(
|
||||
|
@ -20,18 +22,9 @@ deployed_image_id=$(
|
|||
| cut -d: -f2
|
||||
)
|
||||
|
||||
job_image_ids=$(
|
||||
kubectl \
|
||||
--namespace=${environment} \
|
||||
get jobs \
|
||||
-o 'jsonpath={range .items[0:5]}{.spec.template.spec.containers[0].image}{"\n"}{end}' \
|
||||
2> /dev/null \
|
||||
|| true
|
||||
)
|
||||
echo "Deployed image version: $deployed_image_id"
|
||||
|
||||
echo "Deployed image version:"
|
||||
echo "$deployed_image_id"
|
||||
echo
|
||||
echo "Migration job image versions:"
|
||||
echo "$job_image_ids"
|
||||
echo
|
||||
git fetch >/dev/null
|
||||
if [[ "$(git rev-parse tags/$tag)" != $deployed_image_id ]]; then
|
||||
echo "NOTE: tags/$tag $(git rev-parse tags/$tag) is not yet deployed"
|
||||
fi;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue