test-continuous-deployment/deploy/deploy-stack.sh

82 lines
2.1 KiB
Bash
Raw Permalink Normal View History

2024-06-03 02:24:20 +00:00
#!/usr/bin/env bash
2024-06-10 12:12:57 +00:00
# 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.
2024-06-03 02:24:20 +00:00
set -e
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi
2024-06-10 12:12:57 +00:00
if [[ $# -ne 2 ]]; then
echo "Usage: $0 <deployment-name> <deploy-this-branch>" >&2
exit 1
fi
2024-06-03 02:24:20 +00:00
2024-06-10 12:12:57 +00:00
deployment_name=$1
deploy_this_branch=$2
2024-06-03 02:24:20 +00:00
2024-06-10 12:12:57 +00:00
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}
2024-06-03 02:24:20 +00:00
2024-06-10 12:12:57 +00:00
deploy_fail_exit () {
2024-06-03 02:24:20 +00:00
local fail_message=$1
2024-06-10 12:12:57 +00:00
echo "${deployment_name}: ${fail_message}"
echo "${deployment_name}: FAILED"
2024-06-03 02:24:20 +00:00
exit 1
}
log_info () {
local message=$1
2024-06-10 12:12:57 +00:00
echo "$(date +"%Y-%m-%d %T") (${deployment_name}) ${message}"
2024-06-03 02:24:20 +00:00
}
2024-06-10 12:12:57 +00:00
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
2024-06-03 02:24:20 +00:00
exit $deployment_result