Flesh out deploy script

This commit is contained in:
David Boreham 2024-06-10 06:12:57 -06:00
parent 4658d212a5
commit d76461e718

View File

@ -1,27 +1,81 @@
#!/usr/bin/env bash
# Takes two parameters: <deployment-name> <deploy-this-branch>
# e.g. deploy-stack.sh production main
# The special value "test" when supplied as the deployment name invokes
# test mode which does not do any actual deployment.
set -e
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi
SO_COMMAND=laconic-so
if [[ $# -ne 2 ]]; then
echo "Usage: $0 <deployment-name> <deploy-this-branch>" >&2
exit 1
fi
deploy_name="Deploy test stack"
deployment_name=$1
deploy_this_branch=$2
deployment_result=0
stack_repo_name="test-deployment-stack"
stack_name="test-deployment-stack"
stack_path=$(pwd)/${stack_repo_name}/stack-orchestrator/stacks/${stack_name}
deployment_dirs_base=$(pwd)/deployment-repo/deployments
deployment_dir=${deployment_dirs_base}/${deployment_name}
test_fail_exit () {
deploy_fail_exit () {
local fail_message=$1
echo "${deploy_name}: ${fail_message}"
echo "${deploy_name}: FAILED"
echo "${deployment_name}: ${fail_message}"
echo "${deployment_name}: FAILED"
exit 1
}
log_info () {
local message=$1
echo "$(date +"%Y-%m-%d %T"): ${message}"
echo "$(date +"%Y-%m-%d %T") (${deployment_name}) ${message}"
}
log_info "Deployment goes here"
if [[ $deployment_name == "test" ]]; then
test_mode=1
fi
if [[ $test_mode ]]; then
log_info "******* Running deployment script in test mode *******"
fi
SO_COMMAND=laconic-so
deployment_result=0
log_info "Deploying branch: ${deploy_this_branch}"
if [[ ! $test_mode == 1 ]]; then
log_info "Checking deployment directory"
if [[ ! -d $deployment_dir ]]; then
deploy_fail_exit "Deployment directory: $deployment_dir does not exist"
fi
fi
log_info "Setting up repositories"
log_info "Cloning repositories into: $CERC_REPO_BASE_DIR"
$SO_COMMAND --quiet --stack ${stack_path} setup-repositories --branches git.vdb.to/cerc-io/test-project@${deploy_this_branch}
log_info "Building containers"
$SO_COMMAND --quiet --stack ${stack_path} build-containers
log_info "container image list:"
docker image ls
if [[ ! $test_mode == 1 ]]; then
log_info "Pushing container images to cluster"
$SO_COMMAND deployment --dir ${deployment_dir} push-images
log_info "Updating deployment"
$SO_COMMAND deployment --dir ${deployment_dir} update
else
log_info "******* Skipping deployment in test mode *******"
fi
exit $deployment_result