82 lines
2.1 KiB
Bash
Executable File
82 lines
2.1 KiB
Bash
Executable File
#!/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
|
|
|
|
if [[ $# -ne 2 ]]; then
|
|
echo "Usage: $0 <deployment-name> <deploy-this-branch>" >&2
|
|
exit 1
|
|
fi
|
|
|
|
deployment_name=$1
|
|
deploy_this_branch=$2
|
|
|
|
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}
|
|
|
|
deploy_fail_exit () {
|
|
local fail_message=$1
|
|
echo "${deployment_name}: ${fail_message}"
|
|
echo "${deployment_name}: FAILED"
|
|
exit 1
|
|
}
|
|
|
|
log_info () {
|
|
local message=$1
|
|
echo "$(date +"%Y-%m-%d %T") (${deployment_name}) ${message}"
|
|
}
|
|
|
|
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
|