This generalizes the deploy step into a configurable CircleCI command. The available parameters are: - `namespace`: the K8s namespace to alter - `tag`: the docker tag to apply to the image The script for applying migrations to the K8s environment and the corresponding K8s Job config have been generalized so that they can be configured to run in the specified namespace. The main workflow has been updated so that the appropriate deployment will happen, depending on whether we are merging to staging or master. In the future, we could look to add an additional workflow based around Git tags for production. Note that this also removes the creation of the `latest` tag from CD. That tag is no longer hard-coded into our K8s config and so there's no longer a need to update it in our container registry.
39 lines
954 B
Bash
Executable File
39 lines
954 B
Bash
Executable File
#!/bin/sh
|
|
|
|
if [ -z "${K8S_CONTEXT+is_set}" ]; then
|
|
K8S_CMD="kubectl"
|
|
else
|
|
K8S_CMD="kubectl --context=$K8S_CONTEXT"
|
|
fi
|
|
|
|
if [ -z "${MIGRATION_TIMEOUT+is_set}" ]; then
|
|
MIGRATION_TIMEOUT=120s
|
|
fi
|
|
|
|
if [ -z "${K8S_NAMESPACE+is_set}" ]; then
|
|
K8S_NAMESPACE=atat
|
|
fi
|
|
|
|
echo "Creating job..."
|
|
envsubst < deploy/shared/migration.yaml | $K8S_CMD -n ${K8S_NAMESPACE} apply -f -
|
|
|
|
echo "Wait for job to finish or timeout..."
|
|
JOB_SUCCESS=$(${K8S_CMD} -n ${K8S_NAMESPACE} wait --for=condition=complete --timeout=${MIGRATION_TIMEOUT} job/migration)
|
|
|
|
delete_job () {
|
|
echo "Deleting job..."
|
|
$K8S_CMD -n ${K8S_NAMESPACE} delete job migration
|
|
}
|
|
|
|
if echo "$JOB_SUCCESS" | grep -q "condition met"; then
|
|
echo "Job ran successfully."
|
|
delete_job
|
|
exit 0
|
|
else
|
|
POD_NAME=$(${K8S_CMD} -n ${K8S_NAMESPACE} get pods -l job-name=migration -o=jsonpath='{.items[0].metadata.name}')
|
|
echo "Job failed:"
|
|
$K8S_CMD -n ${K8S_NAMESPACE} logs $POD_NAME
|
|
delete_job
|
|
exit 1
|
|
fi
|