Repository navigation
90 lines (81 loc) · 2.89 KB
/
Copy pathdocker_publish.yml
File metadata and controls
90 lines (81 loc) · 2.89 KB
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
name: Build and publish Docker images
# Publishes the tpot-payload-server image to the
# GitHub Container Registry (GHCR) under ghcr.io/greedybear-project.
on:
push:
# Version builds arrive as a workflow_call from release.yml, not as a tag push
branches:
- main
- develop
workflow_dispatch:
workflow_call:
inputs:
ref:
description: Git ref to build. Defaults to the triggering ref.
type: string
required: false
version:
description: Semver version to tag the image with, e.g. 1.2.3.
type: string
required: false
# Cancel superseded runs for the same ref. The group must not depend on
# github.workflow: in a reusable workflow that resolves to the *caller's* name,
# which collides with the calling workflow's own concurrency group and prevents
# the called job from ever starting. Release builds are never cancelled.
concurrency:
group: docker-publish-${{ inputs.ref || github.ref }}
cancel-in-progress: ${{ inputs.version == '' }}
env:
GHCR_NAMESPACE: ghcr.io/greedybear-project
jobs:
build-and-push:
name: Build and push ${{ matrix.image }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
include:
- image: tpot-payload-server
dockerfile: docker/Dockerfile
steps:
- name: Check out repository
uses: actions/checkout@v7
with:
ref: ${{ inputs.ref || github.ref }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract image metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.GHCR_NAMESPACE }}/${{ matrix.image }}
# main branch -> prod
# develop branch -> stag
# dispatch on a tag -> X.Y.Z (from the ref)
# release.yml call -> X.Y.Z (from the version input)
tags: |
type=raw,value=prod,enable=${{ github.ref == 'refs/heads/main' }}
type=raw,value=stag,enable=${{ github.ref == 'refs/heads/develop' }}
type=semver,pattern={{version}}
type=raw,value=${{ inputs.version }},enable=${{ inputs.version != '' }}
flavor: |
latest=false
- name: Build and push
uses: docker/build-push-action@v7
with:
context: .
file: ${{ matrix.dockerfile }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=${{ matrix.image }}
cache-to: ${{ inputs.version == '' && format('type=gha,mode=max,scope={0}', matrix.image) || '' }}