-
Notifications
You must be signed in to change notification settings - Fork 0
81 lines (73 loc) · 2.83 KB
/
docker-publish.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
name: Docker
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
on:
push:
branches: [ main ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [ main ]
workflow_dispatch:
inputs:
dry_run:
type: boolean
default: false
description: "enable dry run"
required: false
tags:
type: string
default: ""
description: "The list of tags to be added to the image"
required: false
labels:
type: string
default: ""
description: "The list of labels to be added to the image"
required: false
force_docker_push:
type: boolean
default: false
description: "force docker push"
required: false
run-name: "Build docker image [dry_run=${{ inputs.dry_run }}, ${{ vars.CONTAINER_REGISTRY_URL }}/${{ vars.CONTAINER_REGISTRY_REPOSITORY }}]"
jobs:
build:
runs-on: [ self-hosted, ubuntu-latest, '${{ vars.RUNNER_LABEL_NAME }}' ]
name: "Build docker image [dry_run=${{ inputs.dry_run }}, ${{ vars.CONTAINER_REGISTRY_URL }}/${{ vars.CONTAINER_REGISTRY_REPOSITORY }}]"
permissions:
contents: read
packages: write
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Checkout repository
uses: actions/[email protected]
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ vars.CONTAINER_REGISTRY_URL }}
if: github.event_name != 'pull_request'
uses: docker/[email protected]
with:
registry: ${{ vars.CONTAINER_REGISTRY_URL }}
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/[email protected]
with:
images: ${{ vars.CONTAINER_REGISTRY_URL }}/${{ vars.CONTAINER_REGISTRY_REPOSITORY }}
# 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 [${{ vars.CONTAINER_REGISTRY_URL }}/${{ vars.CONTAINER_REGISTRY_REPOSITORY }}]
uses: docker/[email protected]
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ (github.event_name != 'pull_request' || inputs.force_docker_push == true ) && inputs.dry_run != true }}
tags: '${{ steps.meta.outputs.tags || inputs.tags }}${{ matrix.image_suffix }}'
labels: ${{ steps.meta.outputs.labels || inputs.labels }}