Skip to content

Commit 1d63164

Browse files
committed
Refactor deployment workflow to dynamically set image tags and full image names based on the current branch and commit SHA. This improves versioning clarity and enhances the overall deployment process.
1 parent 8cbaa77 commit 1d63164

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

.github/workflows/build-push-deploy.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,24 @@ jobs:
9393
runs-on: ubuntu-latest
9494
needs: build-and-push
9595
if: github.ref == 'refs/heads/main' && needs.build-and-push.result == 'success'
96-
env:
97-
FULL_IMAGE: ${{ needs.build-and-push.outputs.full_image }}
98-
IMAGE_TAG: ${{ needs.build-and-push.outputs.image_tag }}
99-
SHA_SHORT: ${{ needs.build-and-push.outputs.sha_short }}
10096
steps:
10197
- name: Checkout code
10298
uses: actions/checkout@v4
10399

100+
- name: Set deployment image tag
101+
id: image
102+
run: |
103+
BRANCH="${GITHUB_REF#refs/heads/}"
104+
SHA_SHORT="$(git rev-parse --short HEAD)"
105+
IMAGE_TAG="${BRANCH}-${SHA_SHORT}"
106+
FULL_IMAGE="${{ env.DOCKER_IMAGE }}:${IMAGE_TAG}"
107+
echo "full_image=${FULL_IMAGE}" >> "$GITHUB_OUTPUT"
108+
echo "image_tag=${IMAGE_TAG}" >> "$GITHUB_OUTPUT"
109+
echo "sha_short=${SHA_SHORT}" >> "$GITHUB_OUTPUT"
110+
echo "FULL_IMAGE=${FULL_IMAGE}" >> "$GITHUB_ENV"
111+
echo "IMAGE_TAG=${IMAGE_TAG}" >> "$GITHUB_ENV"
112+
echo "SHA_SHORT=${SHA_SHORT}" >> "$GITHUB_ENV"
113+
104114
- name: Setup SSH
105115
uses: webfactory/ssh-agent@v0.9.0
106116
with:

0 commit comments

Comments
 (0)