#!/bin/bash # usage: laminarc queue build_publish_image registry="oci.liz.coffee" \ # repo="src/cgit" tag="latest" remote="ssh://src.liz.coffee:2222/cgit" \ # rev="" image_file="Dockerfile" set -e declare -a args=("$registry" "$repo" "$tag" "$remote" "$rev" "$image_file") for arg in "${args[@]}" do if [[ ! "$arg" =~ ^[[:alnum:]:_\.\/\-]*$ ]]; then echo "Invalid argument format. Don't be sneaky snek (-_-)." exit 1 fi done log "Logging into registry $registry" registry_username="$(get_secret $registry | jq -r ".login.username")" get_secret $registry | jq -r ".login.password" \ | docker login --username "$registry_username" --password-stdin "$registry" log "Cloning remote $remote" r=$(echo "build-$(date --iso-8601=seconds)") git clone "$remote" "$r" && cd "$r" git checkout "$rev" image_tag="$registry/$repo:$tag" log "Building image $image_tag" env -i HOME="$HOME" bash -l -c "docker build . -t '$image_tag' -f '$image_file'" log "Pushing $image_tag" docker push "$image_tag" cd - rm -rf "$r" docker logout "$registry"