Skip to content

Commit 74de8d7

Browse files
committed
Improve Docker Push workflow
1 parent a93bb73 commit 74de8d7

1 file changed

Lines changed: 25 additions & 12 deletions

File tree

.github/workflows/docker-push.yml

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ name: "Docker Push"
33
on:
44
release:
55
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
force_rebuild:
9+
description: 'Force container rebuild'
10+
required: true
11+
type: choice
12+
options: [yes, no]
613
schedule:
714
- cron: '30 12 * * *'
815

@@ -18,9 +25,8 @@ jobs:
1825
name: Docker Build & Publish
1926
runs-on: ubuntu-latest
2027

21-
strategy:
22-
matrix:
23-
image: [ 'alpine' ]
28+
env:
29+
DOCKER_FILE: alpine
2430

2531
steps:
2632
- name: Checkout
@@ -67,7 +73,7 @@ jobs:
6773
exit 1
6874
fi
6975
70-
docker_file=".docker/${{matrix.image}}.docker"
76+
docker_file=".docker/${{env.DOCKER_FILE}}.docker"
7177
base_image=$(grep 'FROM ' $docker_file | grep -v 'builder' | sed 's#${REGISTRY}/##' | tail -1 | cut -f2 -d' ')
7278
7379
if [[ -z "$base_image" ]] ; then
@@ -91,10 +97,16 @@ jobs:
9197
exit 0
9298
fi
9399
100+
if [[ "${{ github.event.inputs.force_rebuild }}" == "true" ]] ; then
101+
echo "::warning::Rebuild is required (reason: forced rebuild)"
102+
echo "build=true" >> $GITHUB_OUTPUT
103+
exit 0
104+
fi
105+
94106
echo -e "::group::\033[34mDownloading built image…\033[0m"
95107
96-
if ! docker pull ghcr.io/${{env.IMAGE_NAME}}:${{matrix.image}} ; then
97-
echo "::error::Can't download image ghcr.io/${{env.IMAGE_NAME}}:${{matrix.image}}"
108+
if ! docker pull ghcr.io/${{env.IMAGE_NAME}}:latest ; then
109+
echo "::error::Can't download image ghcr.io/${{env.IMAGE_NAME}}:latest"
98110
exit 1
99111
fi
100112
@@ -115,7 +127,7 @@ jobs:
115127
exit 1
116128
fi
117129
118-
if ! docker inspect "ghcr.io/${{env.IMAGE_NAME}}:${{matrix.image}}" | jq -r '.[0].RootFS.Layers' | grep -q "$base_layer" ; then
130+
if ! docker inspect "ghcr.io/${{env.IMAGE_NAME}}:latest" | jq -r '.[0].RootFS.Layers' | grep -q "$base_layer" ; then
119131
echo "::warning::Rebuild image (reason: base image rebuilt)"
120132
echo "build=true" >> $GITHUB_OUTPUT
121133
exit 0
@@ -131,8 +143,8 @@ jobs:
131143
build-args: |
132144
REGISTRY=docker.io
133145
tags: |
134-
${{env.IMAGE_NAME}}:${{matrix.image}}-${{steps.metadata.outputs.version}}
135-
${{env.IMAGE_NAME}}:${{matrix.image}}
146+
${{env.IMAGE_NAME}}:${{steps.metadata.outputs.version}}
147+
${{env.IMAGE_NAME}}:latest
136148
137149
- name: Build and push Docker images (GHCR)
138150
if: ${{ steps.build_check.outputs.build == 'true' }}
@@ -144,11 +156,12 @@ jobs:
144156
build-args: |
145157
REGISTRY=ghcr.io
146158
tags: |
147-
ghcr.io/${{env.IMAGE_NAME}}:${{matrix.image}}-${{steps.metadata.outputs.version}}
148-
ghcr.io/${{env.IMAGE_NAME}}:${{matrix.image}}
159+
ghcr.io/${{env.IMAGE_NAME}}:${{steps.metadata.outputs.version}}
160+
ghcr.io/${{env.IMAGE_NAME}}:latest
149161
150162
- name: Show info about built Docker image
163+
if: ${{ steps.build_check.outputs.build == 'true' }}
151164
uses: essentialkaos/docker-info-action@v1
152165
with:
153-
image: ghcr.io/${{env.IMAGE_NAME}}:${{matrix.image}}
166+
image: ghcr.io/${{env.IMAGE_NAME}}:latest
154167
show-labels: true

0 commit comments

Comments
 (0)