Skip to content

Commit 23fc548

Browse files
committed
docker.yml: fix build for tag
1 parent 2b60ecb commit 23fc548

File tree

1 file changed

+50
-12
lines changed

1 file changed

+50
-12
lines changed

.github/workflows/docker.yml

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
paths-ignore:
66
- 'docs/**'
77
branches-ignore: ["dependabot/**"]
8+
tags:
9+
- '*'
810
pull_request:
911
paths-ignore:
1012
- 'docs/**'
@@ -99,6 +101,8 @@ jobs:
99101
VERSION=sha-${GITHUB_SHA::8}
100102
if [[ $GITHUB_REF == refs/tags/* ]]; then
101103
VERSION=${GITHUB_REF/refs\/tags\//}
104+
# 9.8.0-x --> 9.8.0
105+
VERSION=$(echo $VERSION | sed "s/-.*//" )
102106
fi
103107
echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
104108
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
@@ -109,6 +113,7 @@ jobs:
109113
ARCH=amd64
110114
fi
111115
echo "ARCH=$ARCH" >> $GITHUB_OUTPUT
116+
112117
- name: Build docs image
113118
uses: docker/build-push-action@v6
114119
if: matrix.container == 'proj-docs'
@@ -131,6 +136,21 @@ jobs:
131136
org.opencontainers.image.revision=${{ github.sha }}
132137
org.opencontainers.image.version=${{ steps.prep.outputs.VERSION }}
133138
org.opencontainers.image.created=${{ steps.prep.outputs.BUILD_DATE }}
139+
140+
- name: Prepare tags
141+
id: prep_tags
142+
run: |
143+
TAGS="docker.io/osgeo/${{ matrix.container }}:${{ steps.prep.outputs.VERSION }}-${{ steps.prep.outputs.ARCH }}
144+
ghcr.io/osgeo/${{ matrix.container }}:${{ steps.prep.outputs.VERSION }}-${{ steps.prep.outputs.ARCH }}"
145+
if [ "${GITHUB_REF}" = "refs/heads/master" ]; then
146+
TAGS="$TAGS
147+
docker.io/osgeo/${{ matrix.container }}:latest-${{ steps.prep.outputs.ARCH }}
148+
ghcr.io/osgeo/${{ matrix.container }}:latest-${{ steps.prep.outputs.ARCH }}"
149+
fi
150+
echo "tags<<EOF" >> $GITHUB_OUTPUT
151+
echo "$TAGS" >> $GITHUB_OUTPUT
152+
echo "EOF" >> $GITHUB_OUTPUT
153+
134154
- name: Build image
135155
uses: docker/build-push-action@v6
136156
id: push
@@ -141,11 +161,7 @@ jobs:
141161
context: .
142162
file: ${{ matrix.dockerfile }}
143163
platforms: linux/${{ steps.prep.outputs.ARCH }}
144-
tags: |
145-
docker.io/osgeo/${{ matrix.container }}:${{ steps.prep.outputs.VERSION }}-${{ steps.prep.outputs.ARCH }}
146-
docker.io/osgeo/${{ matrix.container }}:latest-${{ steps.prep.outputs.ARCH }}
147-
ghcr.io/osgeo/${{ matrix.container }}:${{ steps.prep.outputs.VERSION }}-${{ steps.prep.outputs.ARCH }}
148-
ghcr.io/osgeo/${{ matrix.container }}:latest-${{ steps.prep.outputs.ARCH }}
164+
tags: ${{ steps.prep_tags.outputs.tags }}
149165
labels: |
150166
org.opencontainers.image.title=${{ github.event.repository.name }}
151167
org.opencontainers.image.description=${{ github.event.repository.description }}
@@ -189,16 +205,38 @@ jobs:
189205
username: ${{ secrets.DOCKER_USERNAME }}
190206
password: ${{ secrets.DOCKER_PASSWORD }}
191207

208+
- name: Prepare
209+
id: prep
210+
run: |
211+
VERSION=sha-${GITHUB_SHA::8}
212+
if [[ $GITHUB_REF == refs/tags/* ]]; then
213+
VERSION=${GITHUB_REF/refs\/tags\//}
214+
# 9.8.0-x --> 9.8.0
215+
VERSION=$(echo $VERSION | sed "s/-.*//" )
216+
fi
217+
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
218+
192219
- name: Create and push multi-platform manifest
193220
if: env.PUSH_PACKAGES == 'true'
194221
run: |
195222
docker buildx imagetools create \
196-
-t ghcr.io/osgeo/proj:latest \
197-
ghcr.io/osgeo/proj:latest-amd64 \
198-
ghcr.io/osgeo/proj:latest-arm64
223+
-t ghcr.io/osgeo/proj:${{ steps.prep.outputs.VERSION }} \
224+
ghcr.io/osgeo/proj:${{ steps.prep.outputs.VERSION }}-amd64 \
225+
ghcr.io/osgeo/proj:${{ steps.prep.outputs.VERSION }}-arm64
199226
200227
docker buildx imagetools create \
201-
-t osgeo/proj:latest \
202-
osgeo/proj:latest-amd64 \
203-
osgeo/proj:latest-arm64
204-
228+
-t osgeo/proj:${{ steps.prep.outputs.VERSION }} \
229+
osgeo/proj:${{ steps.prep.outputs.VERSION }}-amd64 \
230+
osgeo/proj:${{ steps.prep.outputs.VERSION }}-arm64
231+
232+
if [ "${GITHUB_REF}" = "refs/heads/master" ]; then
233+
docker buildx imagetools create \
234+
-t ghcr.io/osgeo/proj:latest \
235+
ghcr.io/osgeo/proj:latest-amd64 \
236+
ghcr.io/osgeo/proj:latest-arm64
237+
238+
docker buildx imagetools create \
239+
-t osgeo/proj:latest \
240+
osgeo/proj:latest-amd64 \
241+
osgeo/proj:latest-arm64
242+
fi

0 commit comments

Comments
 (0)