Skip to content

Commit 6272f07

Browse files
committed
Create a Docker setup
1 parent 9ec2558 commit 6272f07

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

Dockerfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# syntax=docker/dockerfile:1
2+
3+
# We use Nix to build DiffDetective.
4+
FROM nixos/nix:2.22.0 AS builder
5+
6+
# Create and navigate to a working directory
7+
WORKDIR /home/user
8+
9+
# Copy all of the source code into the working directory. Impurities like
10+
# additional files and previous build results will be filtered by Nix. Note that
11+
# All files which are considered *tracked* by Git will be used for the build,
12+
# even if they are modified.
13+
COPY . .
14+
15+
# Build the DiffDetective demo. This also all dependencies (e.g., DiffDetective
16+
# itselves) using the default nix binary cache.
17+
RUN nix-build
18+
19+
# Copy DiffDetective with all runtime dependencies (ignoring build-time
20+
# dependencies) to a separate folder. Such a subset of the Nix store is called a
21+
# closure and enables us to create a minimal Docker container.
22+
RUN mkdir closure
23+
RUN nix-store -qR result | xargs cp -Rt closure
24+
25+
# Start building the final container.
26+
FROM scratch
27+
28+
# Create another working directory for runtime files (e.g., cloned repositories).
29+
WORKDIR /home/user
30+
31+
# Copy DiffDetective (it's runtime closure) to the final container.
32+
COPY --from=builder /home/user/closure /nix/store
33+
34+
# Copy the Symlink to the DiffDetective derivation, mostly for convenience.
35+
COPY --from=builder /home/user/result /DiffDetective
36+
37+
# Copy the necessary data. Beware that this directory might have impure files.
38+
COPY data /home/user/data
39+
40+
ENV DISPLAY=:0 HOME=/home/user
41+
CMD ["/DiffDetective/bin/DiffDetective-Demo"]

docker.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
4+
5+
usage() {
6+
echo >&2 "Usage: $0 [build|demo]
7+
8+
To run the demo you need to build the docker container once using '$0 build'.
9+
Afterwards, you can run '$0 demo'."
10+
exit 1
11+
}
12+
13+
if [ $# -ne 1 ]
14+
then
15+
usage
16+
fi
17+
18+
case "$1" in
19+
build)
20+
# Check if Nix is installed and try to build the Docker container with Nix.
21+
# If Nix is not installed or the build failed due to any reason, try to
22+
# build with Docker.
23+
( which nix &>/dev/null && nix-build nix/docker.nix && docker load < result ) ||
24+
docker build . --tag diffdetective-demo:1.0.0 || echo "Failed to build the docker container." && echo "Docker container sucessfully built."
25+
;;
26+
demo)
27+
docker run --rm --net=host --volume="$HOME/.Xauthority:/home/user/.Xauthority:rw" -e _JAVA_AWT_WM_NONREPARENTING="$_JAVA_AWT_WM_NONREPARENTING" diffdetective-demo:1.0.0
28+
;;
29+
*)
30+
usage
31+
;;
32+
esac

0 commit comments

Comments
 (0)