Files
nginx-cache/build.sh
2026-01-07 19:09:13 +01:00

87 lines
2.4 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
 
# ============================================================================
# CONFIGURATION - Modify these for your project
# ============================================================================
 
# Docker registry and image name
DOCKER_REPO="docker.site.quack-lab.dev"
IMAGE_NAME="nginx-cache-proxy"
 
# ============================================================================
# VALIDATE CONFIGURATION
# ============================================================================
echo "Validating nginx configuration..."
nginx -t -c /dev/stdin <<< "$(cat nginx.conf)"
if [ $? -ne 0 ]; then
echo "Error validating nginx configuration"
exit 1
fi
# ============================================================================
# DOCKER BUILD AND TAG
# ============================================================================
 
COMMIT_SHA=$(git rev-parse --short HEAD)
IMAGE_BASE="${DOCKER_REPO}/${IMAGE_NAME}"
 
echo ""
echo "Building Docker image..."
docker build -t "${IMAGE_BASE}:${COMMIT_SHA}" .
 
if [ $? -ne 0 ]; then
echo "Error building agx Docker image"
exit 1
fi
 
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 ""
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 ""
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