From fb173e4d0e9a62aae015b88e0b8327745a93d395 Mon Sep 17 00:00:00 2001 From: Mythie Date: Thu, 20 Mar 2025 10:52:33 +1100 Subject: [PATCH] chore: update docker build scripts --- docker/build.sh | 40 ++++++++++++++++++++++++++++++++++------ docker/buildx.sh | 41 ++++++++++++++++++++++++++++++++++------- 2 files changed, 68 insertions(+), 13 deletions(-) diff --git a/docker/build.sh b/docker/build.sh index ca99ae8a9..b9069e3df 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -8,6 +8,7 @@ command -v docker >/dev/null 2>&1 || { SCRIPT_DIR="$(readlink -f "$(dirname "$0")")" MONOREPO_ROOT="$(readlink -f "$SCRIPT_DIR/../")" +# Get Git information APP_VERSION="$(git name-rev --tags --name-only $(git rev-parse HEAD) | head -n 1 | sed 's/\^0//')" GIT_SHA="$(git rev-parse HEAD)" @@ -15,12 +16,39 @@ echo "Building docker image for monorepo at $MONOREPO_ROOT" echo "App version: $APP_VERSION" echo "Git SHA: $GIT_SHA" +# Build with temporary base tag docker build -f "$SCRIPT_DIR/Dockerfile" \ --progress=plain \ - -t "documenso/documenso:latest" \ - -t "documenso/documenso:$GIT_SHA" \ - -t "documenso/documenso:$APP_VERSION" \ - -t "ghcr.io/documenso/documenso:latest" \ - -t "ghcr.io/documenso/documenso:$GIT_SHA" \ - -t "ghcr.io/documenso/documenso:$APP_VERSION" \ + -t "documenso-base" \ "$MONOREPO_ROOT" + +# Handle repository tagging +if [ ! -z "$DOCKER_REPOSITORY" ]; then + echo "Using custom repository: $DOCKER_REPOSITORY" + + # Add tags for custom repository + docker tag "documenso-base" "$DOCKER_REPOSITORY:latest" + docker tag "documenso-base" "$DOCKER_REPOSITORY:$GIT_SHA" + + # Add version tag if available + if [ ! -z "$APP_VERSION" ] && [ "$APP_VERSION" != "undefined" ]; then + docker tag "documenso-base" "$DOCKER_REPOSITORY:$APP_VERSION" + fi +else + echo "Using default repositories: dockerhub and ghcr.io" + + # Add tags for both default repositories + docker tag "documenso-base" "documenso/documenso:latest" + docker tag "documenso-base" "documenso/documenso:$GIT_SHA" + docker tag "documenso-base" "ghcr.io/documenso/documenso:latest" + docker tag "documenso-base" "ghcr.io/documenso/documenso:$GIT_SHA" + + # Add version tags if available + if [ ! -z "$APP_VERSION" ] && [ "$APP_VERSION" != "undefined" ]; then + docker tag "documenso-base" "documenso/documenso:$APP_VERSION" + docker tag "documenso-base" "ghcr.io/documenso/documenso:$APP_VERSION" + fi +fi + +# Remove the temporary base tag +docker rmi "documenso-base" diff --git a/docker/buildx.sh b/docker/buildx.sh index c5442107d..99ea0ecc0 100755 --- a/docker/buildx.sh +++ b/docker/buildx.sh @@ -9,11 +9,11 @@ SCRIPT_DIR="$(readlink -f "$(dirname "$0")")" MONOREPO_ROOT="$(readlink -f "$SCRIPT_DIR/../")" # Get the platform from environment variable or set to linux/amd64 if not set -# quote the string to prevent word splitting if [ -z "$PLATFORM" ]; then PLATFORM="linux/amd64" fi +# Get Git information APP_VERSION="$(git name-rev --tags --name-only $(git rev-parse HEAD) | head -n 1 | sed 's/\^0//')" GIT_SHA="$(git rev-parse HEAD)" @@ -21,14 +21,41 @@ echo "Building docker image for monorepo at $MONOREPO_ROOT" echo "App version: $APP_VERSION" echo "Git SHA: $GIT_SHA" +# Build with temporary base tag docker buildx build \ -f "$SCRIPT_DIR/Dockerfile" \ --platform=$PLATFORM \ --progress=plain \ - -t "documenso/documenso:latest" \ - -t "documenso/documenso:$GIT_SHA" \ - -t "documenso/documenso:$APP_VERSION" \ - -t "ghcr.io/documenso/documenso:latest" \ - -t "ghcr.io/documenso/documenso:$GIT_SHA" \ - -t "ghcr.io/documenso/documenso:$APP_VERSION" \ + -t "documenso-base" \ "$MONOREPO_ROOT" + +# Handle repository tagging +if [ ! -z "$DOCKER_REPOSITORY" ]; then + echo "Using custom repository: $DOCKER_REPOSITORY" + + # Add tags for custom repository + docker tag "documenso-base" "$DOCKER_REPOSITORY:latest" + docker tag "documenso-base" "$DOCKER_REPOSITORY:$GIT_SHA" + + # Add version tag if available + if [ ! -z "$APP_VERSION" ] && [ "$APP_VERSION" != "undefined" ]; then + docker tag "documenso-base" "$DOCKER_REPOSITORY:$APP_VERSION" + fi +else + echo "Using default repositories: dockerhub and ghcr.io" + + # Add tags for both default repositories + docker tag "documenso-base" "documenso/documenso:latest" + docker tag "documenso-base" "documenso/documenso:$GIT_SHA" + docker tag "documenso-base" "ghcr.io/documenso/documenso:latest" + docker tag "documenso-base" "ghcr.io/documenso/documenso:$GIT_SHA" + + # Add version tags if available + if [ ! -z "$APP_VERSION" ] && [ "$APP_VERSION" != "undefined" ]; then + docker tag "documenso-base" "documenso/documenso:$APP_VERSION" + docker tag "documenso-base" "ghcr.io/documenso/documenso:$APP_VERSION" + fi +fi + +# Remove the temporary base tag +docker rmi "documenso-base"