Investigate cargo-chef to cache things
Some checks failed
Build and Publish Docker Container / build (push) Has been cancelled
Some checks failed
Build and Publish Docker Container / build (push) Has been cancelled
This commit is contained in:
parent
b8c1faced2
commit
d7d7fa9718
7
.github/workflows/build.yml
vendored
7
.github/workflows/build.yml
vendored
@ -10,17 +10,11 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: catthehacker/ubuntu:act-latest
|
||||
env:
|
||||
RUNNER_TOOL_CACHE: /toolcache
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
|
||||
# Note to self: maybe look at this if we want to build outside docker?
|
||||
# - name: Build with cache
|
||||
# uses: Swatinem/rust-cache@v2
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
|
||||
@ -36,6 +30,7 @@ jobs:
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
file: ./Dockerfile.cache
|
||||
tags: git.joshuacoles.me/personal/monzo-ingestion:latest
|
||||
cache-from: type=registry,ref=user/app:latest
|
||||
cache-to: type=inline
|
||||
|
||||
58
Dockerfile.cache
Normal file
58
Dockerfile.cache
Normal file
@ -0,0 +1,58 @@
|
||||
# Stage 1: Build
|
||||
ARG RUST_VERSION=1.76.0
|
||||
FROM lukemathwalker/cargo-chef:latest-rust-${RUST_VERSION} as chef
|
||||
WORKDIR /build/
|
||||
# hadolint ignore=DL3008
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
lld \
|
||||
clang \
|
||||
libclang-dev \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
FROM chef as planner
|
||||
COPY . .
|
||||
RUN cargo chef prepare --recipe-path recipe.json
|
||||
|
||||
FROM chef as builder
|
||||
COPY --from=planner /build/recipe.json recipe.json
|
||||
# Build dependencies - this is the caching Docker layer!
|
||||
RUN cargo chef cook --release -p monzo-ingestion --recipe-path recipe.json
|
||||
# Build application
|
||||
COPY . .
|
||||
RUN cargo build --release -p monzo-ingestion
|
||||
|
||||
# Stage 2: Run
|
||||
FROM debian:bullseye-slim AS final
|
||||
|
||||
RUN set -ex; \
|
||||
apt-get update && \
|
||||
apt-get -y install --no-install-recommends \
|
||||
ca-certificates curl && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Create a non-privileged user that the app will run under.
|
||||
# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
|
||||
ARG UID=10001
|
||||
RUN adduser \
|
||||
--disabled-password \
|
||||
--gecos "" \
|
||||
--home "/nonexistent" \
|
||||
--shell "/sbin/nologin" \
|
||||
--no-create-home \
|
||||
--uid "${UID}" \
|
||||
appuser
|
||||
USER appuser
|
||||
|
||||
# Copy the executable from the "build" stage.
|
||||
COPY --from=builder /build/target/release/monzo-ingestion /bin/
|
||||
|
||||
# Expose the port that the application listens on.
|
||||
EXPOSE 3000
|
||||
|
||||
HEALTHCHECK --interval=5s --timeout=3s --retries=3 \
|
||||
CMD curl -f http://localhost:3000/health || exit 1
|
||||
|
||||
# What the container should run when it is started.
|
||||
CMD ["/bin/server"]
|
||||
@ -27,6 +27,7 @@ enum Commands {
|
||||
#[arg(long)]
|
||||
down: bool,
|
||||
},
|
||||
|
||||
Run {
|
||||
/// If we should perform migration on startup.
|
||||
#[clap(short, long, env, default_value_t = true)]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user