Skip to content

Commit

Permalink
Build docker image in dev profile for docker-compose
Browse files Browse the repository at this point in the history
This improves turnaround speed when locally testing changes that require
rebuilding the docker image.
  • Loading branch information
Nemo157 committed Apr 2, 2024
1 parent 7f94ff7 commit 20a07b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ services:
build:
context: .
dockerfile: ./dockerfiles/Dockerfile
args:
PROFILE: dev
PROFILE_DIR: debug
platform: "linux/amd64"
depends_on:
- db
Expand Down
12 changes: 8 additions & 4 deletions dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ RUN mkdir -p src/bin && \
echo "fn main() {}" > build.rs

RUN cargo fetch
RUN cargo build --release

ARG PROFILE=release
RUN cargo build --profile=$PROFILE

# Dependencies are now cached, copy the actual source code and do another full
# build. The touch on all the .rs files is needed, otherwise cargo assumes the
Expand All @@ -54,7 +56,7 @@ COPY assets assets/
COPY .sqlx .sqlx/
COPY migrations migrations/

RUN cargo build --release
RUN cargo build --profile=$PROFILE

######################
# Web server stage #
Expand All @@ -69,7 +71,8 @@ RUN apt-get update \
tini \
&& rm -rf /var/lib/apt/lists/*

COPY --from=build /build/target/release/cratesfyi /usr/local/bin
ARG PROFILE_DIR=release
COPY --from=build /build/target/$PROFILE_DIR/cratesfyi /usr/local/bin
COPY static /srv/docsrs/static
COPY templates /srv/docsrs/templates
COPY vendor /srv/docsrs/vendor
Expand All @@ -96,7 +99,8 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \

RUN mkdir -p /opt/docsrs/prefix

COPY --from=build /build/target/release/cratesfyi /usr/local/bin
ARG PROFILE_DIR=release
COPY --from=build /build/target/$PROFILE_DIR/cratesfyi /usr/local/bin
COPY static /opt/docsrs/static
COPY templates /opt/docsrs/templates
COPY dockerfiles/entrypoint.sh /opt/docsrs/
Expand Down

0 comments on commit 20a07b8

Please sign in to comment.