Split build-container-image into build-container-image-{debug,release}
This allows `run-in-container` to default to using the much faster `build-container-image-debug`.
This commit is contained in:
15
Dockerfile
15
Dockerfile
@@ -15,14 +15,23 @@ WORKDIR /app
|
|||||||
|
|
||||||
COPY . /app
|
COPY . /app
|
||||||
|
|
||||||
|
ARG RELEASE_BUILD=true
|
||||||
|
|
||||||
RUN --mount=type=cache,target=/cargo,sharing=locked \
|
RUN --mount=type=cache,target=/cargo,sharing=locked \
|
||||||
--mount=type=cache,target=/target,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.
|
# Move it out of the mounted cache, so we can copy it in the next stage.
|
||||||
RUN --mount=type=cache,target=/target,sharing=locked \
|
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
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
# #
|
# #
|
||||||
|
|||||||
@@ -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).
|
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`.
|
If you nevertheless wish to build a container image yourself, you can do so by running:
|
||||||
This will build and tag your container image as `localhost/baibot:latest`.
|
|
||||||
|
- (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
|
### 🐋 Running in a container
|
||||||
|
|||||||
13
justfile
13
justfile
@@ -14,7 +14,7 @@ run-locally *extra_args: app-local-prepare
|
|||||||
cargo run -- {{ extra_args }}
|
cargo run -- {{ extra_args }}
|
||||||
|
|
||||||
# Builds and runs the bot in a container
|
# 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 \
|
/usr/bin/env docker run \
|
||||||
-it \
|
-it \
|
||||||
--rm \
|
--rm \
|
||||||
@@ -39,9 +39,16 @@ build-debug *extra_args:
|
|||||||
# Builds an optimized release binary (target/release/*)
|
# Builds an optimized release binary (target/release/*)
|
||||||
build-release *extra_args: (build-debug "--release")
|
build-release *extra_args: (build-debug "--release")
|
||||||
|
|
||||||
# Builds a container image
|
# Builds a container image (debug mode)
|
||||||
build-container-image tag='latest':
|
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 \
|
/usr/bin/env docker build \
|
||||||
|
--build-arg RELEASE_BUILD={{ release_build }} \
|
||||||
|
-f {{ justfile_directory() }}/Dockerfile \
|
||||||
-t {{ container_image_name }}:{{ tag }} \
|
-t {{ container_image_name }}:{{ tag }} \
|
||||||
.
|
.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user