Run migrations via a collab subcommand
This commit is contained in:
parent
9952f08cce
commit
cedc0f64d5
12 changed files with 180 additions and 113 deletions
|
@ -7,7 +7,7 @@ echo "creating database..."
|
|||
script/sqlx database create
|
||||
|
||||
echo "migrating database..."
|
||||
script/sqlx migrate run
|
||||
cargo run -p collab -- migrate
|
||||
|
||||
echo "seeding database..."
|
||||
script/seed-db
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Prerequisites:
|
||||
#
|
||||
# - Log in to the DigitalOcean API, either interactively, by running
|
||||
# `doctl auth init`, or by setting the `DIGITALOCEAN_ACCESS_TOKEN`
|
||||
# environment variable.
|
||||
|
||||
set -eu
|
||||
source script/lib/deploy-helpers.sh
|
||||
|
||||
if [[ $# < 2 ]]; then
|
||||
echo "Usage: $0 <production|staging|preview> <tag-name>"
|
||||
|
@ -15,28 +10,8 @@ fi
|
|||
export ZED_KUBE_NAMESPACE=$1
|
||||
COLLAB_VERSION=$2
|
||||
|
||||
ENV_FILE="crates/collab/k8s/environments/${ZED_KUBE_NAMESPACE}.sh"
|
||||
if [[ ! -f $ENV_FILE ]]; then
|
||||
echo "Invalid environment name '${ZED_KUBE_NAMESPACE}'"
|
||||
exit 1
|
||||
fi
|
||||
export $(cat $ENV_FILE)
|
||||
|
||||
if [[ ! $COLLAB_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||
echo "Invalid version number '$COLLAB_VERSION'"
|
||||
exit 1
|
||||
fi
|
||||
TAG_NAMES=$(doctl registry repository list-tags collab --no-header --format Tag)
|
||||
if ! $(echo "${TAG_NAMES}" | grep -Fqx v${COLLAB_VERSION}); then
|
||||
echo "No such image tag: 'zed/collab:v${COLLAB_VERSION}'"
|
||||
echo "Found tags"
|
||||
echo "${TAG_NAMES}"
|
||||
exit 1
|
||||
fi
|
||||
export ZED_IMAGE_ID="registry.digitalocean.com/zed/collab:v${COLLAB_VERSION}"
|
||||
|
||||
if [[ $(kubectl config current-context 2> /dev/null) != do-nyc1-zed-1 ]]; then
|
||||
doctl kubernetes cluster kubeconfig save zed-1
|
||||
fi
|
||||
export_vars_for_environment $ZED_KUBE_NAMESPACE
|
||||
export ZED_IMAGE_ID=$(image_id_for_version $COLLAB_VERSION)
|
||||
target_zed_kube_cluster
|
||||
|
||||
envsubst < crates/collab/k8s/manifest.template.yml | kubectl apply -f -
|
||||
|
|
|
@ -1,42 +1,20 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Prerequisites:
|
||||
#
|
||||
# - Log in to the DigitalOcean docker registry
|
||||
# doctl registry login
|
||||
#
|
||||
# - Target the `zed-1` kubernetes cluster
|
||||
# doctl kubernetes cluster kubeconfig save zed-1
|
||||
|
||||
set -eu
|
||||
source script/lib/deploy-helpers.sh
|
||||
|
||||
if [[ $# < 1 ]]; then
|
||||
echo "Usage: $0 [production|staging|...]"
|
||||
if [[ $# < 2 ]]; then
|
||||
echo "Usage: $0 <production|staging|preview> <tag-name>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export ZED_KUBE_NAMESPACE=$1
|
||||
ENV_FILE="crates/collab/k8s/environments/${ZED_KUBE_NAMESPACE}.sh"
|
||||
if [[ ! -f $ENV_FILE ]]; then
|
||||
echo "Invalid environment name '${ZED_KUBE_NAMESPACE}'"
|
||||
exit 1
|
||||
fi
|
||||
COLLAB_VERSION=$2
|
||||
|
||||
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 $ZED_IMAGE_ID
|
||||
docker push $ZED_IMAGE_ID
|
||||
export_vars_for_environment $ZED_KUBE_NAMESPACE
|
||||
export ZED_IMAGE_ID=$(image_id_for_version ${COLLAB_VERSION})
|
||||
export ZED_MIGRATE_JOB_NAME=zed-migrate-${COLLAB_VERSION}
|
||||
target_zed_kube_cluster
|
||||
|
||||
envsubst < crates/collab/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
|
||||
|
|
43
script/lib/deploy-helpers.sh
Normal file
43
script/lib/deploy-helpers.sh
Normal file
|
@ -0,0 +1,43 @@
|
|||
# Prerequisites:
|
||||
#
|
||||
# - Log in to the DigitalOcean API, either interactively, by running
|
||||
# `doctl auth init`, or by setting the `DIGITALOCEAN_ACCESS_TOKEN`
|
||||
# environment variable.
|
||||
|
||||
function export_vars_for_environment {
|
||||
local environment=$1
|
||||
local env_file="crates/collab/k8s/environments/${environment}.sh"
|
||||
if [[ ! -f $env_file ]]; then
|
||||
echo "Invalid environment name '${environment}'"
|
||||
exit 1
|
||||
fi
|
||||
export $(cat $env_file)
|
||||
}
|
||||
|
||||
function image_id_for_version {
|
||||
local version=$1
|
||||
if [[ ! ${version} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||
echo "Invalid version number '${version}'"
|
||||
exit 1
|
||||
fi
|
||||
TAG_NAMES=$(doctl registry repository list-tags collab --no-header --format Tag)
|
||||
if ! $(echo "${TAG_NAMES}" | grep -Fqx v${version}); then
|
||||
echo "No such image tag: 'zed/collab:v${version}'"
|
||||
echo "Found tags"
|
||||
echo "${TAG_NAMES}"
|
||||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue