refac:updated ci/cd pipeline to create docker images with timestamp and commit sha
Build & Deploy (develop) / build-and-deploy (push) Successful in 2m17s
Build & Deploy (develop) / build-and-deploy (push) Successful in 2m17s
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user