From 730f7ae1fcb101eea5cebd48a315d7ea5d3cac71 Mon Sep 17 00:00:00 2001 From: Yorgos Saslis Date: Tue, 18 Jun 2024 12:11:19 +0300 Subject: [PATCH] build: switch to build args over env vars in dockerfile `--env` is a podman-specific feature. While it is clear that podman is a requirement here, switching these to build arguments better expresses intent. These values are meant to be configurable at build time, which is exactly what build arguments are for, while environment variables are meant to persist in the image built. Additionally, this removes unused env vars. Signed-off-by: Yorgos Saslis --- radicle-httpd/build/Dockerfile | 11 ++++++++++- radicle-httpd/build/build | 20 ++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/radicle-httpd/build/Dockerfile b/radicle-httpd/build/Dockerfile index 8ae30d1fd..c02b58861 100644 --- a/radicle-httpd/build/Dockerfile +++ b/radicle-httpd/build/Dockerfile @@ -4,6 +4,11 @@ LABEL maintainer="Radicle Team " WORKDIR /src COPY . . +ARG TZ +ARG LC_ALL +ARG SOURCE_DATE_EPOCH +ARG RADICLE_VERSION + # Copy cargo configuration we're going to use to specify compiler options. RUN mkdir -p .cargo && cp build/config.toml .cargo/config.toml # Install dependencies. @@ -49,6 +54,10 @@ RUN cargo zigbuild --locked --release \ # Now copy the files to a new image without all the intermediary artifacts to # save some space. FROM alpine:3.19 as packager + +ARG RADICLE_VERSION +ARG SOURCE_DATE_EPOCH + COPY --from=builder \ /src/target/x86_64-unknown-linux-musl/release/rad-web \ /src/target/x86_64-unknown-linux-musl/release/radicle-httpd \ @@ -77,7 +86,7 @@ RUN find * -maxdepth 0 -type d -exec mv '{}' "radicle-$RADICLE_VERSION-{}" \; && find * -maxdepth 0 -type d -exec tar \ --sort=name \ --verbose \ - --mtime="@$GIT_COMMIT_TIME" \ + --mtime="@$SOURCE_DATE_EPOCH" \ --owner=0 \ --group=0 \ --numeric-owner \ diff --git a/radicle-httpd/build/build b/radicle-httpd/build/build index 0c8ed44b8..852846634 100755 --- a/radicle-httpd/build/build +++ b/radicle-httpd/build/build @@ -49,12 +49,10 @@ main() { case "$OS" in Darwin) podman build \ - --env SOURCE_DATE_EPOCH \ - --env TZ \ - --env LC_ALL \ - --env GIT_COMMIT_TIME=$SOURCE_DATE_EPOCH \ - --env GIT_HEAD=$rev \ - --env RADICLE_VERSION=$version \ + --build-arg SOURCE_DATE_EPOCH \ + --build-arg TZ \ + --build-arg LC_ALL \ + --build-arg RADICLE_VERSION=$version \ --arch aarch64 --tag $image -f ./build/Dockerfile - <$gitarchive echo "Creating container (radicle-build-container).." @@ -62,12 +60,10 @@ main() { ;; *) podman --cgroup-manager=cgroupfs build \ - --env SOURCE_DATE_EPOCH \ - --env TZ \ - --env LC_ALL \ - --env GIT_COMMIT_TIME=$SOURCE_DATE_EPOCH \ - --env GIT_HEAD=$rev \ - --env RADICLE_VERSION=$version \ + --build-arg SOURCE_DATE_EPOCH \ + --build-arg TZ \ + --build-arg LC_ALL \ + --build-arg RADICLE_VERSION=$version \ --arch amd64 --tag $image -f ./build/Dockerfile - <$gitarchive echo "Creating container (radicle-build-container).."