Talon/scripts/build_container.sh
2023-03-31 23:55:08 +02:00

56 lines
1.7 KiB
Bash
Executable file

#!/bin/bash
set -e
# Setup variables
REGISTRY="${X:-docker.io}"
if [ -z "$IMAGE" ]; then echo "IMAGE unset"; exit 1; fi
if [ -z "$TAG" ]; then echo "TAG unset"; exit 1; fi
if [ -z "$DOCKER_USERNAME" ]; then echo "DOCKER_USERNAME unset"; exit 1; fi
if [ -z "$DOCKER_PASSWORD" ]; then echo "DOCKER_PASSWORD unset"; exit 1; fi
echo "building docker image $IMAGE:$TAG"
ARCHITECTURES=("amd64" "aarch64")
# Create manifest
buildah manifest create "$REGISTRY/$IMAGE:$TAG"
for arch in "${ARCHITECTURES[@]}"; do
case "$arch" in
"amd64")
target_dir="target/x86_64-unknown-linux-musl"
;;
"aarch64")
target_dir="target/aarch64-unknown-linux-musl"
;;
*)
echo "unknown arch: $arch"; exit 1
;;
esac
echo "arch: $arch"
# Create empty container
container=$(buildah from scratch)
wd=$(buildah mount "$container")
# Copy files
mkdir "$wd/tmp" "$wd/data"
chmod a+w "$wd/tmp"
cp "$target_dir/release/talon" "$wd"
# Finalize container
buildah umount "$container"
buildah config --entrypoint "/talon" --cmd "run -d /data" --arch "$arch" --port 3000 --author "ThetaDev" "$container"
buildah commit "$container" "$IMAGE:$arch-$TAG"
buildah manifest add "$REGISTRY/$IMAGE:$TAG" "$IMAGE:$arch-$TAG"
done
buildah login --username "$DOCKER_USERNAME" --password "$DOCKER_PASSWORD" "$REGISTRY"
buildah manifest push --all "$REGISTRY/$IMAGE:$TAG" "docker://$REGISTRY/$IMAGE:$TAG"
if [ -n "$LATEST" ]; then
buildah tag "$REGISTRY/$IMAGE:$TAG" "$REGISTRY/$IMAGE:latest"
buildah manifest push --all "$REGISTRY/$IMAGE:latest" "docker://$REGISTRY/$IMAGE:latest"
fi