From ed4547166a4f893c6a48deb55ffca98623347f8d Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Tue, 10 Feb 2026 19:13:03 +0100 Subject: [PATCH] build: fix `make release-docker` (#918) PR - https://github.com/zrepl/zrepl/pull/913 didn't update the `release-docker` flow to use `uv`, thereby breaking it. ## Changes - Create `.uv-version` file to centralize UV version between Dockerfile and CircleCI - Update build container to use `uv` While at it, make life with the build container better: - Create `zrepl_build` user in the build container as same UID/GID as the caller of `make release-docker` - Allow Ctrl-C to cancel `make release-docker` in interactive shells --- .circleci/config.yml | 15 ++++++++++----- .uv-version | 1 + Makefile | 11 +++++++---- build/build.Dockerfile | 30 +++++++++++++++++++----------- 4 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 .uv-version diff --git a/.circleci/config.yml b/.circleci/config.yml index ea9d367..b3a3528 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,14 +16,19 @@ commands: echo "$line" >> $BASH_ENV fi - # NOTE: when updating uv version, update both the install URL and cache keys below + # NOTE: UV version is defined in .uv-version file at repository root install-docdep: steps: + - run: + name: Read UV version from .uv-version + command: | + UV_VERSION=$(cat .uv-version) + echo "export UV_VERSION=$UV_VERSION" >> $BASH_ENV # Python is managed by uv - it will automatically download the version # specified in docs/.python-version when needed - run: name: Install uv - command: curl -LsSf https://astral.sh/uv/0.9.30/install.sh | sh + command: curl -LsSf https://astral.sh/uv/${UV_VERSION}/install.sh | sh - run: name: Add uv to PATH and set cache dir command: | @@ -32,8 +37,8 @@ commands: - restore_cache: name: Restore uv cache keys: - - uv-cache-v1-0.9.30-{{ checksum "docs/uv.lock" }} - - uv-cache-v1-0.9.30- + - uv-cache-v1-${UV_VERSION}-{{ checksum "docs/uv.lock" }} + - uv-cache-v1-${UV_VERSION}- save-uv-cache: steps: @@ -42,7 +47,7 @@ commands: command: uv cache prune --ci - save_cache: name: Save uv cache - key: uv-cache-v1-0.9.30-{{ checksum "docs/uv.lock" }} + key: uv-cache-v1-${UV_VERSION}-{{ checksum "docs/uv.lock" }} paths: - ~/.cache/uv diff --git a/.uv-version b/.uv-version new file mode 100644 index 0000000..7a4cc25 --- /dev/null +++ b/.uv-version @@ -0,0 +1 @@ +0.9.30 diff --git a/Makefile b/Makefile index 8777fb1..2bf3506 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ endif ifneq ($(RELEASE_DOCKER_CACHEMOUNT),) - _RELEASE_DOCKER_CACHEMOUNT := -v $(RELEASE_DOCKER_CACHEMOUNT)/mod:/go/pkg/mod -v $(RELEASE_DOCKER_CACHEMOUNT)/xdg-cache:/root/.cache/go-build + _RELEASE_DOCKER_CACHEMOUNT := -v $(RELEASE_DOCKER_CACHEMOUNT)/mod:/go/pkg/mod -v $(RELEASE_DOCKER_CACHEMOUNT)/xdg-cache:/.cache/go-build .PHONY: release-docker-mkcachemount release-docker-mkcachemount: mkdir -p $(RELEASE_DOCKER_CACHEMOUNT) @@ -71,10 +71,13 @@ release: ensure-release-toolchain release-docker: $(ARTIFACTDIR) release-docker-mkcachemount sed 's/FROM.*!SUBSTITUTED_BY_MAKEFILE/FROM $(RELEASE_DOCKER_BASEIMAGE)/' build/build.Dockerfile > $(ARTIFACTDIR)/build.Dockerfile - docker build -t zrepl_release --pull -f $(ARTIFACTDIR)/build.Dockerfile . - docker run --rm -i \ + docker build -t zrepl_release --pull \ + --build-arg BUILD_UID=$$(id -u) \ + --build-arg BUILD_GID=$$(id -g) \ + -f $(ARTIFACTDIR)/build.Dockerfile . + docker run --rm -i$$(test -t 0 && echo t) \ $(_RELEASE_DOCKER_CACHEMOUNT) \ - -v $(CURDIR):/src -u $$(id -u):$$(id -g) \ + -v $(CURDIR):/src \ zrepl_release \ make release \ GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) \ diff --git a/build/build.Dockerfile b/build/build.Dockerfile index fc7e45f..c660d61 100644 --- a/build/build.Dockerfile +++ b/build/build.Dockerfile @@ -1,22 +1,30 @@ FROM !SUBSTITUTED_BY_MAKEFILE -RUN apt-get update && apt-get install -y \ - python3-pip \ - python3-venv \ - unzip \ - gawk +ARG BUILD_UID=1000 +ARG BUILD_GID=1000 -# setup venv for docs -ENV VIRTUAL_ENV=/opt/venv -RUN python3 -m venv $VIRTUAL_ENV -ENV PATH="$VIRTUAL_ENV/bin:$PATH" -ADD docs/requirements.txt /tmp/requirements.txt -RUN pip3 install -r /tmp/requirements.txt +RUN apt-get update && apt-get install -y \ + python3 \ + unzip \ + gawk \ + curl + +# Create build user with the host's UID/GID before installing uv +RUN groupadd -g ${BUILD_GID} zrepl_build && \ + useradd -u ${BUILD_UID} -g ${BUILD_GID} -m zrepl_build # Go toolchain uses xdg-cache RUN mkdir -p /.cache && chmod -R 0777 /.cache +# Install uv as the build user - version from .uv-version file +ADD .uv-version /tmp/.uv-version +USER zrepl_build +RUN UV_VERSION=$(cat /tmp/.uv-version) && \ + curl -LsSf https://astral.sh/uv/${UV_VERSION}/install.sh | sh + # Go devtools are managed by Makefile WORKDIR /src +ENV PATH="/home/zrepl_build/.local/bin:$PATH" \ + GOCACHE="/.cache/go-build"