-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaction.yml
More file actions
65 lines (60 loc) · 1.91 KB
/
action.yml
File metadata and controls
65 lines (60 loc) · 1.91 KB
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
62
63
64
65
name: 'Docker build and push'
description: 'Build and push Docker image with versioning'
inputs:
context:
description: 'Docker build context path'
required: true
default: .
file:
description: 'Dockerfile path'
required: true
build-args:
description: 'Docker build arguments'
required: false
docker-image:
description: 'Docker image name'
required: true
dockerhub-username:
description: 'Docker Hub username'
required: true
dockerhub-token:
description: 'Docker Hub token'
required: true
runs:
using: "composite"
steps:
- name: Format version
id: format_version
shell: bash
run: |
commitHash=${GITHUB_SHA:0:7}
ts=$(date +%s)
version=$commitHash-$ts
echo "VERSION=$version" >> $GITHUB_ENV
- name: Sanitize branch name
id: sanitize_branch_name
shell: bash
run: |
sanitized_ref_name=$(echo "${GITHUB_REF_NAME}" | sed 's/[\/.]/-/g')
echo "SANITIZED_REF_NAME=$sanitized_ref_name" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ inputs.dockerhub-username }}
password: ${{ inputs.dockerhub-token }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ${{ inputs.context }}
file: ${{ inputs.file }}
platforms: linux/amd64
push: ${{github.ref_name == 'main' || github.ref_name == 'dev'}}
build-args: ${{ inputs.build-args }}
tags: |
${{ inputs.docker-image }}:${{ env.SANITIZED_REF_NAME }}-${{ env.VERSION }}
${{ inputs.docker-image }}:${{ env.SANITIZED_REF_NAME }}
${{ github.ref_name == 'main' && format('{0}:latest', inputs.docker-image) || '' }}
cache-from: type=gha
cache-to: type=gha,mode=max