1function export_vars_for_environment {
2 local environment=$1
3 local env_file="crates/collab/k8s/environments/${environment}.sh"
4 if [[ ! -f $env_file ]]; then
5 echo "Invalid environment name '${environment}'" >&2
6 exit 1
7 fi
8 export $(cat $env_file)
9}
10
11function image_id_for_version {
12 local version=$1
13
14 # Check that version is valid
15 if [[ ! ${version} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
16 echo "Invalid version number '${version}'" >&2
17 exit 1
18 fi
19
20 # Check that image exists for version
21 tag_names=$(doctl registry repository list-tags collab --no-header --format Tag)
22 if ! $(echo "${tag_names}" | grep -Fqx v${version}); then
23 echo "No docker image tagged for version '${version}'" >&2
24 echo "Found images with these tags:" ${tag_names} >&2
25 exit 1
26 fi
27
28 echo "registry.digitalocean.com/zed/collab:v${version}"
29}
30
31function version_for_image_id {
32 local image_id=$1
33 echo $image_id | cut -d: -f2
34}
35
36function target_zed_kube_cluster {
37 if [[ $(kubectl config current-context 2> /dev/null) != do-nyc1-zed-1 ]]; then
38 doctl kubernetes cluster kubeconfig save zed-1
39 fi
40}