memgraph/release/package_deploy
Marko Budiselic 9ed4102897 Release preparation.
Summary: Alpha config fix. Docker volume support.

Reviewers: teon.banek, dgleich

Reviewed By: teon.banek, dgleich

Subscribers: pullbot, buda

Differential Revision: https://phabricator.memgraph.io/D484
2017-06-16 15:16:11 +02:00

127 lines
4.0 KiB
Bash
Executable File

#!/bin/bash
# Build, Package (docker image) & Deploy Memgraph
function print_help () {
echo "Usage: $0 [OPTION] --version MAJOR.MINOR.PATCH"
echo "Optional arguments:"
echo -e " -h|--help Print help."
echo -e " --skip-compile Skip compilation process."
echo -e " --skip-deploy Skip deployment process."
echo -e " --docker-image-name Custom docker image name, otherwise the image name will be the same as the package name."
echo -e " -s|--server Deployment server address. -|"
echo -e " -u|--user Deployment server user. -| -> Required if deployment isn't skipped."
echo -e " -k|--key Deployment server SSH key. -|"
}
working_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
project_dir="${working_dir}/.."
# argument parsing
required_args_no=0
skip_compile=false
skip_deploy=false
version=0
docker_image_name=""
while [[ $# -gt 0 ]]
do
case $1 in
-h|--help)
print_help
exit -1
;;
-s|--server)
deploy_server="$2"
required_args_no=$((required_args_no+1))
shift # past argument
;;
-u|--user)
deploy_user="$2"
required_args_no=$((required_args_no+1))
shift # past argument
;;
-k|--key)
deploy_key="$2"
required_args_no=$((required_args_no+1))
shift # past argument
;;
--skip-compile)
skip_compile=true
;;
--skip-deploy)
skip_deploy=true
;;
--docker-image-name)
docker_image_name="$2"
shift
;;
--version)
version=$2
required_args_no=$((required_args_no+1))
shift
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
# arguments validation
# version validation (semantic versioning)
if [[ ! ${version} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo -e "Something is wrong with your version number. Semantic version number is required (MAJOR.MINOR.PATCH).\n"
print_help
exit 1
fi
# validate --skip-deploy, --version, --server, --user, --key
if [[ "${skip_deploy}" == false ]]; then
if [[ ${required_args_no} -ne 4 ]]; then
print_help
exit 1
fi
else # if deploy is skipped server, user and key are not required
if [[ ${required_args_no} -ne 1 ]]; then
print_help
exit 1
fi
fi
echo "Skip compile: ${skip_compile}"
echo "Skip deploy: ${skip_deploy}"
if [[ "${skip_deploy}" == false ]]; then
echo "Deploy server: ${deploy_server}"
echo "Deploy user: ${deploy_user}"
echo "Deploy key: ${deploy_key}"
fi
## build binary
if [[ "${skip_compile}" == true ]]; then
${working_dir}/build_interpreter --skip-compile --version ${version}
else
${working_dir}/build_interpreter --build-type Release --version ${version}
fi
## build package (docker image)
cd ${working_dir}
package_name=`ls -t -d memgraph_*/ | head -1 | sed 's/.$//'`
# for some reason docker image has to be lowercase string
# and because our package name is based on the cmake build type
# string (which can be camel case) the package name has to be transformed
if [[ "${docker_image_name}" == "" ]] ; then
docker_image_name=$(echo "${package_name}"| tr '[:upper:]' '[:lower:]')
fi
docker build -t ${docker_image_name} -f ${working_dir}/alpha.dockerfile --build-arg build_name=${package_name} .
docker save ${docker_image_name} > ${docker_image_name}.tar.gz
if [[ "${skip_deploy}" == false ]]; then
## deploy
# copy package
scp -i ${deploy_key} ${docker_image_name}.tar.gz ${deploy_user}@${deploy_server}:/home/${deploy_user}
# load package
ssh -i ${deploy_key} ${deploy_user}@${deploy_server} docker load -i /home/${deploy_user}/${docker_image_name}.tar.gz
# spin up the instance
public_port=$(echo ${package_name} | grep -o "memgraph_[0-9]*_" | sed 's/[^0-9]*//g')
ssh -i ${deploy_key} ${deploy_user}@${deploy_server} docker run -d --name ${docker_image_name} -p ${public_port}:7687 ${docker_image_name}
fi