#!/bin/bash set -e trap 'catch $? $LINENO' EXIT usage() { echo "Usage: $0" echo " Build the Cardano Builder container." echo "" echo "Available options:" echo " --tag* The cardano-builder container tag [Default: none] [Example: latest, 1.0]" echo " --agent Which agent to use to push the container [Default: docker] [docker|buildah]" echo " --help Display this message" echo " * = mandatory options" exit 0 } catch() { if [ "$1" != "0" ]; then echo "An error has occured. Abording." exit 0 fi } help=${help:-false} tag=${tag:-} agent=${agent:-docker} while [ $# -gt 0 ]; do if [[ $1 == *"--"* ]]; then param="${1/--/}" declare $param="$2" 2>/dev/null fi shift done if [ "$help" != false ]; then usage fi if [ -z "$tag" ]; then usage fi build_path=${PWD} echo "" echo "Verify the options before continuing :" echo "" echo "tag : $tag" echo "agent : $agent" echo "build path : $build_path" echo "" read -n 1 -s -r -p "Press any key to continue" echo "" if [ ! -d "${build_path}" ]; then echo "Build path ${build_path} doesn't exist" exit 0 fi tag="cardano-builder:${tag}" echo "Cleaning local repository ${tag}..." set +e ${agent} rmi "localhost/${tag}" 2>/dev/null set -e echo "Building image ${tag}..." case "${agent}" in "docker") ${agent} build --tag ${tag} ${build_path} ;; "buildah") ${agent} bud --tag ${tag} ${build_path} ;; esac echo "Image ${tag} built successfully..." echo "" ${agent} images | grep -i "cardano-builder"