-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (100 loc) · 3.33 KB
/
build-image.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
name: build docker image
on:
workflow_call:
inputs:
image_name:
required: true
type: string
dockerfile:
required: true
type: string
image_title:
required: true
type: string
license:
required: true
type: string
tag:
required: true
type: string
go_plugin_link:
required: true
type: string
permissions:
packages: write
jobs:
build-image:
runs-on: ubuntu-latest
env:
CONTEXT: .
LICENSE: ${{ inputs.license }}
IMAGE_NAME: ${{ inputs.image_name }}
DOCKER_FILE: ${{ inputs.dockerfile }}
IMAGE_TITLE: ${{ inputs.image_title }}
TAG: ${{ inputs.tag }}
GO_LINK: ${{ inputs.go_plugin_link }}
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.IMAGE_TITLE }}
org.opencontainers.image.source=https://github.com/FarisZR/caddy-dns-OCI
# 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: linux/amd64,linux/arm64,linux/arm/v7, linux/arm/v6
push: ${{ github.event_name != 'pull_request' }}
build-args: "GO_LINK=${{ env.GO_LINK }}"
tags: |
quay.io/${{ env.IMAGE_NAME }}:${{ env.TAG }}
ghcr.io/${{ env.IMAGE_NAME }}:${{ env.TAG }}
docker.io/${{ env.IMAGE_NAME }}:${{ env.TAG }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max