refac:updated ci/cd pipeline to create docker images with timestamp and commit sha
Build & Deploy (develop) / build-and-deploy (push) Successful in 2m17s

This commit is contained in:
2026-09-29 10:59:09 +03:30
parent 92a3f014a6
commit b93c780fea
2 changed files with 20 additions and 8 deletions
+9 -6
View File
@@ -20,17 +20,20 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Resolve commit SHA
- name: Resolve image tag
id: vars
run: |
# For PRs, gitea.sha is a temporary merge commit — use the real
# PR head commit instead so tags map to actual git history.
FULL_SHA="${{ gitea.event.pull_request.head.sha || gitea.sha }}"
echo "sha=${FULL_SHA:0:7}" >> "$GITHUB_OUTPUT"
SHORT_SHA="${FULL_SHA:0:7}"
BUILD_TIME=$(date -u +%Y%m%d-%H%M%S)
echo "sha=${SHORT_SHA}" >> "$GITHUB_OUTPUT"
echo "tag=${BUILD_TIME}-${SHORT_SHA}" >> "$GITHUB_OUTPUT"
- name: Build Docker image (tagged by commit SHA)
- name: Build Docker image (tagged by UTC build time and commit SHA)
run: |
docker build -t robot-market:${{ steps.vars.outputs.sha }} .
docker build -t robot-market:${{ steps.vars.outputs.tag }} .
- name: Save previous tag for rollback
id: backup
@@ -42,7 +45,7 @@ jobs:
- name: Point compose at this build
run: |
echo "IMAGE_TAG=${{ steps.vars.outputs.sha }}" > /opt/robot-market-front/.env
echo "IMAGE_TAG=${{ steps.vars.outputs.tag }}" > /opt/robot-market-front/.env
- name: Deploy via compose
id: deploy
@@ -85,7 +88,7 @@ jobs:
- name: Clean up dangling (untagged) layers
run: docker image prune -f
- name: Prune old SHA-tagged images (keep last 5)
- name: Prune old build-tagged images (keep last 5)
run: |
KEEP=5
CURRENT_TAG=$(grep IMAGE_TAG /opt/robot-market-front/.env 2>/dev/null | cut -d= -f2)
+11 -2
View File
@@ -2,7 +2,8 @@ name: Rollback (develop)
# Trigger manually from the Gitea Actions UI.
# Leave "sha" empty to roll back to the previous deploy.
# Fill "sha" in (short 7-char form, e.g. a3f9c21) to roll back to a specific past build.
# Fill "sha" in (short 7-char form, e.g. a3f9c21) to roll back to the newest
# build for that commit. Build tags include a UTC timestamp and commit SHA.
on:
workflow_dispatch:
inputs:
@@ -18,7 +19,15 @@ jobs:
- name: Determine target tag
run: |
if [ -n "${{ gitea.event.inputs.sha }}" ]; then
TAG="${{ gitea.event.inputs.sha }}"
SHA="${{ gitea.event.inputs.sha }}"
TAG=$(docker images robot-market --format '{{.Tag}}' \
| grep -E "-${SHA}$" \
| sort -r \
| head -n 1)
# Keep accepting legacy SHA-only tags created before timestamped tags.
if [ -z "$TAG" ]; then
TAG="$SHA"
fi
else
TAG=$(grep IMAGE_TAG /opt/robot-market-front/.env.previous | cut -d= -f2)
fi