Skip to content

Commit d452dd4

Browse files
Nemo157syphar
authored andcommitted
Build docker image in dev profile for docker-compose
This improves turnaround speed when locally testing changes that require rebuilding the docker image.
1 parent 71c2894 commit d452dd4

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ services:
44
build:
55
context: .
66
dockerfile: ./dockerfiles/Dockerfile
7+
args:
8+
PROFILE: dev
9+
PROFILE_DIR: debug
710
platform: "linux/amd64"
811
depends_on:
912
- db

dockerfiles/Dockerfile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ RUN mkdir -p src/bin && \
3636
echo "fn main() {}" > build.rs
3737

3838
RUN cargo fetch
39-
RUN cargo build --release
39+
40+
ARG PROFILE=release
41+
RUN cargo build --profile=$PROFILE
4042

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

57-
RUN cargo build --release
59+
RUN cargo build --profile=$PROFILE
5860

5961
######################
6062
# Web server stage #
@@ -69,7 +71,8 @@ RUN apt-get update \
6971
tini \
7072
&& rm -rf /var/lib/apt/lists/*
7173

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

97100
RUN mkdir -p /opt/docsrs/prefix
98101

99-
COPY --from=build /build/target/release/cratesfyi /usr/local/bin
102+
ARG PROFILE_DIR=release
103+
COPY --from=build /build/target/$PROFILE_DIR/cratesfyi /usr/local/bin
100104
COPY static /opt/docsrs/static
101105
COPY templates /opt/docsrs/templates
102106
COPY dockerfiles/entrypoint.sh /opt/docsrs/

0 commit comments

Comments
 (0)