Files
SPARC/.gitlab-ci.yml
T
0xWheatyz 03105a2f87 feat(ci): add timestamp-based image tags with commit hash
Push images with versioned tags in format TIMESTAMP-COMMIT and
frontend-TIMESTAMP-COMMIT for better traceability and rollback support.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-03-15 02:35:33 -04:00

42 lines
1.2 KiB
YAML

stages:
- build
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: "/certs"
LATEST_TAG: $CI_REGISTRY_IMAGE:latest
build-and-push:
stage: build
image: docker:24-cli
services:
- docker:24-dind
before_script:
- echo "Logging into GitLab Container Registry..."
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
# Generate timestamp and short commit hash for tags
- export TIMESTAMP=$(date -u +%Y%m%d%H%M%S)
- export SHORT_COMMIT=$(echo $CI_COMMIT_SHA | cut -c1-7)
- export VERSIONED_TAG=$CI_REGISTRY_IMAGE:${TIMESTAMP}-${SHORT_COMMIT}
- export FRONTEND_TAG=$CI_REGISTRY_IMAGE:frontend-${TIMESTAMP}-${SHORT_COMMIT}
script:
- echo "Building Docker image..."
- docker build -t $VERSIONED_TAG -t $FRONTEND_TAG -t $LATEST_TAG .
- echo "Pushing Docker image to registry..."
- docker push $VERSIONED_TAG
- docker push $FRONTEND_TAG
- docker push $LATEST_TAG
- echo "Build and push completed successfully!"
- echo "Images available at:"
- echo " $VERSIONED_TAG"
- echo " $FRONTEND_TAG"
- echo " $LATEST_TAG"
rules:
- if: $CI_COMMIT_BRANCH == "main"
when: always
- if: $CI_COMMIT_TAG
when: always
- when: manual
tags:
- docker