forked from moq-dev/moq
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
43 lines (33 loc) · 1.47 KB
/
Dockerfile
File metadata and controls
43 lines (33 loc) · 1.47 KB
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
# We're using a Dockerfile despite the fact that Nix can create Docker images directly.
#
# 1. It's difficult to cross compile Docker images with Nix.
# - I tried, but OSX makes it even more difficult.
# 2. Nix is not required for developers; `docker build .` will work.
#
# Unfortunately, it means that caching is more difficult.
# Nix uses /nix/store for both caching AND the final output (lots of symlinks)
FROM nixos/nix:latest AS builder
ENV NIX_CONFIG="experimental-features = nix-command flakes"
WORKDIR /build
RUN mkdir -p /output/store
COPY . .
# Build stage that accepts an optional package argument
ARG package
# Build the package
RUN --mount=type=cache,target=/root/.cache --mount=type=cache,target=/nix,from=nixos/nix:latest,source=/nix \
nix build .#${package} --out-link result && \
cp -r $(nix-store -qR result) /output/store && \
cp -r $(readlink -f result) /output/result && \
rm -rf /output/store/$(basename $(readlink -f result))
# Default to `/bin/sh` for the entrypoint if no package is specified
ARG package="sh"
# Create entry.sh script that knows which binary to run
RUN echo '#!/bin/sh' > /output/entry.sh && \
echo "exec /bin/${package} \"\$@\"" >> /output/entry.sh && \
chmod +x /output/entry.sh
# Final image (when no specific package is selected, defaults to sh)
FROM nixos/nix:latest
COPY --from=builder /output/entry.sh /bin/entry.sh
COPY --from=builder /output/store /nix/store
COPY --from=builder /output/result/bin/* /bin/
ENTRYPOINT ["/bin/entry.sh"]