-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Don't include node_modules in Docker context * Add env var to provide precompiled webapp assets * Do npm build in separate Dockerfile stage * Use cargo chef in Dockerfile * Use sparse registry protocol in Dockerfile * Use docker buildx caching in CI
- Loading branch information
1 parent
18ebe35
commit e6a4542
Showing
7 changed files
with
68 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target | ||
*/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,43 @@ | ||
FROM rust:1.69.0-alpine as builder | ||
FROM node:alpine as assets | ||
WORKDIR /src/app | ||
COPY app/package.json /src/app/package.json | ||
COPY app/package-lock.json /src/app/package-lock.json | ||
RUN npm ci | ||
COPY app /src/app | ||
RUN npm ci | ||
RUN npm run build | ||
|
||
FROM rust:1.69.0-alpine as chef | ||
RUN apk add libc-dev | ||
RUN apk add --update npm | ||
ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse | ||
RUN cargo install cargo-chef | ||
WORKDIR /src | ||
COPY app /src/app | ||
|
||
FROM chef AS planner | ||
COPY Cargo.toml /src/Cargo.toml | ||
COPY Cargo.lock /src/Cargo.lock | ||
COPY build.rs /src/build.rs | ||
COPY migration /src/migration | ||
COPY src /src/src | ||
RUN cargo chef prepare --recipe-path recipe.json | ||
|
||
FROM chef as builder | ||
COPY --from=planner /src/recipe.json /src/recipe.json | ||
RUN cargo chef cook --workspace --release --recipe-path recipe.json | ||
COPY Cargo.toml /src/Cargo.toml | ||
COPY Cargo.lock /src/Cargo.lock | ||
COPY build.rs /src/build.rs | ||
COPY migration /src/migration | ||
COPY src /src/src | ||
RUN cd app && npm ci | ||
COPY --from=assets /src/app/build /src/app/build | ||
ARG RUST_FEATURES=default | ||
RUN --mount=type=cache,target=/usr/local/cargo/registry \ | ||
--mount=type=cache,target=/src/target \ | ||
cargo build --profile release -p migration && \ | ||
cp /src/target/release/migration /migration | ||
RUN --mount=type=cache,target=/usr/local/cargo/registry \ | ||
--mount=type=cache,target=/src/target \ | ||
cargo build --profile release --features ${RUST_FEATURES} && \ | ||
cp /src/target/release/divviup_api_bin /divviup_api_bin | ||
RUN ASSET_DIR=/src/app/build cargo build --workspace --release --features ${RUST_FEATURES} | ||
|
||
FROM alpine:3.17.3 | ||
FROM alpine:3.17.3 AS final | ||
ARG GIT_REVISION=unknown | ||
LABEL revision ${GIT_REVISION} | ||
EXPOSE 8080 | ||
ENV HOST=0.0.0.0 | ||
COPY --from=builder /migration /migration | ||
COPY --from=builder /divviup_api_bin /divviup_api_bin | ||
COPY --from=builder /src/target/release/migration /migration | ||
COPY --from=builder /src/target/release/divviup_api_bin /divviup_api_bin | ||
ENTRYPOINT ["/divviup_api_bin"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters