Skip to content

Commit 721aba3

Browse files
committed
Add in docker/metadata action's annotations and labels
1 parent d257e5d commit 721aba3

File tree

3 files changed

+68
-17
lines changed

3 files changed

+68
-17
lines changed

.github/workflows/ci.yml

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
- '**.md'
99
- '.gitignore'
1010
- '.github/workflows/pushrm.yml'
11+
workflow_dispatch:
1112
pull_request:
1213
paths-ignore:
1314
- '**.md'
@@ -151,6 +152,9 @@ jobs:
151152
needs: [ test-script ]
152153
runs-on: ubuntu-22.04
153154
environment: docker.io
155+
permissions:
156+
contents: read
157+
packages: write
154158
steps:
155159
# Increase available disk space by removing unnecessary tool chains:
156160
# https://github.com/actions/runner-images/issues/2840#issuecomment-790492173
@@ -165,27 +169,48 @@ jobs:
165169
- name: Set up Docker Buildx
166170
uses: docker/setup-buildx-action@v3
167171

172+
- name: Configure build revision
173+
id: vars
174+
run: echo "sha_short=${GITHUB_SHA:0:7}" >> "$GITHUB_OUTPUT"
175+
168176
- name: Login to Docker Hub
169-
uses: docker/login-action@v2
177+
uses: docker/login-action@v3
178+
if: github.repository_owner == 'prodrigestivill'
170179
with:
171180
username: ${{ secrets.DOCKERHUB_USERNAME }}
172181
password: ${{ secrets.DOCKERHUB_TOKEN }}
173182

174-
- name: Configure build revision
175-
id: vars
176-
run: echo "::set-output name=sha_short::${GITHUB_SHA:0:7}"
183+
- name: Login to GitHub Container Registry
184+
uses: docker/login-action@v3
185+
if: github.repository_owner != 'prodrigestivill'
186+
with:
187+
registry: ghcr.io
188+
username: ${{ github.actor }}
189+
password: ${{ secrets.GITHUB_TOKEN }}
177190

178-
- name: Build images
179-
env:
180-
REGISTRY_PREFIX: ${{ secrets.DOCKERHUB_USERNAME }}/
181-
BUILD_REVISION: ${{ steps.vars.outputs.sha_short }}
182-
run: docker buildx bake --pull
191+
- name: Docker meta
192+
id: meta
193+
uses: docker/metadata-action@v5
194+
195+
- name: Get repo name
196+
run: |
197+
echo "REPO_NAME=$(echo "$GITHUB_REPOSITORY" | cut -d "/" -f 2)" >> "$GITHUB_ENV"
198+
echo "GHCR_REPO=ghcr.io/$GITHUB_REPOSITORY_OWNER" >> "$GITHUB_ENV"
183199
184-
- name: Push images
200+
- name: Build image
201+
uses: docker/bake-action@v6
185202
env:
186-
REGISTRY_PREFIX: ${{ secrets.DOCKERHUB_USERNAME }}/
203+
REGISTRY_PREFIX: ${{ github.repository_owner == 'prodrigestivill' && secrets.DOCKERHUB_USERNAME || env.GHCR_REPO }}/
204+
IMAGE_NAME: ${{ github.repository_owner == 'prodrigestivill' && 'postgres-backup-local' || env.REPO_NAME }}
187205
BUILD_REVISION: ${{ steps.vars.outputs.sha_short }}
188-
run: docker buildx bake --push
206+
with:
207+
push: true
208+
targets: alpine
209+
files: |
210+
./docker-bake.hcl
211+
cwd://${{ steps.meta.outputs.bake-file-labels }}
212+
cwd://${{ steps.meta.outputs.bake-file-annotations }}
213+
189214
190215
## Example of publish using GitHub Container Registry instead
191216
# publish:

docker-bake.hcl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
target "docker-metadata-action" {}
2+
13
group "default" {
2-
targets = ["debian-latest", "alpine-latest", "debian-17", "debian-16", "debian-15", "debian-14", "debian-13", "alpine-17", "alpine-16", "alpine-15", "alpine-14", "alpine-13"]
4+
targets = ["debian-latest", "debian-17", "debian-16", "debian-15", "debian-14", "debian-13", "alpine-latest", "alpine-17", "alpine-16", "alpine-15", "alpine-14", "alpine-13"]
5+
}
6+
7+
group "debian-all" {
8+
targets = ["debian-latest", "debian-17", "debian-16", "debian-15", "debian-14", "debian-13"]
9+
}
10+
11+
group "alpine-all" {
12+
targets = ["alpine-latest", "alpine-17", "alpine-16", "alpine-15", "alpine-14", "alpine-13"]
313
}
414

515
variable "REGISTRY_PREFIX" {
@@ -15,11 +25,13 @@ variable "BUILD_REVISION" {
1525
}
1626

1727
target "debian" {
28+
inherits = ["docker-metadata-action"]
1829
args = {"GOCRONVER" = "v0.0.11"}
1930
dockerfile = "debian.Dockerfile"
2031
}
2132

2233
target "alpine" {
34+
inherits = ["docker-metadata-action"]
2335
args = {"GOCRONVER" = "v0.0.11"}
2436
dockerfile = "alpine.Dockerfile"
2537
}

generate-docker-bake.sh

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,22 @@ cd "$(dirname "$0")"
1212

1313
P="\"$(echo $PLATFORMS | sed 's/ /", "/g')\""
1414

15-
T="\"debian-latest\", \"alpine-latest\", \"$(echo debian-$TAGS_EXTRA | sed 's/ /", "debian-/g')\", \"$(echo alpine-$TAGS_EXTRA | sed 's/ /", "alpine-/g')\""
15+
DEBIAN_TARGETS="\"debian-latest\", \"$(echo debian-$TAGS_EXTRA | sed 's/ /", "debian-/g')\""
16+
ALPINE_TARGETS="\"alpine-latest\", \"$(echo alpine-$TAGS_EXTRA | sed 's/ /", "alpine-/g')\""
17+
18+
cat >"$DOCKER_BAKE_FILE" <<EOF
19+
target "docker-metadata-action" {}
1620
17-
cat > "$DOCKER_BAKE_FILE" << EOF
1821
group "default" {
19-
targets = [$T]
22+
targets = [$DEBIAN_TARGETS, $ALPINE_TARGETS]
23+
}
24+
25+
group "debian-all" {
26+
targets = [$DEBIAN_TARGETS]
27+
}
28+
29+
group "alpine-all" {
30+
targets = [$ALPINE_TARGETS]
2031
}
2132
2233
variable "REGISTRY_PREFIX" {
@@ -32,11 +43,13 @@ variable "BUILD_REVISION" {
3243
}
3344
3445
target "debian" {
46+
inherits = ["docker-metadata-action"]
3547
args = {"GOCRONVER" = "$GOCRONVER"}
3648
dockerfile = "debian.Dockerfile"
3749
}
3850
3951
target "alpine" {
52+
inherits = ["docker-metadata-action"]
4053
args = {"GOCRONVER" = "$GOCRONVER"}
4154
dockerfile = "alpine.Dockerfile"
4255
}
@@ -64,7 +77,8 @@ target "alpine-latest" {
6477
}
6578
EOF
6679

67-
for TAG in $TAGS_EXTRA; do cat >> "$DOCKER_BAKE_FILE" << EOF
80+
for TAG in $TAGS_EXTRA; do
81+
cat >>"$DOCKER_BAKE_FILE" <<EOF
6882
6983
target "debian-$TAG" {
7084
inherits = ["debian"]

0 commit comments

Comments
 (0)