diff --git a/Dockerfile b/Dockerfile index 1565734..9304e2c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,14 +15,23 @@ WORKDIR /app COPY . /app +ARG RELEASE_BUILD=true + RUN --mount=type=cache,target=/cargo,sharing=locked \ --mount=type=cache,target=/target,sharing=locked \ - cargo build --release + if [ "$RELEASE_BUILD" = "true" ]; then \ + cargo build --release; \ + else \ + cargo build; \ + fi # Move it out of the mounted cache, so we can copy it in the next stage. RUN --mount=type=cache,target=/target,sharing=locked \ - cp /target/release/baibot /baibot - + if [ "$RELEASE_BUILD" = "true" ]; then \ + cp /target/release/baibot /baibot; \ + else \ + cp /target/debug/baibot /baibot; \ + fi ####################################### # # diff --git a/docs/installation.md b/docs/installation.md index 3ec4070..8079210 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -15,8 +15,16 @@ We provide prebuilt container images for the `amd64` and `arm64` architectures, so **you don't necessarily need to build images yourself** and can jump to [Running in a container](#-running-in-a-container). -If you nevertheless wish to build a container image yourself, you can do so by running `just build-container-image`. -This will build and tag your container image as `localhost/baibot:latest`. +If you nevertheless wish to build a container image yourself, you can do so by running: + +- (recommended) `just build-container-image-release` to build a release version of the container image + +- or `just build-container-image-debug` to build a debug version of the container image + +Debug images are faster to build but are larger in size. +Release images are ~5x smaller in size, but are slower to build. + +Both of these commands will build and tag your container image as `localhost/baibot:latest`. ### 🐋 Running in a container diff --git a/justfile b/justfile index b14de7e..8ffafcd 100644 --- a/justfile +++ b/justfile @@ -14,7 +14,7 @@ run-locally *extra_args: app-local-prepare cargo run -- {{ extra_args }} # Builds and runs the bot in a container -run-in-container *extra_args: app-container-prepare build-container-image +run-in-container *extra_args: app-container-prepare build-container-image-debug /usr/bin/env docker run \ -it \ --rm \ @@ -39,9 +39,16 @@ build-debug *extra_args: # Builds an optimized release binary (target/release/*) build-release *extra_args: (build-debug "--release") -# Builds a container image -build-container-image tag='latest': +# Builds a container image (debug mode) +build-container-image-debug tag='latest': (_build-container-image "false" tag) + +# Builds a container image (release mode) +build-container-image-release tag='latest': (_build-container-image "true" tag) + +_build-container-image release_build tag: /usr/bin/env docker build \ + --build-arg RELEASE_BUILD={{ release_build }} \ + -f {{ justfile_directory() }}/Dockerfile \ -t {{ container_image_name }}:{{ tag }} \ .