-
Notifications
You must be signed in to change notification settings - Fork 7
61 lines (53 loc) · 2.17 KB
/
build-and-push-docker-image.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
name: Build and push image to docker hub
on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine Docker image tag when event is 'push'
if: ${{ github.event_name == 'push' }}
shell: bash
# Docker tag will be the tag that triggered the workflow run
run: echo "DOCKER_TAG=$GITHUB_REF_NAME" >> $GITHUB_ENV
- name: Determine Docker image tag when event is 'workflow_dispatch'
if: ${{ github.event_name == 'workflow_dispatch' }}
shell: bash
# Docker tag will be the latest commit hash of the branch that triggered the workflow run
run: |
if [[ ${{ github.ref_type }} == 'tag' ]]; then
DOCKER_TAG=$GITHUB_REF_NAME
else
DOCKER_TAG=$(git rev-parse --short=7 "$GITHUB_REF_NAME^{commit}")
fi
echo "DOCKER_TAG=$DOCKER_TAG" >> $GITHUB_ENV
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push Docker images tagged with both latest and above determined tag
uses: docker/build-push-action@v5
# If the workflow trigger event is `push`, then its clear that a new tag has been pushed, hence we push images tagged with latest as well
if: ${{ github.event_name == 'push' }}
with:
context: .
file: Dockerfile
push: true
tags: juspaydotin/hyperswitch-card-vault:latest,juspaydotin/hyperswitch-card-vault:${{ env.DOCKER_TAG }}
- name: Build and push Docker image tagged only with above determined tag
uses: docker/build-push-action@v5
# If the workflow is triggered manually, the built image need not necessarily be latest
if: ${{ github.event_name == 'workflow_dispatch' }}
with:
context: .
file: Dockerfile
push: true
tags: juspaydotin/hyperswitch-card-vault:${{ env.DOCKER_TAG }}