Skip to content

Commit

Permalink
osrdyne, gateway, editoast: change docker base images to alpine
Browse files Browse the repository at this point in the history
Signed-off-by: ElysaSrc <101974839+ElysaSrc@users.noreply.github.com>
  • Loading branch information
ElysaSrc committed Oct 4, 2024
1 parent 665c62d commit d7e29de
Show file tree
Hide file tree
Showing 6 changed files with 512 additions and 718 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ jobs:
run: |
docker run --name=gateway-test --net=host -v $PWD/output:/output \
${{ fromJSON(needs.build.outputs.stable_tags).gateway-test }} \
/bin/bash -c "cargo test --verbose && grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore "/*" -o /output/lcov.info"
/bin/sh -c "cargo test --verbose && grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore "/*" -o /output/lcov.info"
exit $(docker wait gateway-test)
Expand Down Expand Up @@ -753,7 +753,7 @@ jobs:
run: |
docker run --name=osrdyne-test --net=host -v $PWD/output:/output \
${{ fromJSON(needs.build.outputs.stable_tags).osrdyne-test }} \
/bin/bash -c "cargo test --verbose && grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore "/*" -o /output/lcov.info"
/bin/sh -c "cargo test --verbose && grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore "/*" -o /output/lcov.info"
exit $(docker wait osrdyne-test)
Expand Down
20 changes: 8 additions & 12 deletions editoast/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
##############
# Cargo chef #
##############
FROM lukemathwalker/cargo-chef:0.1.67-rust-1.81.0 AS chef
FROM lukemathwalker/cargo-chef:0.1.68-rust-1.81-alpine3.20 AS chef
WORKDIR /editoast

#######################
Expand All @@ -16,8 +16,9 @@ RUN cargo chef prepare --recipe-path recipe.json
######################
FROM chef as base_builder
# geos crate requirement
RUN apt update -yqq && apt install -yqq --no-install-recommends libgeos-dev mold
RUN apk add --no-cache build-base openssl-dev mold libpq-dev geos-dev
# Instal diesel_cli
ENV RUSTFLAGS="-C target-feature=-crt-static -C link-arg=-fuse-ld=mold"
RUN cargo install diesel_cli --no-default-features --features postgres
COPY --from=static_assets . /assets

Expand All @@ -32,8 +33,7 @@ RUN rustup component add llvm-tools && \
COPY --from=planner /editoast/recipe.json recipe.json
COPY --from=planner /editoast/editoast_derive/ editoast_derive
COPY --from=test_data . /tests/data

ENV RUSTFLAGS="-Cinstrument-coverage -C link-arg=-fuse-ld=mold"
ENV RUSTFLAGS="-Cinstrument-coverage -C target-feature=-crt-static -C link-arg=-fuse-ld=mold"
ENV LLVM_PROFILE_FILE="editoast-%p-%m.profraw"
RUN cargo chef cook --tests --recipe-path recipe.json
COPY . .
Expand All @@ -44,10 +44,9 @@ COPY . .
FROM base_builder AS run_builder
COPY --from=planner /editoast/recipe.json recipe.json
COPY --from=planner /editoast/editoast_derive/ editoast_derive
ENV RUSTFLAGS="-C link-arg=-fuse-ld=mold"
ARG CARGO_PROFILE=release
ARG CARGO_FEATURES
RUN --mount=type=cache,target=/usr/local/cargo/registry \
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/editoast/target \
cargo chef cook --features="${CARGO_FEATURES}" --profile="${CARGO_PROFILE}" --recipe-path recipe.json
COPY . .
Expand All @@ -58,11 +57,8 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \
###############
# Running env #
###############
FROM debian:bookworm-slim as running_env
RUN apt update -yqq && \
apt install -yqq --no-install-recommends libpq-dev curl ca-certificates libgeos-dev libjemalloc2 && \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \
rm -rf /var/lib/apt/lists/*
FROM alpine:3.20 as running_env
RUN apk add --no-cache jemalloc curl ca-certificates geos libpq openssl

COPY --from=run_builder /usr/local/cargo/bin/editoast /usr/local/bin/editoast
COPY --from=run_builder /usr/local/cargo/bin/diesel /usr/local/bin/diesel
Expand All @@ -74,5 +70,5 @@ ENV OSRD_GIT_DESCRIBE=${OSRD_GIT_DESCRIBE}
ENV DYNAMIC_ASSETS_PATH=/assets

# We use jemalloc to reduce allocation fragmentation
ENV LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libjemalloc.so.2"
ENV LD_PRELOAD="/usr/lib/libjemalloc.so.2"
CMD ["editoast", "runserver"]
16 changes: 8 additions & 8 deletions gateway/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
##############
# Cargo chef #
##############
FROM lukemathwalker/cargo-chef:0.1.67-rust-1.81.0 AS chef
FROM lukemathwalker/cargo-chef:0.1.68-rust-1.81-alpine3.20 AS chef
WORKDIR /gateway

#######################
Expand All @@ -17,6 +17,8 @@ RUN cargo chef prepare --recipe-path recipe.json
# Cargo chef : build #
######################
FROM chef as run_builder
RUN apk add --no-cache musl-dev build-base jemalloc-dev openssl-dev mold
ENV RUSTFLAGS="-C link-arg=-fuse-ld=mold"
COPY --from=planner /gateway/recipe.json recipe.json
ARG CARGO_PROFILE=release
RUN --mount=type=cache,target=/usr/local/cargo/registry \
Expand Down Expand Up @@ -45,17 +47,15 @@ COPY . .
#######################
# Running env : build #
#######################
FROM debian:bookworm-slim as running_env
RUN apt update -yqq && \
apt install -yqq --no-install-recommends curl ca-certificates libjemalloc2 jq && \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \
rm -rf /var/lib/apt/lists/*
FROM alpine:3.20 as running_env
RUN apk add --no-cache jemalloc curl ca-certificates

COPY --from=run_builder /usr/local/cargo/bin/osrd_gateway /usr/local/bin/osrd_gateway

ARG OSRD_GIT_DESCRIBE
ENV OSRD_GIT_DESCRIBE=${OSRD_GIT_DESCRIBE}
# We use jemalloc to reduce allocation fragmentation
ENV LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libjemalloc.so.2"

# Preload jemalloc for memory optimization
ENV LD_PRELOAD="/usr/lib/libjemalloc.so.2"

CMD ["/usr/local/bin/osrd_gateway"]
Loading

0 comments on commit d7e29de

Please sign in to comment.