-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (88 loc) · 2.81 KB
/
build-push-image.yml
File metadata and controls
97 lines (88 loc) · 2.81 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
name: Build and push image to registry
on:
workflow_call:
inputs:
registry:
description: Registry to push to, defaults to Docker Hub
required: false
type: string
images:
description: A list of the org/repo names to push to
required: true
type: string
tags:
# https://github.com/marketplace/actions/docker-metadata-action#tags-input
description: Tag rules for docker/metadata-action
required: false
type: string
default: |
type=edge
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
context:
description: The context to use for the Docker build command
required: false
type: string
default: ./
dockerfile:
description: The Dockerfile to use for the Docker build command
required: false
type: string
default: Dockerfile
platforms:
description: The platforms to use for the Docker build command
required: false
type: string
default: linux/amd64
push:
description: Whether to push the image to the registry
required: false
type: boolean
default: true
secrets:
username:
required: true
token:
required: true
jobs:
build:
name: Build and push image to registry
runs-on: ubuntu-latest
permissions:
contents: read
packages: write # needed when pushing image to ghcr.io
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ inputs.images }}
tags: ${{ inputs.tags }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Login to the container registry
if: ${{ inputs.push }}
uses: docker/login-action@v3
with:
registry: ${{ inputs.registry }}
username: ${{ secrets.username }}
password: ${{ secrets.token }}
- name: Build and push
uses: docker/build-push-action@v5
with:
builder: ${{ steps.buildx.outputs.name }}
context: ${{ inputs.context }}
file: ${{ inputs.dockerfile }}
platforms: ${{ inputs.platforms }}
push: ${{ inputs.push }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}