#!/bin/bash # potential flags: custom tag, no squash, delete/redo, custom dir # Parameters if [[ $# -eq 0 ]]; then echo "Usage: $0 imagedir [containername]" exit 0 fi if [[ ! -d $1 ]]; then echo "Error: directory \"$1\" not found." exit 1 else proj=$1 fi if [[ -n $2 ]]; then cont=$2 else cont=$proj fi fail() { podman image rm $proj:$today podman rm -f $cont echo "Encountered unexpected error. Exiting." exit 2 } today=$(date "+%Y-%m-%d-T%H%M") tag=latest # Main set -e cd $proj # execute install script if it exists # install script should be idempotent if [[ -f Install ]]; then ./Install fi # build image echo "Building container ..." podman build -f Containerfile -t $proj:$today -t $proj:$tag || fail #--squash # start container echo "Creating container ..." podman create --name $cont $proj:$today || fail podman start $cont || fail # Systemdfile is for commands that need systemd to execute echo "Running build steps that require systemd ..." podman exec $cont bash -c "if [ -f /root/Systemdfile ]; then /root/Systemdfile; fi" || fail echo "Finished!" # get container IP printf "Container IP is: " podman inspect -f '{{ .NetworkSettings.IPAddress }}' $cont #echo "Use this address to configure your reverse proxy" # todo: configure autostart service # todo: handle volumes