#!/bin/bash -e # Build and package Docker image of Memgraph. function print_help () { echo "Usage: $0 [--latest] MEMGRAPH_PACKAGE.deb" echo "Optional arguments:" echo -e "\t-h|--help\t\tPrint help." echo -e "\t--latest\t\tTag image as latest version." } working_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" latest_image="" tag_latest="" if [[ $# -eq 2 && "$1" == "--latest" ]]; then latest_image="memgraph:latest" tag_latest="-t memgraph:latest" shift elif [[ $# -ne 1 || "$1" == "-h" || "$1" == "--help" ]]; then print_help exit 1 fi deb_path="$1" if [[ ! -f "$deb_path" ]]; then echo "File '$deb_path' does not exist!" exit 1 fi # Copy the .deb to working directory. cp "$deb_path" "${working_dir}/" cd ${working_dir} # Extract version and offering from deb name. deb_name=`echo $(basename "$deb_path") | sed 's/.deb$//'` version=`echo ${deb_name} | cut -d '_' -f 2 | rev | cut -d '-' -f 2- | rev | tr '+~' '__'` dockerfile_path="${working_dir}/memgraph.dockerfile" image_name="memgraph:${version}" package_name="memgraph-${version}-docker.tar.gz" # Build docker image. docker build -t ${image_name} ${tag_latest} -f ${dockerfile_path} --build-arg deb_release=${deb_name}.deb . docker save ${image_name} ${latest_image} > ${package_name} rm "${deb_name}.deb" echo "Built Docker image at '${working_dir}/${package_name}'"