-
Notifications
You must be signed in to change notification settings - Fork 0
/
Earthfile
76 lines (58 loc) · 2.17 KB
/
Earthfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
VERSION 0.8
FROM rust:1
ARG --global PUSH_CACHE=true
prepare:
FROM rust:1
WORKDIR /code
RUN apt-get --yes update && apt-get --yes install cmake musl-tools
ENV CARGO_BUILD_TARGET=x86_64-unknown-linux-musl
RUN rustup target add "${CARGO_BUILD_TARGET}"
RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
RUN cargo binstall --secure --no-confirm --no-cleanup cargo-chef cargo-nextest
IF ${PUSH_CACHE} == "true"
SAVE IMAGE --push ghcr.io/nais/mutilator/cache:prepare
ELSE
SAVE IMAGE ghcr.io/nais/mutilator/cache:prepare
END
chef-planner:
FROM +prepare
COPY --dir src .config Cargo.lock Cargo.toml .
RUN cargo chef prepare --recipe-path recipe.json
SAVE ARTIFACT recipe.json
chef-cook:
FROM +prepare
COPY +chef-planner/recipe.json recipe.json
RUN cargo chef cook --recipe-path recipe.json --release --tests
RUN cargo chef cook --recipe-path recipe.json --release
IF ${PUSH_CACHE} == "true"
SAVE IMAGE --push ghcr.io/nais/mutilator/cache:chef-cook
ELSE
SAVE IMAGE ghcr.io/nais/mutilator/cache:chef-cook
END
build:
FROM +chef-cook
COPY --dir src .config Cargo.lock Cargo.toml .
RUN cargo build --release
RUN cargo nextest run --profile ci --release
SAVE ARTIFACT target/${CARGO_BUILD_TARGET}/release/mutilator mutilator
SAVE ARTIFACT target/nextest/ci/junit.xml AS LOCAL target/nextest/ci/junit.xml
IF ${PUSH_CACHE} == "true"
SAVE IMAGE --push ghcr.io/nais/mutilator/cache:build
ELSE
SAVE IMAGE ghcr.io/nais/mutilator/cache:build
END
docker:
FROM gcr.io/distroless/static-debian11:nonroot
# Explicitly build these targets so that the cache images are pushed
BUILD +prepare
BUILD +chef-cook
BUILD +build
WORKDIR /
COPY +build/mutilator /
CMD ["/mutilator"]
# builtins must be declared
ARG EARTHLY_GIT_SHORT_HASH
ARG REGISTRY=europe-north1-docker.pkg.dev/nais-io/nais/images
ARG image=${REGISTRY}/mutilator
ARG VERSION=$EARTHLY_GIT_SHORT_HASH
SAVE IMAGE --push ${image}:${VERSION} ${image}:latest