memgraph/release/package_deploy

87 lines
2.6 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# Build, Package (docker image) & Deploy Memgraph
function print_help () {
echo "Usage: $0 [-h|--help] -s|--server deploy_server_domain -u|--user username -k|--key private_user_key --version X.Y.Z [--skip-compile]"
}
working_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
project_dir="${working_dir}/.."
# argument parsing
required_args_no=0
skip_compile=false
version=0
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
;;
--version)
version=$2
required_args_no=$((required_args_no+1))
shift
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
if [[ ${required_args_no} -ne 4 ]]; then
print_help
exit -1
fi
echo "Deploy server: ${deploy_server}"
echo "Deploy user: ${deploy_user}"
echo "Deploy key: ${deploy_key}"
echo "Skip compile: ${skip_compile}"
## build binary
if [[ "${skip_compile}" == true ]]; then
${working_dir}/build_interpreter --skip-compile --version ${version}
else
${working_dir}/build_interpreter --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
docker_image_name=$(echo "${package_name}"| tr '[:upper:]' '[:lower:]')
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
## 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}