#!/usr/bin/bash if [ -n "$1" ]; then if [ "$1" == "--no-cache" ]; then FORCE_NO_CACHE="--no-cache" COMMIT=$(git rev-parse --short HEAD) else COMMIT=$1 if ! git cat-file -e $COMMIT^{commit} 2>/dev/null; then echo "ERROR: Commit $COMMIT not found in local repository." exit 1 fi fi else COMMIT=$(git rev-parse --short HEAD) fi if [ "$COMMIT" == "$(git rev-parse --short HEAD)" ]; then if [ -n "$(git status --porcelain)" ]; then echo "WARNING: You are building the latest commit ${COMMIT}, but you have uncommitted changes." echo " This means that the image will not be reproducible." echo " If you want to build the latest commit, please commit your changes first." read -p "Do you want to continue anyway? [y/N] " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi fi fi check_remote_commit_exists() { local url="$1" local commit="$2" local tmpdir tmpdir="$(mktemp -d)" trap 'rm -rf "$tmpdir"' RETURN git -C "$tmpdir" init -q git -C "$tmpdir" remote add origin "$url" if git -C "$tmpdir" fetch --quiet --depth=1 origin "$commit" 2>/dev/null; then echo "✅ Commit $commit exists on remote." return 0 else echo "❌ ERROR: Commit $commit not found on remote." echo "Refs currently visible on remote:" git ls-remote --heads --tags "$url" return 1 fi } if ! check_remote_commit_exists https://github.com/jkiesele/minicalosim $COMMIT; then echo "WARNING: Commit $COMMIT not found in remote repository." fi if [ "$2" == "--no-cache" ]; then FORCE_NO_CACHE="--no-cache" fi cd "$(dirname "$0")" cd ../../ echo "Building minicalosim-mini:$COMMIT" echo "Current working directory: $(pwd)" docker build $FORCE_NO_CACHE \ -t jkiesele/minicalosim-mini:$COMMIT \ --build-arg USER=$USER \ --build-arg BUILD_DATE="$(date)" \ --build-arg COMMIT=$COMMIT \ -f minicalosim/docker/Dockerfile-mini . echo "successfully built container jkiesele/minicalosim-mini:${COMMIT}" docker tag jkiesele/minicalosim-mini:$COMMIT jkiesele/minicalosim-mini:latest echo "also tagged as jkiesele/minicalosim-mini:latest"