Repository navigation
152 lines (132 loc) · 4.95 KB
/
Copy pathdocker-build.yml
File metadata and controls
152 lines (132 loc) · 4.95 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
---
name: Create and Publish Docker Image
on:
workflow_call:
inputs:
image_name:
required: true
type: string
platforms:
type: string
default: linux/amd64,linux/arm64
build_args:
type: string
cache_dir:
type: string
description: "Where the cache is added into the container. Default: `/root/.cache/`"
default: /root/.cache
# Cancel previous run for same branch
concurrency:
group: ${{ github.ref }}-1
cancel-in-progress: true
jobs:
build_sha:
runs-on: lansible-runners
if: ${{ !contains(github.ref, 'refs/tags/') }}
timeout-minutes: 1440 # 24h
# https://docs.docker.com/build/ci/github-actions/examples/#multi-platform-images
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
# Setup cachedir which can be used to speedup builds
# https://pythonspeed.com/articles/docker-cache-pip-downloads/
- name: Build Cache for Docker
uses: actions/cache@v6
with:
key: docker-cache
path: cache/ # default cache-source of cache-dance action
# use the v1 container since that runs without node (just bash)
- name: Inject build-cache into docker
uses: reproducible-containers/buildkit-cache-dance/inject@v1.0.1
with:
cache-target: ${{ inputs.cache_dir }}
- name: Login to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GHCR.io
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v7
with:
context: .
platforms: ${{ inputs.platforms }}
push: true
build-args: ${{ inputs.build_args }}
labels: |
org.opencontainers.image.created=${{ steps.build_date.outputs.date }}
org.opencontainers.image.authors='Wilmar den Ouden <info@wilmardenouden.nl>'
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.documentation=${{ github.server_url }}/${{ github.repository }}/blob/main/README.md
org.opencontainers.image.vendor=${{ github.repository_owner }}
tags: |
${{ inputs.image_name }}:${{ github.sha }}
ghcr.io/${{ inputs.image_name }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Extract build-cache from docker
uses: reproducible-containers/buildkit-cache-dance/inject@v1.0.1
with:
cache-target: ${{ inputs.cache_dir }} # path in the docker container
retag_branch:
runs-on: lansible-runners
needs: build_sha
steps:
- name: Login to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GHCR.io
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get branch name
run: echo "branch_name=${GITHUB_REF##*/}" >> $GITHUB_ENV
- name: Retag to branch name
uses: LANsible/copy-image-manifest-action@main
with:
source: ${{ inputs.image_name }}:${{ github.sha }}
targets: |
${{ inputs.image_name }}:${{ env.branch_name }},
ghcr.io/${{ inputs.image_name }}:${{ env.branch_name }}
wait_platforms: ${{ inputs.platforms }}
retag_tag:
runs-on: lansible-runners
# https://github.com/orgs/community/discussions/25692
if: ${{ contains(github.ref, 'refs/tags/') }}
steps:
- name: Login to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GHCR.io
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get tag name
run: echo "tag_name=${GITHUB_REF##*/}" >> $GITHUB_ENV
- name: Retag to tag and latest
uses: LANsible/copy-image-manifest-action@main
with:
source: ${{ inputs.image_name }}:${{ github.sha }}
targets: |
${{ inputs.image_name }}:${{ env.tag_name }},
${{ inputs.image_name }}:latest,
ghcr.io/${{ inputs.image_name }}:${{ env.tag_name }},
ghcr.io/${{ inputs.image_name }}:latest
wait_platforms: ${{ inputs.platforms }}