1
+ FROM nixos/nix:2.29.0 AS builder
2
+
3
+ RUN nix-env -iA nixpkgs.rsync nixpkgs.glibc nixpkgs.gawk
4
+
5
+ # Copy the source code into the container
6
+ COPY . /tmp/build
7
+ WORKDIR /tmp/build
8
+
9
+ # Set build to docker to skip the podman initilization while opening the flake
10
+ ENV BUILD=docker
11
+
12
+ # Build the Rust application
13
+ RUN nix --extra-experimental-features "nix-command flakes" \
14
+ develop .#docker-build --command bash -c "cargo build --release --bin movement"
15
+
16
+ RUN rust_binary="./target/release/movement" ; dest_dir="/tmp/runtime" ; \
17
+ mkdir -p "$dest_dir" ; ldd "$rust_binary" | awk '{print $3}' | \
18
+ grep '^/' | xargs -I {} dirname {} | sort | uniq | xargs -I {} \
19
+ bash -c 'mkdir -p "$0/$1" && rsync -a --copy-links "$1/" "$0/$1/"' "$dest_dir" {}
20
+
21
+
22
+ FROM alpine:3.22.0
23
+
24
+ # Create non-root user
25
+ RUN adduser -u 1000 -D -s /bin/bash movement
26
+
27
+ # Copy binary and runtime deps
28
+ COPY --from=builder /tmp/build/target/release/movement /app/movement
29
+ COPY --from=builder /tmp/runtime/nix/store /nix/store
30
+
31
+ # Environment setup
32
+ ENV PATH="/nix/var/nix/profiles/default/bin:$PATH"
33
+ ENV XDG_RUNTIME_DIR="/run/user/1000"
34
+ ENV TMPDIR="/tmp"
35
+ ENV DOCKER_HOST="unix:///run/user/1000/podman/podman-machine-default-api.sock"
36
+
37
+ # Create required runtime dirs with proper ownership
38
+ RUN mkdir -p /run/user/1000/podman && \
39
+ chown -R movement:movement /run/user/1000 /app /nix
40
+
41
+ # Copy runtime bootstrap script
42
+ COPY docker/build/movement/entry.sh /app/entry.sh
43
+ RUN chmod +x /app/entry.sh
44
+
45
+ # Switch to non-root user
46
+ USER movement
47
+
48
+ # Entrypoint to bootstrap podman and launch movement
49
+ ENTRYPOINT ["/app/entry.sh" ]
0 commit comments