Optimize caching in Dockerfile
This commit is contained in:
8
Cargo.lock
generated
8
Cargo.lock
generated
@ -1,5 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "addr2line"
|
||||
version = "0.14.1"
|
||||
@ -2166,7 +2168,7 @@ checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0"
|
||||
|
||||
[[package]]
|
||||
name = "stl"
|
||||
version = "2.6.4"
|
||||
version = "2.6.5"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"chrono",
|
||||
@ -2189,7 +2191,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "stl_cli"
|
||||
version = "2.6.4"
|
||||
version = "2.6.5"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"futures",
|
||||
@ -2208,7 +2210,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "stl_lib"
|
||||
version = "2.6.4"
|
||||
version = "2.6.5"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"serde",
|
||||
|
||||
52
Dockerfile
52
Dockerfile
@ -1,18 +1,56 @@
|
||||
##################
|
||||
### BASE STAGE ###
|
||||
##################
|
||||
FROM rust:1.53 as base
|
||||
|
||||
# Install build dependencies
|
||||
RUN cargo install strip_cargo_version
|
||||
RUN rustup target add x86_64-unknown-linux-musl
|
||||
|
||||
WORKDIR /app
|
||||
RUN mkdir cli lib server
|
||||
|
||||
|
||||
###########################
|
||||
### STRIP-VERSION STAGE ###
|
||||
###########################
|
||||
FROM base as strip-version
|
||||
|
||||
# Strip version from Cargo.*
|
||||
# This avoids cache invalidations (ergo rebuilding all deps) when bumping the version number
|
||||
COPY Cargo.lock Cargo.toml ./
|
||||
COPY server/Cargo.toml ./server/
|
||||
COPY cli/Cargo.toml ./cli/
|
||||
COPY lib/Cargo.toml ./lib/
|
||||
RUN strip_cargo_version
|
||||
|
||||
|
||||
###################
|
||||
### BUILD STAGE ###
|
||||
###################
|
||||
FROM rust:1.51 as build_stage
|
||||
FROM base as build_stage
|
||||
|
||||
# Install build dependencies
|
||||
RUN rustup target add x86_64-unknown-linux-musl
|
||||
RUN cargo init --bin server
|
||||
RUN cargo init --lib lib
|
||||
|
||||
# Create a dummy binary for pre-compiling dependencies (for caching)
|
||||
COPY --from=strip-version /app/server/Cargo.toml /app/server/
|
||||
COPY --from=strip-version /app/lib/Cargo.toml /app/lib/
|
||||
COPY --from=strip-version /app/cli/Cargo.toml /app/cli/
|
||||
COPY --from=strip-version /app/Cargo.lock /app/Cargo.toml /app/
|
||||
|
||||
# Build project
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
WORKDIR /app/server
|
||||
RUN cargo build --release --target x86_64-unknown-linux-musl
|
||||
|
||||
# Copy actual source files
|
||||
WORKDIR /app
|
||||
RUN strip target/x86_64-unknown-linux-musl/release/stl
|
||||
COPY . .
|
||||
|
||||
# Compile final binary
|
||||
WORKDIR /app/server
|
||||
RUN cargo build --release --target x86_64-unknown-linux-musl
|
||||
RUN strip /app/target/x86_64-unknown-linux-musl/release/stl
|
||||
|
||||
|
||||
########################
|
||||
### PRODUCTION STAGE ###
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "stl_cli"
|
||||
version = "2.6.4"
|
||||
version = "2.6.5"
|
||||
authors = ["Joakim Hulthe <joakim@hulthe.net>"]
|
||||
license = "MPL-2.0"
|
||||
edition = "2018"
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "stl_lib"
|
||||
version = "2.6.4"
|
||||
version = "2.6.5"
|
||||
authors = ["Joakim Hulthe <joakim@hulthe.net>"]
|
||||
license = "MPL-2.0"
|
||||
edition = "2018"
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "stl"
|
||||
description = "studielogg aka scuffed toggl"
|
||||
version = "2.6.4"
|
||||
version = "2.6.5"
|
||||
authors = ["Joakim Hulthe <joakim@hulthe.net>"]
|
||||
license = "MPL-2.0"
|
||||
edition = "2018"
|
||||
|
||||
Reference in New Issue
Block a user