Skip to content

Commit e5daaf3

Browse files
authored
Merge pull request #4 from VariantSync/experimental-virtualization
Experimental virtualization
2 parents d506ef5 + 5b8652c commit e5daaf3

5 files changed

Lines changed: 172 additions & 76 deletions

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"]

INSTALL.md

Lines changed: 83 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
# Setup Instructions
22

3-
You may run the demo manually, or by using Nix or Docker.
4-
The manual setup enables you to use DiffDetective in any of your own Maven projects.
5-
The Nix and Docker setups just build the demo for you to run it.
6-
Windows users should _not_ use the Nix setup except if they have experience with WSL2, XServers, and Nix (see [REQUIREMENTS.md](REQUIREMENTS.md)).
3+
You may build and run the demo _either_ manually _or_ by using Docker _or_ Nix.
74

8-
In case you encounter problems, you may have a look at the _Troubleshooting_ section at the bottom of this file.
5+
**The purpose of this demo is to serve as a template project for starting to develop with DiffDetective, as well as to give examples on how to use and integrate DiffDetective in your projects.
6+
We hence recommend the manual setup because it enables you to use DiffDetective in any of your own Maven projects.**
97

10-
## Manual Setup
8+
The Nix and Docker setups build the demo to a runnable jar file.
9+
We also provide scripts for running the Demo using Nix dependencies and inside Docker but we do not recommend the complete Docker setup because the demo launches a graphical user interface which frequently causes problems when inside of Docker (see Troubleshooting section at the bottom of this file).
10+
We hence recommend (1) to build either manually or with Nix or with Docker and (2) to run the produced jar file manually.
11+
(Windows users should _not_ use the Nix setup except if they are experts on WSL2, XServers, and Nix (see [REQUIREMENTS.md](REQUIREMENTS.md)).)
1112

12-
Check the requirements needed for the manual setup in the [REQUIREMENTS.md](REQUIREMENTS.md) file.
13+
Once you decided for a setup (Manual/Docker/Nix), check the requirements needed for the respective setup in the [REQUIREMENTS.md](REQUIREMENTS.md) file.
14+
15+
>In case you encounter problems during the setup, you may have a look at the _Troubleshooting_ section at the bottom of this file.
16+
17+
18+
## Manual Build
1319

