Skip to content

Commit 98d05b0

Browse files
Fix GitHub Actions to use short SHA for image tags
- Use first 7 characters of commit SHA instead of full SHA - Update docker metadata action to use format=short for SHA tags - Update documentation examples to show short SHA format - Image tags will now be: develop-6e3fce0 instead of develop-6e3fce0cbe8660e3bc972d4a5d936808d4e1bb35 This makes image tags more readable and follows common Git conventions.
1 parent 6e3fce0 commit 98d05b0

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

.github/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Automatically builds and publishes Docker images to Docker Hub when code is push
1313
- Pull requests to `main` or `develop` branches
1414

1515
**Image Tags:**
16-
- `main-<commit-sha>` - For main branch commits
17-
- `develop-<commit-sha>` - For develop branch commits
16+
- `main-<short-sha>` - For main branch commits (e.g., `main-6e3fce0`)
17+
- `develop-<short-sha>` - For develop branch commits (e.g., `develop-6e3fce0`)
1818
- `latest` - For main branch (default branch)
1919
- `pr-<pr-number>` - For pull requests
2020

@@ -35,10 +35,10 @@ Images are automatically built and published. To use a specific version:
3535
docker pull mariusgeorgescu/bjj-dapp-web:latest
3636

3737
# Specific commit
38-
docker pull mariusgeorgescu/bjj-dapp-web:main-abc1234
38+
docker pull mariusgeorgescu/bjj-dapp-web:main-6e3fce0
3939

4040
# Develop branch
41-
docker pull mariusgeorgescu/bjj-dapp-web:develop-xyz5678
41+
docker pull mariusgeorgescu/bjj-dapp-web:develop-6e3fce0
4242
```
4343

4444
## Configuration

.github/workflows/docker-build.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
tags: |
4444
type=ref,event=branch
4545
type=ref,event=pr
46-
type=sha,prefix={{branch}}-
46+
type=sha,prefix={{branch}}-,format=short
4747
type=raw,value=latest,enable={{is_default_branch}}
4848
4949
- name: Build and push Docker image
@@ -75,11 +75,12 @@ jobs:
7575
- name: Extract image tag
7676
id: image-tag
7777
run: |
78+
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
7879
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
79-
echo "tag=main-${{ github.sha }}" >> $GITHUB_OUTPUT
80+
echo "tag=main-${SHORT_SHA}" >> $GITHUB_OUTPUT
8081
echo "branch=main" >> $GITHUB_OUTPUT
8182
else
82-
echo "tag=develop-${{ github.sha }}" >> $GITHUB_OUTPUT
83+
echo "tag=develop-${SHORT_SHA}" >> $GITHUB_OUTPUT
8384
echo "branch=develop" >> $GITHUB_OUTPUT
8485
fi
8586

0 commit comments

Comments
 (0)