Skip to content

Commit 9ebbe4e

Browse files
committed
Create a script for compiling the jar
1 parent 021c14f commit 9ebbe4e

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ RUN nix-build
2323
RUN mkdir -p /etc/fonts && nix-build nix/fontconfig.nix --out-link /etc/fonts/fonts.conf
2424
RUN mkdir -p /var/cache/fontconfig && nix-shell -p fontconfig --run fc-cache
2525

26+
# We need `cp` to copy out the jar.
27+
RUN nix-build '<nixpkgs>' -A coreutils -o coreutils
28+
2629
# Copy DiffDetective with all runtime dependencies (ignoring build-time
2730
# dependencies) to a separate folder. Such a subset of the Nix store is called a
2831
# closure and enables us to create a minimal Docker container.
2932
RUN mkdir closure
30-
RUN nix-store -qR result /etc/fonts/fonts.conf | xargs cp -Rt closure
33+
RUN nix-store -qR result /etc/fonts/fonts.conf coreutils | xargs cp -Rt closure
3134

3235
# Start building the final container.
3336
FROM scratch
@@ -48,5 +51,8 @@ COPY data /home/user/data
4851
COPY --from=builder /etc/fonts/fonts.conf /etc/fonts/fonts.conf
4952
COPY --from=builder /var/cache/fontconfig /var/cache/fontconfig
5053

54+
# Install `cp`
55+
COPY --from=builder /home/user/coreutils/bin/cp /bin/cp
56+
5157
ENV DISPLAY=:0 HOME=/home/user
5258
CMD ["/DiffDetective/bin/DiffDetective-Demo"]

build-jar.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
3+
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
4+
5+
if command -v nix-build &>/dev/null
6+
then
7+
echo "Using Nix to build the DiffDetective demo jar."
8+
nix-build &&
9+
cp result/share/java/DiffDetective-Demo.jar . &&
10+
echo "The jar has been built successfully. You can find it in $(realpath DiffDetective-Demo.jar)" &&
11+
echo "You might want to remove the 'result' link ('rm result') to allow the Nix garbage collector to reclaim some space."
12+
elif command -v docker &>/dev/null
13+
then
14+
echo "Using Docker to build the DiffDetective demo jar."
15+
16+
root=0
17+
if ! groups | grep -q docker
18+
then
19+
if [ "$(id -u)" -ne 0 ]
20+
then
21+
echo >&2 "You don't seem to be able to run Docker as your user. Please start this script as root (e.g., using 'sudo') or ensure you are a member of the docker group."
22+
exit 2
23+
fi
24+
fi
25+
26+
if ! docker version &>/dev/null
27+
then
28+
echo >&2 "Docker isn't running. You need to start the docker engine first."
29+
echo >&2 "On most Linux distributions you can do so using 'systemctl start docker'."
30+
exit 3
31+
fi
32+
33+
docker build . --tag diffdetective-demo:1.0.0 &&
34+
docker run --volume "$(realpath .):/output:rw" diffdetective-demo:1.0.0 /bin/cp /DiffDetective/share/java/DiffDetective-Demo.jar /output
35+
36+
if [ "$?" -eq 0 ]
37+
then
38+
echo
39+
echo "The jar has been built successfully. You can find it in $(realpath DiffDetective-Demo.jar)"
40+
echo "You might want to remove the Docker image ('docker image rm diffdetective-demo:1.0.0')."
41+
42+
if [ "$(id -u)" -eq 0 ]
43+
then
44+
echo "You might want to change the owner of the jar ('chown username:group DiffDetective-Demo.jar') because it's current owner is root."
45+
fi
46+
fi
47+
else
48+
echo "Neither Nix nor Docker are installed. You need to compile the jar for yourselves. See INSTALL.md for instructions."
49+
fi

0 commit comments

Comments
 (0)