1420
Follow the setup instructions on the [DiffDetective website](https://variantsync.github.io/DiffDetective/) for building and installing DiffDetective with Maven (and _not_ with Nix).
1521
These instructions make you clone the repo and install it.
@@ -30,19 +36,26 @@ To run the demo, invoke `java` on the jar file that includes any dependencies:
3036
java -jar target/diffdetectivedemo-1.0.0-jar-with-dependencies.jar
3137
```
3238
The expected output and behavior of the jar file is explained below in the section _Expected Output_.
39+
Make sure that you are at the top level of this repository in the terminal (i.e, the directory containing this INSTALL.md file).
3340

34-
## Docker Setup
41+
## Automatic Build
3542

36-
Check the requirements needed for the Docker setup in the [REQUIREMENTS.md](REQUIREMENTS.md) file.
43+
We provide two methods for automatically building this demo:
44+
- a [Docker](https://www.docker.com/get-started) build, and
45+
- a [Nix](https://nixos.org/download/) build.
46+
47+
### Starting the docker deamon
3748

38-
### Start the docker deamon
49+
If you want to use Docker to build the jar for you, Docker needs to be installed and running.
50+
Check the requirements needed for the Docker setup in the [REQUIREMENTS.md](REQUIREMENTS.md) file.
51+
You may also need to start the Docker daemon before any Docker commands can be run.
3952

4053
- **On Linux**: Typically, the docker deamon runs automatically, so there is nothing to do. Otherwise, run `sudo systemctl start docker`.
4154
- **On Windows**: Open the search bar using the 'Windows Key' and search for 'Docker' or 'Docker Desktop'.
4255

4356
More detailed instructions on starting the deamon are given [here](https://docs.docker.com/config/daemon/start/) on the docker website.
4457

45-
### Docker Setup on Windows
58+
### Docker Build on Windows
4659

4760
Open a terminal (preferably Windows PowerShell) and navigate to the repository's directory (the directory containing this `INSTALL.md`).
4861
Then, create the docker image
@@ -54,73 +67,80 @@ You can verify that the image was created successfully by running
5467
docker images
5568
```
5669
and checking that an image called `diffdetective-demo` is listed.
57-
You can run the image and thus the demo with the following command:
70+
71+
To extract the built jar you can run
5872
```shell
59-
docker run --net=host -e DISPLAY=host.docker.internal:0 --volume="$PWD/data/output:/home/user/data/output:rw" -t diffdetective-demo
73+
docker run --volume "${pwd}:/output:rw" diffdetective-demo:1.0.0 /bin/cp /DiffDetective/share/java/DiffDetective-Demo.jar /output
6074
```
61-
You may get some font errors, which you can ignore (see Troubleshooting below).
62-
The parameters `--net=host` and `-e DISPLAY=host.docker.internal:0` are required to launch graphical user interfaces from within Docker.
63-
64-
### Docker Setup on Linux
65-
66-
> You might require elevated privileges to execute Docker commands (e.g., `sudo ./docker.sh build` or adding the user to the `docker` or `wheel` group).
67-
> See Docker's [post-installation steps](https://docs.docker.com/engine/install/linux-postinstall/) for more information.
75+
and execute it using
76+
````shell
77+
java -jar DiffDetective-Demo.jar
78+
````
79+
80+
> **Experimental:**
81+
> Alternatively, You can run the image and thus the demo with the following command:
82+
> ```shell
83+
> docker run --net=host -e DISPLAY=host.docker.internal:0 --volume="$PWD/data/output:/home/user/data/output:rw" -t diffdetective-demo
84+
> ```
85+
> You may get some font errors, which you can ignore (see Troubleshooting below).
86+
> The parameters `--net=host` and `-e DISPLAY=host.docker.internal:0` are required to launch graphical user interfaces from within Docker.
87+
88+
### Nix or Docker Build on Linux
89+
90+
You can use the `build-jar.sh` script to build the Demo jar using [Nix](https://nixos.org/download/) or [Docker](https://www.docker.com/get-started).
91+
The `build-jar.sh` script will automatically choose the build method depending on the available software (Nix or Docker, in that order).
92+
You might require elevated privileges to execute Docker commands (e.g., `sudo ./build-jar.sh` or adding the user to the `docker` or `wheel` group).
93+
See Docker's [post-installation steps](https://docs.docker.com/engine/install/linux-postinstall/) for more information.
94+
Also, it is best to install required software (e.g., Nix, Docker) using your distro's package manager if it is available.
6895
69-
> It is best to install required software (e.g., Docker, Maven) using your distro's package manager if it is available.
70-
71-
You can use the `docker.sh` script to build and execute the Demo using [Docker](https://www.docker.com/get-started) as described below.
72-
73-
#### Setup
7496
Clone and navigate to this repository (the directory containing this `INSTALL.md`).
75-
Then, simply build the image using the provided script:
97+
Then, simply build the jar using the provided script:
7698
```shell
77-
./docker.sh build
99+
./build-jar.sh
78100
```
79101
80-
This will automatically build the Docker container using Nix if Nix is installed on your system.
102+
The jar can then be executed with
103+
````shell
104+
java -jar DiffDetective-Demo.jar
105+
````
81106
82-
#### Execution
83-
Once the image has been build, you can start the demo with
84-
```shell
85-
./docker.sh demo
86-
```
107+
### Complete Docker Setup on Linux
87108
88-
## Nix Setup
109+
> **Experimental:**
110+
> You can build and start a demo Docker container with
111+
> ```shell
112+
> ./docker.sh build
113+
> ./docker.sh demo
114+
> ```
89115
90-
Nix can be used to reproducibly build both, a standalone derivation and a docker container.
91-
Nix aids in reproducible builds whereas Docker aids in reproducible execution.
116+
### Nix Build
92117
118+
Nix can be used to reproducibly build this DiffDetective demo.
93119
To use Nix, you need to have [Nix](https://nixos.org/download/) installed on your system.
94-
See [REQUIREMENTS.md](REQUIREMENTS.md) for instructions on how to install Nix and optionally also Docker.
95-
96-
### Standalone Build
120+
See [REQUIREMENTS.md](REQUIREMENTS.md) for instructions on how to install Nix.
97121
98122
> Notice for Windows users:
99123
> You must run the following commands from within a WSL2 terminal.
100124
> Also, make sure to clone this repository to a directory within WSL and _not_ to a Windows directory.
101125
> Otherwise, the Nix setup might fail due to incompatibilities with the file system.
102-
> Moreover, if you would like to have access to the demo's GUI, you need an XServer installed (see [REQUIREMENTS.md](REQUIREMENTS.md)).
103126
104-
Clone and navigate to this repository.
105-
Then simply build and run the Demo using
127+
> Notice for Nix flake users:
128+
> If you have flakes enabled, you can just use `nix run github:VariantSync/DiffDetective-Demo` to run the demo instead of the following instructions.
129+
130+
Clone and navigate to this repository in a terminal.
131+
Then simply build the Demo with
106132
```shell
107133
nix-build
108-
./result/bin/DiffDetective-Demo
109134
```
110135
111-
If you have flakes enabled, you can instead just use
136+
Afterwards, the produced jar file is located at `result/share/java/DiffDetective-Demo.jar`.
137+
You can run it manually with Java (requires Java 17 or higher):
112138
```shell
113-
nix run github:VariantSync/DiffDetective-Demo
139+
java -jar result/share/java/DiffDetective-Demo.jar
114140
```
115-
116-
### Using a Docker Image
117-
118-
If you have Nix installed, the `docker.sh` script will automatically build this demo using Nix.
119-
Hence, the instructions are the same as for docker:
120-
Clone and navigate to this repository and execute the following:
141+
or alternatively with the provided wrapper script:
121142
```shell
122-
./docker.sh build
123-
./docker.sh demo
143+
./result/bin/DiffDetective-Demo
124144
```
125145
126146
@@ -205,3 +225,13 @@ To fix, start the docker daemon as it was probably not running.
205225
### Gtk-Message: 00:08:30.171: Failed to load module "colorreload-gtk-module"
206226
207227
This error can be savely ignore. The `colorreload-gtk-module` is used for theming and, hence, is not useful in this scenario.
228+
229+
### error: experimental Nix feature 'nix-command' is disabled; add '--extra-experimental-features nix-command' to enable it
230+
231+
You ran Nix flakes without having enabled it. Either enable it by adding the extra parameters to the call as indicated in the error message, or stick to the non-experimental nix commands as described above (recommended).
232+
233+
### Exception in thread "main" java.nio.file.NoSuchFileException: data/examples/simple_v1.txt
234+
235+
The demo could not find one of this input files.
236+
This likely happened because you ran the demo from a working directory that is not the top level of this repository in the terminal (i.e, the directory containing this INSTALL.md file).
237+
To fix, navigate to the root directory of this repository in your terminal and run the demo again.

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# DiffDetective-Demo
22

3-
A small demonstration of [DiffDetective](https://github.com/VariantSync/DiffDetective).
3+
This is a small demonstration of [DiffDetective](https://github.com/VariantSync/DiffDetective).
44
The purpose of this demo is to provide an example of how to use DiffDetective and to serve as a template project for you to clone and adapt as a quickstart for developing with DiffDetective.
55

66
There is a screencast available on YouTube, guiding you through the demo's setup with Maven in IntelliJ and how to implement variability-aware differencing and analyses of Git histories:
@@ -10,16 +10,14 @@ There is a screencast available on YouTube, guiding you through the demo's setup
1010
This demo, also manifests the artifact submission for our paper _Variability-Aware Differencing with DiffDetective_, accepted at the FSE'24 demonstrations track.
1111
A preprint of the paper is available as part of this repository, [here](Variability-Aware%20Differencing%20with%20DiffDetective.pdf).
1212
Our application for artifact badges can be found in the [STATUS.md](STATUS.md) file.
13+
Please note that this submission is _not_ a replication package of an empirical study (e.g., tool evaluation).
14+
Instead, this repository is a template project with examples for how to use DiffDetective as a library (i.e., a demo).
1315

1416
## Setup
1517

1618
The demo is a Java Maven project, which includes DiffDetective as a library.
17-
You may run the demo manually, or by using Nix or Docker.
18-
The manual setup enables you to use DiffDetective in any of your own Maven projects.
19-
The Nix and Docker setups just build the demo for you to run it.
2019

2120
Software requirements are documented in the [REQUIREMENTS.md](REQUIREMENTS.md) file (there are no specific hardware requirements).
2221
Basically, you will have to install Java and Maven, or alternatively Nix or Docker.
2322

2423
Installation instructions are documented in the [INSTALL.md](INSTALL.md) file.
25-

REQUIREMENTS.md

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,40 @@ None
44

55
## Software Requirements
66

7-
> This demo can be run with Docker or Nix. If you intend to use one of them, you may skip to the last section in this document.
8-
97
We do not require a certain operating system or prepared environment.
108
For downloading this demo, we recommend Git (installing Git is explained in [this article](https://github.com/git-guides/install-git)).
11-
The setup is tested on Windows 10, WSL2, Manjaro, Ubuntu, NixOS and MacOS Monterey.
9+
The setup is tested on Windows 10, WSL2, Manjaro, and NixOS.
10+
11+
**Executing the demo consists of two steps**: _building the project_ and _running the demo_.
12+
Each step has its own software requirements.
13+
14+
15+
### Requirements for Building
16+
17+
This demo can be built _either_ manually _or_ using Docker _or_ using Nix.
18+
You may choose one of these setups.
19+
If you intend to use this project to develop your own library or application based on DiffDetective, we recommend the manual build.
20+
21+
#### Requirements for Building Manually
1222

13-
### Toolchain
1423
This demo is a Maven project based on Java 17.
1524

1625
To build the demo, a [Java development toolkit](https://www.oracle.com/java/technologies/downloads/) of version 17 or higher, and [Maven](https://maven.apache.org/) are required.
1726

18-
To run the demo, graphviz should be installed. You may find installation instructions for graphviz [here](https://graphviz.org/download/).
19-
You may run the demo without graphviz but the demo will print an error to the terminal and DiffDetective cannot compute a layout for visualizing graphs.
20-
So the GUI may appear differently as in the screencast (see _Expected Output_ section in [INSTALL.md](INSTALL.md)).
21-
22-
### Java Dependencies
2327
The demo has few dependencies, most of which will be handled automatically by Maven.
2428
The dependencies are documented in the Maven build file ([pom.xml](pom.xml)).
2529
The only dependency that must be installed manually is our tool and library DiffDetective, which is also a Java Maven project.
2630
Installing DiffDetective follows the default maven workflow and is explained on the [DiffDetective website](https://variantsync.github.io/DiffDetective/) and README.
2731

28-
## Virtualization: Docker or Nix
29-
For easy replication, this demo also comes with a Nix package and a Docker container, which can be used on any system supporting Nix or Docker, respectively.
30-
The Nix and Docker setup will take care of all requirements and dependencies (including DiffDetective) and will build the demo to a single runnable JAR file.
31-
_Note_: Nix and Docker are neither required by the demo nor DiffDetective! They only serve to ease the setup for you.
32-
33-
### Docker
32+
#### Requirements for Building with Docker
3433

3534
How to install Docker depends on your operating system:
3635

3736
- _Windows or Mac_: You can find download and installation instructions [here](https://www.docker.com/get-started).
3837
- _Linux Distributions_: How to install Docker on your system, depends on your distribution. The chances are high that Docker is part of your distributions package database.
3938
Docker's [documentation](https://docs.docker.com/engine/install/) contains instructions for common distributions.
4039

41-
### Nix
40+
#### Requirements for Building with Nix
4241

4342
How to install Nix, also depends on your operating system.
4443
Head to the [NixOS website](https://nixos.org/download/) and follow the installation instructions for your system.
@@ -49,4 +48,17 @@ Instead, you can use Nix from within Windows Subsystem for Linux (WSL2).
4948
However, we do not recommend using Nix on Windows, except if you are already familiar with WSL2, Nix, and XServers.
5049
We recommend using Docker or a manual setup instead.
5150
Running the Demo from within WSL2 requires an XServer.
52-
We recommend [VcXsrv](https://sourceforge.net/projects/vcxsrv/).
51+
We recommend [VcXsrv](https://sourceforge.net/projects/vcxsrv/).
52+
53+
### Requirements for Running
54+
55+
To run the demo, a [Java development toolkit](https://www.oracle.com/java/technologies/downloads/) of version 17 or higher is required.
56+
57+
As an _optional_ dependency, running the demo uses graphviz.
58+
You may find installation instructions for graphviz [here](https://graphviz.org/download/).
59+
You may run the demo without graphviz, in which case the demo will print an error to the terminal and DiffDetective cannot compute a layout for visualizing graphs.
60+
In this case, the GUI may appear differently as in the screencast (see _Expected Output_ section in [INSTALL.md](INSTALL.md)).
61+
62+
> We also provide a nix and docker setup for running the demo, too. However, these setups are fragile because the demo launches a graphical user interface which may cause errors.
63+
> Hence, you can also run the demo without installing Java or graphviz.
64+
> We hence recommend to run the demo manually with Java.

build-jar.sh

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

0 commit comments

Comments
 (0)