Skip to content

Commit

Permalink
Split build-container-image into build-container-image-{debug,release}
Browse files Browse the repository at this point in the history
This allows `run-in-container` to default to using the much faster
`build-container-image-debug`.
  • Loading branch information
spantaleev committed Sep 21, 2024
1 parent 2a5a2d6 commit c8c5e0e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
15 changes: 12 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

#######################################
# #
Expand Down
12 changes: 10 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 }} \
.

Expand Down

0 comments on commit c8c5e0e

Please sign in to comment.