From da9f6d7a63664533306998adf27bd1e22bfe87cd Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Wed, 26 Nov 2025 23:39:10 +0100 Subject: [PATCH] Add a docker build file script --- docker-build.sh | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 docker-build.sh diff --git a/docker-build.sh b/docker-build.sh new file mode 100644 index 0000000..01c2b1d --- /dev/null +++ b/docker-build.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +set -e + +# ============================================================================ +# CONFIGURATION - Modify these for your project +# ============================================================================ + +# Docker registry and image name +DOCKER_REPO="docker.site.quack-lab.dev" +IMAGE_NAME="journal-fe" + +# ============================================================================ +# BUILD PROJECT +# ============================================================================ + +echo "Building project..." +bun run build + +# ============================================================================ +# DOCKER BUILD AND TAG +# ============================================================================ + +COMMIT_SHA=$(git rev-parse --short HEAD) +IMAGE_BASE="${DOCKER_REPO}/${IMAGE_NAME}" + +echo "Building Docker image..." +docker build -t "${IMAGE_BASE}:${COMMIT_SHA}" . + +echo "Tagging as latest..." +docker tag "${IMAGE_BASE}:${COMMIT_SHA}" "${IMAGE_BASE}:latest" + +TAGS=$(git tag --points-at HEAD) +if [ -n "$TAGS" ]; then + echo "Found tags on current commit:" + while IFS= read -r tag; do + if [ -n "$tag" ]; then + echo "Tagging as ${tag}..." + docker tag "${IMAGE_BASE}:${COMMIT_SHA}" "${IMAGE_BASE}:${tag}" + fi + done <<< "$TAGS" +fi + +# ============================================================================ +# PUSH IMAGES +# ============================================================================ + +echo "Pushing Docker images..." +docker push "${IMAGE_BASE}:${COMMIT_SHA}" +docker push "${IMAGE_BASE}:latest" + +if [ -n "$TAGS" ]; then + while IFS= read -r tag; do + if [ -n "$tag" ]; then + docker push "${IMAGE_BASE}:${tag}" + fi + done <<< "$TAGS" +fi + +# ============================================================================ +# SUMMARY +# ============================================================================ + +echo "Build complete! Image pushed as:" +echo " - ${IMAGE_BASE}:${COMMIT_SHA}" +echo " - ${IMAGE_BASE}:latest" +if [ -n "$TAGS" ]; then + while IFS= read -r tag; do + if [ -n "$tag" ]; then + echo " - ${IMAGE_BASE}:${tag}" + fi + done <<< "$TAGS" +fi