Picsur/support/build.sh

58 lines
1.2 KiB
Bash
Raw Normal View History

2022-02-25 15:41:56 +00:00
#!/bin/bash
2023-03-15 13:24:26 +00:00
PACKAGE_URL="ghcr.io/caramelfur/picsur"
2022-08-26 10:38:05 +00:00
2022-09-02 10:23:18 +00:00
if [ "$1" == "alpha" ]; then
2022-09-06 14:32:16 +00:00
PACKAGE_URL="$PACKAGE_URL-alpha"
2022-09-02 10:23:18 +00:00
elif [ "$1" == "stable" ]; then
2022-09-06 14:32:16 +00:00
true
2022-09-02 10:23:18 +00:00
else
2022-09-06 14:32:16 +00:00
echo "Usage: $0 [alpha|stable]"
exit 1
2022-09-02 10:23:18 +00:00
fi
2022-02-25 15:41:56 +00:00
# Go to this script
2022-06-05 10:20:16 +00:00
cd "$(dirname "${BASH_SOURCE[0]}")"
2022-02-25 15:41:56 +00:00
2022-09-02 10:23:18 +00:00
# Install binfmt
docker run --privileged --rm tonistiigi/binfmt --install all
2022-02-25 15:41:56 +00:00
# Read current version from ../package.json
VERSION=$(cat ../package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g' | tr -d '[[:space:]]')
echo "Building version $VERSION"
2022-12-27 15:56:59 +00:00
# Allow host networking for buildx
2023-06-15 12:22:58 +00:00
docker buildx create --append --name picsur --driver-opt network=host
2022-02-25 15:41:56 +00:00
2023-06-15 12:22:58 +00:00
docker build \
--push \
2022-12-27 15:56:59 +00:00
--network host \
-t "$PACKAGE_URL-stage1:$VERSION" \
-t "$PACKAGE_URL-stage1:latest" \
-f ./picsur-stage1.Dockerfile ..
2022-12-27 15:56:59 +00:00
# Exit if stage1 build failed
if [ $? -ne 0 ]; then
echo "Stage1 build failed"
exit 1
fi
2022-09-02 10:23:18 +00:00
docker buildx build \
2023-06-15 12:22:58 +00:00
--builder picsur \
2022-09-02 10:23:18 +00:00
--platform linux/amd64,linux/arm64 \
--push \
2022-12-27 15:56:59 +00:00
--network host \
2022-09-02 10:23:18 +00:00
-t "$PACKAGE_URL:$VERSION" \
-t "$PACKAGE_URL:latest" \
-f ./picsur-stage2.Dockerfile ..
2022-02-25 15:41:56 +00:00
2022-12-27 15:56:59 +00:00
# Exit if stage2 build failed
if [ $? -ne 0 ]; then
echo "Stage2 build failed"
exit 1
fi
2022-09-02 10:23:18 +00:00
echo "Done pushing $PACKAGE_URL:$VERSION"