Generalize deploy scripts to work w/ both production and staging
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
1cfdd07d40
commit
7599ac1e8c
7 changed files with 91 additions and 30 deletions
|
@ -1,11 +1,42 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
# Prerequisites:
|
||||
#
|
||||
# - Log in to the DigitalOcean docker registry
|
||||
# doctl registry login
|
||||
#
|
||||
# - Target the `zed-1` kubernetes cluster
|
||||
# doctl kubernetes cluster kubeconfig save zed-1
|
||||
|
||||
IMAGE_ID=registry.digitalocean.com/zed/zed-migrator
|
||||
set -eu
|
||||
|
||||
if [[ $# < 1 ]]; then
|
||||
echo "Usage: $0 [production|staging|...]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export ZED_KUBE_NAMESPACE=$1
|
||||
ENV_FILE="server/k8s/environments/${ZED_KUBE_NAMESPACE}.sh"
|
||||
if [[ ! -f $ENV_FILE ]]; then
|
||||
echo "Invalid environment name '${ZED_KUBE_NAMESPACE}'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -n $(git status --short) ]]; then
|
||||
echo "Cannot deploy with uncommited changes"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
git_sha=$(git rev-parse HEAD)
|
||||
export ZED_IMAGE_ID=registry.digitalocean.com/zed/zed-migrator:${ZED_KUBE_NAMESPACE}-${git_sha}
|
||||
export ZED_MIGRATE_JOB_NAME=zed-migrate-${git_sha}
|
||||
|
||||
docker build . \
|
||||
--file ./Dockerfile.migrator \
|
||||
--tag $IMAGE_ID
|
||||
docker push $IMAGE_ID
|
||||
kubectl apply -f ./server/migrate.yml
|
||||
--tag $ZED_IMAGE_ID
|
||||
docker push $ZED_IMAGE_ID
|
||||
|
||||
envsubst < server/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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue