#!/bin/bash # potential flags: custom tag, squash, delete/redo, custom dir, debug (don't delete tmp), custom build image # todo: configure autostart service # todo: handle volumes # Variables quit() { podman rm -f tmp-$epoch 2>&1 > /dev/null exit $1 } today=$(date "+%Y-%m-%d-T%H%M") epoch=$(date "+%s.%3N") tag=latest # Handle errors/arguments if [[ $# -eq 0 ]]; then echo "Usage: $0 directory [image_name]" exit 0 fi if [[ ! -d $1 ]]; then echo "Error: directory \"$1\" not found." exit 1 fi cd $1 if [[ -n $2 ]]; then name=$2 else name=$(basename $(pwd)) fi # Main # build image echo "Building container ..." podman build -f Containerfile -t tmp:$epoch || quit 2 # start container echo "Creating container ..." podman create --name tmp-$epoch tmp:$epoch || quit 2 podman start tmp-$epoch || quit 2 # Systemdfile is for commands that need systemd to execute echo "Running build steps that require systemd ..." podman exec tmp-$epoch bash -c "if [ -f /root/Systemdfile ]; then /root/Systemdfile; fi" || quit 2 # commit finalized container state to image echo "Committing container to image ..." podman commit tmp-$epoch $name:$today || quit 2 # tag with latest tag podman tag $name:$today $name:$tag echo "Finished!" quit 0