|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -ex |
| 4 | + |
| 5 | +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 6 | +TOP_LEVEL="$(cd "$DIR/../.." && pwd)" |
| 7 | + |
| 8 | +# FUTUREWORK: Define this list in the makefile to allow overriding |
| 9 | +EXECUTABLES="cannon brig cargohold galley gundeck federator brig-index brig-schema galley-schema galley-migrate-data gundeck-schema proxy spar spar-schema" |
| 10 | +CONTAINER_NAME="output" |
| 11 | +DOCKER_TAG=${DOCKER_TAG:-$USER} |
| 12 | + |
| 13 | +buildah containers | awk '{print $5}' | grep "$CONTAINER_NAME" \ |
| 14 | + || buildah from --name "$CONTAINER_NAME" -v "${TOP_LEVEL}":/src --pull quay.io/wire/alpine-deps:develop |
| 15 | + |
| 16 | +# Only brig needs these templates, but for simplicity we add them to all resulting images (optimization FUTUREWORK) |
| 17 | +buildah run "$CONTAINER_NAME" -- sh -c 'mkdir -p /usr/share/wire/templates && cp -r "/src/services/brig/deb/opt/brig/templates" "/usr/share/wire/templates"' |
| 18 | + |
| 19 | +for EX in $EXECUTABLES; do |
| 20 | + # Copy the main executable into the PATH on the container |
| 21 | + buildah run "$CONTAINER_NAME" -- cp "/src/dist/$EX" "/usr/bin/$EX" |
| 22 | + |
| 23 | + # Start that executable by default when launching the docker image |
| 24 | + buildah config --entrypoint "[ \"/usr/bin/dumb-init\", \"--\", \"/usr/bin/$EX\" ]" "$CONTAINER_NAME" |
| 25 | + buildah config --cmd null "$CONTAINER_NAME" |
| 26 | + |
| 27 | + # Bake an image |
| 28 | + buildah commit "$CONTAINER_NAME" quay.io/wire/"$EX":"$DOCKER_TAG" |
| 29 | + |
| 30 | + # remove executable from the image in preparation for the next iteration |
| 31 | + buildah run "$CONTAINER_NAME" -- rm "/usr/bin/$EX" |
| 32 | +done |
| 33 | + |
| 34 | +if [[ $BUILDAH_PUSH -eq 1 ]]; then |
| 35 | + for EX in $EXECUTABLES; do |
| 36 | + buildah push "quay.io/wire/$EX:$DOCKER_TAG" |
| 37 | + done |
| 38 | +fi |
| 39 | + |
| 40 | +"$DIR/buildah-purge-untagged.sh" |
0 commit comments