1# Prerequisites:
2#
3# - Log in to the DigitalOcean API, either interactively, by running
4# `doctl auth init`, or by setting the `DIGITALOCEAN_ACCESS_TOKEN`
5# environment variable.
6
7function export_vars_for_environment {
8 local environment=$1
9 local env_file="crates/collab/k8s/environments/${environment}.sh"
10 if [[ ! -f $env_file ]]; then
11 echo "Invalid environment name '${environment}'"
12 exit 1
13 fi
14 export $(cat $env_file)
15}
16
17function image_id_for_version {
18 local version=$1
19 if [[ ! ${version} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
20 echo "Invalid version number '${version}'"
21 exit 1
22 fi
23 TAG_NAMES=$(doctl registry repository list-tags collab --no-header --format Tag)
24 if ! $(echo "${TAG_NAMES}" | grep -Fqx v${version}); then
25 echo "No such image tag: 'zed/collab:v${version}'"
26 echo "Found tags"
27 echo "${TAG_NAMES}"
28 exit 1
29 fi
30
31 echo "registry.digitalocean.com/zed/collab:v${version}"
32}
33
34function version_for_image_id {
35 local image_id=$1
36 echo $image_id | cut -d: -f2
37}
38
39function target_zed_kube_cluster {
40 if [[ $(kubectl config current-context 2> /dev/null) != do-nyc1-zed-1 ]]; then
41 doctl kubernetes cluster kubeconfig save zed-1
42 fi
43}