fd19f76cba
Summary: Build, Packege & Deploy script. Reviewers: teon.banek, mferencevic, mislav.bradac, dgleich Reviewed By: dgleich Subscribers: dgleich, pullbot, buda Differential Revision: https://phabricator.memgraph.io/D397
77 lines
2.1 KiB
Bash
Executable File
77 lines
2.1 KiB
Bash
Executable File
#!/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 [--skip-compile]"
|
|
}
|
|
|
|
working_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
project_dir="${working_dir}/.."
|
|
|
|
# argument parsing
|
|
required_args_no=0
|
|
skip_compile=false
|
|
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
|
|
;;
|
|
*)
|
|
# unknown option
|
|
;;
|
|
esac
|
|
shift # past argument or value
|
|
done
|
|
if [[ ${required_args_no} -ne 3 ]]; 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
|
|
else
|
|
${working_dir}/build_interpreter
|
|
fi
|
|
|
|
## build package (docker image)
|
|
cd ${working_dir}
|
|
package_name=`ls -t -d memgraph_*/ | head -1 | sed 's/.$//'`
|
|
docker build -t ${package_name} -f ${working_dir}/alpha_interpreter.dockerfile --build-arg build_name=${package_name} .
|
|
docker save ${package_name} > ${package_name}.tar.gz
|
|
|
|
## deploy
|
|
# copy package
|
|
scp -i ${deploy_key} ${package_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}/${package_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 ${package_name} -p ${public_port}:7687 ${package_name}
|