Set Docker image tag when building

to prevent rebuild when nothing has changed

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-29 08:55:57 +02:00
parent c684123ffc
commit dc42cd7f24
2 changed files with 15 additions and 2 deletions
+2
View File
@@ -3,6 +3,7 @@ services:
build:
context: ../backend
dockerfile: ../docker/Dockerfile.backend
image: bamort-backend:${GIT_TAG:-latest}
container_name: bamort-backend
ports:
- "8182:8180"
@@ -25,6 +26,7 @@ services:
build:
context: ../frontend
dockerfile: ../docker/Dockerfile.frontend
image: bamort-frontend:${GIT_TAG:-latest}
container_name: bamort-frontend
ports:
- "8181:80"
+13 -2
View File
@@ -24,11 +24,22 @@ else
fi
fi
# Determine image tag from git commit hash (first 5 chars)
GIT_TAG=$(git -C "$(dirname "$0")/.." rev-parse --short=5 HEAD 2>/dev/null || echo "latest")
export GIT_TAG
echo "🏷️ Image tag: ${GIT_TAG}"
echo "📦 Building and starting production containers..."
echo "🔧 Frontend will use API: ${API_URL:-https://bamort-api.trokan.de}"
# Build before stopping existing containers
docker-compose -f docker-compose.yml --env-file .env.prd -p bamort build
# Build only if images for this commit don't exist yet
if ! docker image inspect "bamort-backend:${GIT_TAG}" > /dev/null 2>&1 || \
! docker image inspect "bamort-frontend:${GIT_TAG}" > /dev/null 2>&1; then
echo "🔨 Images not found for tag '${GIT_TAG}', building..."
docker-compose -f docker-compose.yml --env-file .env.prd -p bamort build
else
echo "✅ Images already exist for tag '${GIT_TAG}', skipping build."
fi
# Stoppe vorhandene Container
docker-compose -f docker-compose.yml -p bamort down