Skip to content

Commit 3d53e0a

Browse files
committed
Fix version number in Docker builds
We were getting an unclean git repo inside of the Docker build which is where setuptools_scm determines the version number. This happend because our .dockerignore was excluding some directories that exist in the git repo but aren't required in the docker image. That's reasonable, but it makes it impossible to determine the version number correctly inside of the docker build. This change add a docker ARG, and determines the version number in the GitHub Actions workflow before building the image. Closes #897
1 parent 66386af commit 3d53e0a

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ docker-compose.*.yml
1010
**/__pycache__
1111
**/*.py[cod]
1212

13+
#Git/VCS
14+
.git
15+
.jj
16+
1317
# CI / distribution / packaging
1418
**/*.egg-info
1519
.github

.github/workflows/docker.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,27 @@ jobs:
5151
username: gadockersvc
5252
image_tag: ${{ env.UNSTABLE_TAG }},latest
5353
password: "${{ secrets.DockerPassword }}"
54-
build_extra_args: "--build-arg=ENVIRONMENT=deployment"
54+
build_extra_args: "--build-arg=ENVIRONMENT=deployment --build-arg=EXPLORER_VERSION=${{ env.UNSTABLE_TAG }}"
5555

56-
# This section is for releases
56+
##############################
57+
# Only For GitHub Releases! #
58+
##############################
5759
- name: Get and log tag for this build if it exists
5860
if: github.event_name == 'release'
5961
run: |
6062
set -ex
61-
RELEASE=$(git describe --abbrev=0 --tags)
62-
echo "RELEASE=$RELEASE" >> $GITHUB_ENV
63+
RELEASE_VERSION=$(git describe --abbrev=0 --tags)
64+
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
6365
6466
- name: Build and Push release if we have a tag
6567
uses: whoan/docker-build-with-cache-action@d8d3ad518e7ac382b880720d0751815e656fe032 # v8.1.0
6668
if: github.event_name == 'release'
6769
with:
6870
image_name: ${{ env.IMAGE_NAME }}
69-
image_tag: ${{ env.RELEASE }}
71+
image_tag: ${{ env.RELEASE_VERSION }}
7072
username: gadockersvc
7173
password: "${{ secrets.DockerPassword }}"
72-
build_extra_args: "--build-arg=ENVIRONMENT=deployment"
74+
build_extra_args: "--build-arg=ENVIRONMENT=deployment --build-arg=EXPLORER_VERSION=${{ env.RELEASE_VERSION }}"
7375

7476
- name: Update Docker Hub Description
7577
uses: peter-evans/dockerhub-description@1b9a80c056b620d92cedb9d9b5a223409c68ddfa # v5.0.0

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ RUN --mount=type=cache,id=opendatacube-uv-cache,target=/root/.cache \
5959
COPY --link . /build/
6060

6161
ARG ENVIRONMENT=deployment
62+
ARG EXPLORER_VERSION=""
63+
ENV SETUPTOOLS_SCM_PRETEND_VERSION=${EXPLORER_VERSION}
6264
# The deployment image should not have binaries that aid an attacker to get their
6365
# rootkit in place, and uv downloads over the network. There is no conditional
6466
# copy in Docker, so truncate the uv binaries to 0 bytes to render them harmless
@@ -74,6 +76,9 @@ RUN --mount=type=cache,id=opendatacube-uv-cache,target=/root/.cache \
7476

7577
FROM base
7678

79+
ARG EXPLORER_VERSION=""
80+
LABEL org.opencontainers.image.version=${EXPLORER_VERSION}
81+
7782
# Add login-script for UID/GID-remapping.
7883
COPY --chown=root:root --link docker/files/remap-user.sh /usr/local/bin/remap-user.sh
7984

0 commit comments

Comments
 (0)