Skip to content

Commit e0473ca

Browse files
authored
ci: add build-docker-image.yml
1 parent 34ec043 commit e0473ca

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Build & Push Docker Image to container image registry
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
ADD_FLAVOR:
7+
description: "Whether to add flavor (only -dev atm) to the image tag"
8+
type: boolean
9+
required: false
10+
default: true
11+
NO_CACHE:
12+
description: "Whether to use build cache"
13+
type: boolean
14+
required: false
15+
default: false
16+
secrets:
17+
BOT_TOKEN:
18+
required: true
19+
20+
concurrency:
21+
group: ${{ github.workflow }}-${{ github.ref }}
22+
cancel-in-progress: false
23+
24+
jobs:
25+
build:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Check Out Repo
29+
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
30+
with:
31+
fetch-depth: 2
32+
33+
#- name: Set up QEMU (We don't need QEMU, because we don't build images for platforms other than linux/amd64, which is our current native arch in our infra
34+
# uses: docker/setup-qemu-action@v1.2.0
35+
36+
- name: Set up Docker Buildx
37+
id: buildx
38+
uses: docker/setup-buildx-action@f03ac48505955848960e80bbb68046aa35c7b9e7 # v2.4.1
39+
40+
- name: Login to GitHub Container Registry
41+
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0
42+
if: ${{ github.event_name != 'pull_request' }}
43+
with:
44+
registry: ghcr.io
45+
username: ${{ github.repository_owner }}
46+
password: ${{ secrets.BOT_TOKEN }}
47+
48+
- name: Extract tag name
49+
id: tags
50+
if: ${{ github.event_name == 'release' }}
51+
run: echo ::set-output name=name::${GITHUB_REF##*/}
52+
53+
- name: Extract flavor
54+
id: flavor
55+
if: ${{ inputs.ADD_FLAVOR == true }}
56+
run: if [ "${{ github.event_name }}" = "release" ]; then echo ::set-output name=name::; else echo ::set-output name=name::-dev; fi
57+
58+
- name: Generate Docker image metadata
59+
uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96 # v4.3.0
60+
id: img_meta
61+
with:
62+
flavor: |
63+
latest=auto
64+
suffix=${{ steps.flavor.outputs.name }}
65+
images: ghcr.io/${{ github.repository }}
66+
tags: |
67+
${{ steps.tags.outputs.name }}
68+
latest
69+
70+
- name: Build and push
71+
id: docker_build
72+
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 # v4.0.0
73+
with:
74+
context: ./
75+
tags: ${{ steps.img_meta.outputs.tags }}
76+
labels: ${{ steps.img_meta.outputs.labels }}
77+
push: ${{ github.event_name != 'pull_request' }}
78+
secrets: |
79+
"GH_PKG_AUTH_TOKEN=${{ secrets.BOT_TOKEN }}"
80+
"GITHUB_TOKEN=${{ secrets.BOT_TOKEN }}"
81+
cache-from: type=gha,mode=max
82+
cache-to: type=gha,mode=max
83+
no-cache: ${{ inputs.NO_CACHE == true }}

0 commit comments

Comments
 (0)