Skip to content

Commit

Permalink
Merge pull request #138 from amosproj/change/improve-generator-docker…
Browse files Browse the repository at this point in the history
…-build

Improved generator docker build by caching dependencies
  • Loading branch information
jandegen authored Dec 14, 2022
2 parents 6beb1de + 03b4f32 commit 63dd59f
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions Apps/generator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
# Use official rust:slim as base
FROM rust:slim
################
##### Builder
FROM rust:slim as builder

WORKDIR /usr/src

# Create folder structur for code
RUN mkdir -p /usr/src/generator
# Create blank project
RUN USER=root cargo new generator

# We want dependencies cached, so copy those first.
COPY Cargo.toml Cargo.lock /usr/src/generator/

# Set the working directory
WORKDIR /usr/src/generator

# Copy source code onto docker image
COPY . .
## Install target platform (Cross-Compilation) --> Needed for Alpine
RUN rustup target add x86_64-unknown-linux-musl

# This is a dummy build to get the dependencies cached.
RUN cargo build --target x86_64-unknown-linux-musl --release

# Now copy in the rest of the sources
COPY src /usr/src/generator/src/

## Touch main.rs to prevent cached release build
RUN touch /usr/src/generator/src/main.rs

# This is the actual application build.
RUN cargo build --target x86_64-unknown-linux-musl --release

################
##### Runtime
FROM alpine:3.16.0 AS runtime

# Build
RUN cargo build
# Copy application binary from builder image
COPY --from=builder /usr/src/generator/target/x86_64-unknown-linux-musl/release/generator /usr/local/bin

# Run on container start
CMD ["cargo", "run"]
# Run the application
CMD ["/usr/local/bin/generator"]

0 comments on commit 63dd59f

Please sign in to comment.