2021-07-12 23:14:39 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Prerequisites:
|
|
|
|
#
|
|
|
|
# - Log in to the DigitalOcean docker registry
|
|
|
|
# doctl registry login
|
|
|
|
#
|
2021-09-30 00:08:53 +03:00
|
|
|
# - Target the `zed-1` kubernetes cluster
|
2021-07-12 23:14:39 +03:00
|
|
|
# doctl kubernetes cluster kubeconfig save zed-1
|
|
|
|
|
2021-09-30 00:08:53 +03:00
|
|
|
set -eu
|
2021-07-12 23:14:39 +03:00
|
|
|
|
2021-09-30 00:08:53 +03:00
|
|
|
if [[ $# < 1 ]]; then
|
|
|
|
echo "Usage: $0 [production|staging|...]"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-07-12 23:14:39 +03:00
|
|
|
|
2021-09-30 00:08:53 +03:00
|
|
|
export ZED_KUBE_NAMESPACE=$1
|
2021-11-04 05:22:00 +03:00
|
|
|
ENV_FILE="crates/server/k8s/environments/${ZED_KUBE_NAMESPACE}.sh"
|
2021-09-30 00:08:53 +03:00
|
|
|
if [[ ! -f $ENV_FILE ]]; then
|
|
|
|
echo "Invalid environment name '${ZED_KUBE_NAMESPACE}'"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-09-30 00:53:52 +03:00
|
|
|
if [[ $ZED_KUBE_NAMESPACE == "production" && -n $(git status --short) ]]; then
|
|
|
|
echo "Cannot deploy uncommited changes to production"
|
2021-09-30 00:08:53 +03:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
git_sha=$(git rev-parse HEAD)
|
2021-09-30 00:53:52 +03:00
|
|
|
export ZED_IMAGE_ID="registry.digitalocean.com/zed/zed-server:${ZED_KUBE_NAMESPACE}-${git_sha}"
|
2021-09-30 00:08:53 +03:00
|
|
|
export $(cat $ENV_FILE)
|
|
|
|
|
2021-09-30 00:53:52 +03:00
|
|
|
docker build . --tag "$ZED_IMAGE_ID"
|
|
|
|
docker push "$ZED_IMAGE_ID"
|
2021-09-30 00:08:53 +03:00
|
|
|
|
2021-11-04 05:22:00 +03:00
|
|
|
envsubst < crates/server/k8s/manifest.template.yml | kubectl apply -f -
|