-
Notifications
You must be signed in to change notification settings - Fork 25
165 lines (153 loc) · 5.07 KB
/
Docker.yml
File metadata and controls
165 lines (153 loc) · 5.07 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
153
154
155
156
157
158
159
160
161
162
163
164
165
name: Reusable Docker Build
on:
workflow_call:
inputs:
image_name:
required: true
type: string
image_version:
required: true
type: string
image_build_args:
required: true
type: string
image_context:
required: true
type: string
image_file:
required: true
type: string
platforms:
required: false
type: string
default: linux/amd64
push:
required: false
type: boolean
default: true
# --- Tous optionnels ---
readme_url:
description: "URL brute (raw) du README.md"
required: false
type: string
default: ""
image_description:
description: "Courte description de l'image (opencontainers)"
required: false
type: string
default: ""
license:
description: "Licence du projet"
required: false
type: string
default: ""
keywords:
description: "Mots-clés séparés par des virgules"
required: false
type: string
default: ""
logo_url:
description: "URL du logo (PNG ou SVG)"
required: false
type: string
default: ""
secrets:
DOCKER_USERNAME:
required: true
DOCKER_PASSWORD:
required: true
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ inputs.image_name }}
- name: Compose optional labels
run: |
{
echo 'EXTRA_LABELS<<EOF'
if [ -n "${{ inputs.readme_url }}" ]; then
echo "io.artifacthub.package.readme-url=${{ inputs.readme_url }}"
fi
if [ -n "${{ inputs.license }}" ]; then
echo "io.artifacthub.package.license=${{ inputs.license }}"
fi
if [ -n "${{ inputs.keywords }}" ]; then
echo "io.artifacthub.package.keywords=${{ inputs.keywords }}"
fi
if [ -n "${{ inputs.logo_url }}" ]; then
echo "io.artifacthub.package.logo-url=${{ inputs.logo_url }}"
fi
if [ -n "${{ inputs.image_description }}" ]; then
echo "org.opencontainers.image.description=${{ inputs.image_description }}"
fi
echo 'EOF'
} >> "$GITHUB_ENV"
- name: Build image (no push)
if: inputs.push != true
uses: docker/build-push-action@v5
with:
context: ${{ inputs.image_context }}
file: ${{ inputs.image_file }}
build-args: ${{ inputs.image_build_args }}
push: false
platforms: ${{ inputs.platforms }}
labels: |
${{ steps.meta.outputs.labels }}
${{ env.EXTRA_LABELS }}
tags: ${{ inputs.image_name }}:${{ inputs.image_version }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Build and push Docker image (main -> latest + version)
if: github.ref == 'refs/heads/main' && inputs.push == true
uses: docker/build-push-action@v5
with:
context: ${{ inputs.image_context }}
file: ${{ inputs.image_file }}
build-args: ${{ inputs.image_build_args }}
push: true
tags: ${{ inputs.image_name }}:${{ inputs.image_version }},${{ inputs.image_name }}:latest
platforms: ${{ inputs.platforms }}
labels: |
${{ steps.meta.outputs.labels }}
${{ env.EXTRA_LABELS }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Build and push Docker image (branches ≠ main -> version)
if: github.ref != 'refs/heads/main' && inputs.push == true
uses: docker/build-push-action@v5
with:
context: ${{ inputs.image_context }}
file: ${{ inputs.image_file }}
build-args: ${{ inputs.image_build_args }}
push: true
tags: ${{ inputs.image_name }}:${{ inputs.image_version }}
platforms: ${{ inputs.platforms }}
labels: |
${{ steps.meta.outputs.labels }}
${{ env.EXTRA_LABELS }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache