88 workflow_dispatch :
99 inputs :
1010 postgres_version :
11- description : ' PostgreSQL version to build'
12- required : true
13- default : ' 18.1'
11+ description : ' PostgreSQL base image version to build from'
12+ required : false
13+ revision :
14+ description : ' Image rebuild revision, e.g. 1 publishes <postgres_version>-r1'
15+ required : false
1416
1517env :
1618 REGISTRY_DOCKER : docker.io
5052 username : ${{ github.actor }}
5153 password : ${{ secrets.GITHUB_TOKEN }}
5254
53- - name : Read VERSION
55+ - name : Read versions
5456 id : version
55- run : echo "VERSION=$(cat VERSION)" >> $GITHUB_OUTPUT
57+ run : |
58+ POSTGRES_VERSION="${{ github.event.inputs.postgres_version }}"
59+ REVISION="${{ github.event.inputs.revision }}"
60+
61+ if [ -z "$POSTGRES_VERSION" ]; then
62+ POSTGRES_VERSION="$(cat POSTGRES_VERSION)"
63+ fi
64+
65+ if [ -n "$REVISION" ]; then
66+ if ! [[ "$REVISION" =~ ^[1-9][0-9]*$ ]]; then
67+ echo "Revision must be a positive integer." >&2
68+ exit 1
69+ fi
70+
71+ IMAGE_VERSION="$POSTGRES_VERSION-r$REVISION"
72+ else
73+ IMAGE_VERSION="$(cat VERSION)"
74+ fi
75+
76+ echo "POSTGRES_VERSION=$POSTGRES_VERSION" >> "$GITHUB_OUTPUT"
77+ echo "IMAGE_VERSION=$IMAGE_VERSION" >> "$GITHUB_OUTPUT"
78+
79+ - name : Refuse existing release tag
80+ if : github.event_name != 'pull_request'
81+ run : |
82+ IMAGE_VERSION="${{ steps.version.outputs.IMAGE_VERSION }}"
83+
84+ for image in \
85+ "${{ env.REGISTRY_DOCKER }}/ethoslink/postgres-backrest" \
86+ "${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME }}"
87+ do
88+ if docker buildx imagetools inspect "$image:$IMAGE_VERSION" >/dev/null 2>&1; then
89+ echo "Refusing to overwrite existing image tag: $image:$IMAGE_VERSION" >&2
90+ exit 1
91+ fi
92+ done
93+
94+ if git ls-remote --exit-code --tags origin "refs/tags/$IMAGE_VERSION" >/dev/null 2>&1; then
95+ echo "Refusing to recreate existing git tag: $IMAGE_VERSION" >&2
96+ exit 1
97+ fi
5698
5799 - name : Extract metadata (tags, labels) for Docker
58100 id : meta
@@ -62,15 +104,13 @@ jobs:
62104 ${{ env.REGISTRY_DOCKER }}/ethoslink/postgres-backrest
63105 ${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME }}
64106 tags : |
65- type=schedule
66- type=ref,event=branch
67- type=ref,event=tag
68107 type=ref,event=pr
69- type=semver,pattern={{version}}
70- type=semver,pattern={{major}}.{{minor}}
71108 type=raw,value=latest,enable={{is_default_branch}}
72- type=raw,value=${{ steps.version.outputs.VERSION }}
109+ type=raw,value=${{ steps.version.outputs.IMAGE_VERSION }}
73110 type=sha
111+ labels : |
112+ org.opencontainers.image.version=${{ steps.version.outputs.IMAGE_VERSION }}
113+ org.opencontainers.image.base.name=docker.io/library/postgres:${{ steps.version.outputs.POSTGRES_VERSION }}
74114
75115 - name : Extract first Docker tag
76116 id : extract_tag
92132 push : ${{ github.event_name != 'pull_request' }}
93133 platforms : ${{ github.event_name == 'pull_request' && 'linux/amd64' || 'linux/amd64,linux/arm64' }}
94134 build-args : |
95- POSTGRES_VERSION=${{ steps.version.outputs.VERSION }}
135+ POSTGRES_VERSION=${{ steps.version.outputs.POSTGRES_VERSION }}
96136 tags : ${{ steps.meta.outputs.tags }}
97137 labels : ${{ steps.meta.outputs.labels }}
98138 cache-from : type=gha
@@ -112,7 +152,7 @@ jobs:
112152 - name : Create Git Tag
113153 if : github.event_name == 'push' && github.ref == 'refs/heads/master'
114154 run : |
115- VERSION="${{ steps.version.outputs.VERSION }}"
155+ VERSION="${{ steps.version.outputs.IMAGE_VERSION }}"
116156 git tag "$VERSION"
117157 git push origin "$VERSION"
118158
@@ -122,10 +162,10 @@ jobs:
122162 env :
123163 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
124164 with :
125- tag_name : ${{ steps.version.outputs.VERSION }}
126- release_name : PostgreSQL ${{ steps.version.outputs.VERSION }}
165+ tag_name : ${{ steps.version.outputs.IMAGE_VERSION }}
166+ release_name : Image ${{ steps.version.outputs.IMAGE_VERSION }} for PostgreSQL ${{ steps.version.outputs.POSTGRES_VERSION }}
127167 body : |
128- PostgreSQL ${{ steps.version.outputs.VERSION }}
168+ PostgreSQL base image: ${{ steps.version.outputs.POSTGRES_VERSION }}
169+ Image version: ${{ steps.version.outputs.IMAGE_VERSION }}
129170 draft : false
130171 prerelease : false
131-
0 commit comments