Repository navigation
111 lines (103 loc) · 3.65 KB
/
Copy pathreusable-docker-ghcr.yml
File metadata and controls
111 lines (103 loc) · 3.65 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
on:
workflow_call:
inputs:
fetch_depth:
description: 'Number of commits to fetch. 0 indicates all history for all branches and tags.'
required: false
default: 0
type: string
version_tag:
required: true
type: string
user:
required: false
default: tools-bot
type: string
file:
required: false
default: Dockerfile
type: string
provenance:
required: false
default: true
type: boolean
platforms:
description: Comma-separated list of target platforms for build
required: false
type: string
build_args:
description: New-line-separated list of docker build arguments like "arg=value"
required: false
type: string
outputs:
image_repository:
description: "Image repository docker image was pushed to"
value: ${{ jobs.dockerize.outputs.image_repository }}
image_uri:
description: "Full URI of docker image tagged with input version tag"
value: ${{ jobs.dockerize.outputs.image_uri }}
secrets:
USER_TOKEN:
required: true
concurrency:
group: ${{ inputs.version_tag }}
cancel-in-progress: true
jobs:
dockerize:
runs-on: ubuntu-latest
outputs:
image_repository: ${{ steps.set_outputs.outputs.IMAGE_REPOSITORY }}
image_uri: ${{ steps.set_outputs.outputs.IMAGE_URI }}
steps:
- uses: actions/checkout@v7
with:
fetch-depth: ${{ inputs.fetch_depth }}
- name: set environment variables and outputs
id: set_outputs
env:
VERSION_TAG: ${{ inputs.version_tag }}
run: |
echo "CI_JOB_TIMESTAMP=$(date --utc --rfc-3339=seconds)" >> $GITHUB_ENV
export IMAGE_REPOSITORY=ghcr.io/${GITHUB_REPOSITORY,,}
echo "IMAGE_REPOSITORY=${IMAGE_REPOSITORY}" >> ${GITHUB_ENV}
echo "IMAGE_REPOSITORY=${IMAGE_REPOSITORY}" >> ${GITHUB_OUTPUT}
export IMAGE_URI=${IMAGE_REPOSITORY}:${VERSION_TAG}
echo "IMAGE_URI=${IMAGE_URI}" >> ${GITHUB_ENV}
echo "IMAGE_URI=${IMAGE_URI}" >> ${GITHUB_OUTPUT}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
with:
platforms: ${{ inputs.platforms }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ inputs.user }}
password: ${{ secrets.USER_TOKEN }}
- name: Build, tag, and push image to GitHub Container Registry
uses: docker/build-push-action@v7
with:
context: .
file: ./${{ inputs.file }}
build-args: ${{ inputs.build_args }}
push: ${{ ! github.event.pull_request.head.repo.fork }}
platforms: ${{ inputs.platforms }}
provenance: ${{ inputs.provenance }}
tags: |
${{ env.IMAGE_URI }}
labels: |
org.opencontainers.image.created=${{ env.CI_JOB_TIMESTAMP }}
org.opencontainers.image.version=${{ inputs.version_tag }}
org.opencontainers.image.revision=${{ github.sha }}
- name: Add test tag
if: ${{ github.event_name == 'push' && contains(inputs.version_tag, '.dev') }}
uses: akhilerm/tag-push-action@v2.3.0
with:
src: ${{ env.IMAGE_URI }}
dst: ${{ env.IMAGE_REPOSITORY }}:test
- name: Add latest tag
if: ${{ github.event_name == 'push' && ! contains(inputs.version_tag, '.dev') }}
uses: akhilerm/tag-push-action@v2.3.0
with:
src: ${{ env.IMAGE_URI }}
dst: ${{ env.IMAGE_REPOSITORY }}:latest