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