forked from LF-Decentralized-Trust-labs/paladin
-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (99 loc) · 3.07 KB
/
build-image.yaml
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
98
99
100
101
102
103
104
105
106
107
108
name: Build docker image
permissions:
contents: write
packages: write
id-token: write
on:
workflow_call:
inputs:
dockerfile:
description: 'Path to the Dockerfile'
required: true
type: string
registry:
description: 'Docker registry to push to'
required: true
type: string
image:
description: 'Name of the image'
required: true
type: string
image_tag:
description: 'Tag of the image'
required: true
type: string
push:
description: 'Push the image to the registry'
required: false
type: boolean
default: true
platforms:
description: 'Platforms to build for'
required: false
default: 'linux/amd64'
type: string
runs-on:
description: 'The type of machine to run the job on'
required: false
default: 'ubuntu-latest'
type: string
secrets:
username:
description: 'Docker registry username'
required: false
password:
description: 'Docker registry token (password)'
required: false
jobs:
docker:
runs-on: ${{ inputs.runs-on }}
steps:
- name: Print inputs
run: |
echo "dockerfile: ${{ inputs.dockerfile }}"
echo "registry: ${{ inputs.registry }}"
echo "image: ${{ inputs.image }}"
echo "image_tag: ${{ inputs.image_tag }}"
echo "push: ${{ inputs.push }}"
echo "platforms: ${{ inputs.platforms }}"
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Docker registry login
if: ${{ inputs.push }}
uses: docker/login-action@v3
with:
registry: ${{ inputs.registry }}
username: ${{ secrets.username }}
password: ${{ secrets.password }}
- name: Set lower case image name
run: |
echo "IMAGE_LC=${IMAGE,,}" >>${GITHUB_ENV}
env:
IMAGE: ${{ inputs.registry }}/${{ inputs.image }}
- name: Set build tag
id: build_tag_generator
run: |
echo "BUILD_TAG=$(date +"%Y%m%d")-$GITHUB_RUN_NUMBER" >> $GITHUB_OUTPUT
echo "BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_OUTPUT
- name: Build and push
uses: docker/build-push-action@v6
with:
provenance: false
file: ${{ inputs.dockerfile }}
builder: ${{ steps.buildx.outputs.name }}
push: ${{ inputs.push }}
platforms: ${{ inputs.platforms }}
tags: "${{ env.IMAGE_LC }}:${{ inputs.image_tag }}"
labels: |
commit=${{ github.sha }}
build_date=${{ steps.build_tag_generator.outputs.BUILD_DATE }}
tag=${{ steps.build_tag_generator.outputs.BUILD_TAG }}
cache-from: type=gha
cache-to: type=gha,mode=max