-
Notifications
You must be signed in to change notification settings - Fork 0
156 lines (141 loc) · 4.55 KB
/
build-workflow.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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
name: build docker image and update build hash
on:
workflow_call:
inputs:
image_name:
required: true
type: string
dockerfile:
required: true
type: string
license:
required: true
type: string
clone_repo:
required: true
type: boolean
hash_file:
required: true
type: string
app_name:
required: true
type: string
repo:
required: true
type: string
branch:
required: false
default: 'main'
type: string
build_arch:
required: true
type: string
context:
required: true
type: string
permissions:
contents: write
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
jobs:
build-image:
runs-on: ubuntu-latest
env:
CONTEXT: ${{ inputs.context }}
LICENSE: ${{ inputs.license }}
CLONE_REPO: ${{ inputs.clone_repo }}
IMAGE_NAME: ${{ inputs.image_name }}
DOCKER_FILE: ${{ inputs.dockerfile }}
HASH_FILE: ${{ inputs.hash_file }}
APP_NAME: ${{ inputs.app_name }}
REPO: ${{ inputs.repo }}
BRANCH: ${{ inputs.branch }}
build_arch: ${{ inputs.build_arch }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@master
with:
platforms: all
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry docker.io
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}
- name: Log into registry quay.io
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: quay.io
username: ${{ secrets.QUAY_USER }}
password: ${{ secrets.QUAY_PASS }}
- name: Log into registry ghcr.io
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/${{ env.IMAGE_NAME }}
quay.io/${{ env.IMAGE_NAME }}
docker.io/${{ env.IMAGE_NAME }}
labels: |
org.opencontainers.image.licenses=${{ env.LICENSE }}
org.opencontainers.image.title=${{ env.APP_NAME }}
- name: Clone git repo for docker context
if: env.CLONE_REPO == 'true'
run: |
git clone --branch ${{ env.BRANCH }} ${{ env.REPO }} ${{ env.CONTEXT }}
cp ${{ env.DOCKER_FILE }} ${{ env.CONTEXT }}/${{ env.DOCKER_FILE }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v4
with:
context: ${{ env.CONTEXT }}
file: ${{ env.DOCKER_FILE }}
platforms: ${{ env.build_arch }}
push: ${{ github.event_name != 'pull_request' }}
tags: |
quay.io/${{ env.IMAGE_NAME }}:latest
ghcr.io/${{ env.IMAGE_NAME }}:latest
docker.io/${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
update-build-commit:
runs-on: ubuntu-latest
needs: build-image
env:
HASH_FILE: ${{ inputs.hash_file }}
REPO: ${{ inputs.repo }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: fetch latest commits
run: git pull
- name: Update build commit
run: git ls-remote ${{ env.REPO }} ${{ inputs.branch }} > ${{ env.HASH_FILE }}
- name: commit and push hash update
uses: stefanzweifel/git-auto-commit-action@v4
with:
file_pattern: ${{ inputs.hash_file }}
commit_message: update ${{ inputs.app_name }} build commit