diff --git a/docker/Dockerfile b/docker/Dockerfile index 1fae68921..ea23ddca6 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -11,7 +11,7 @@ COPY ./src ./src RUN ./build.bash -FROM jrei/systemd-ubuntu:20.04 +FROM ubuntu:20.04 RUN apt update && apt install -y \ dnsmasq iproute2 isc-dhcp-client \ @@ -31,19 +31,19 @@ COPY --from=gobuilder /minimega/bin/miniweb /opt/minimega/bin/miniweb COPY --from=gobuilder /minimega/bin/miniccc /opt/minimega/bin/miniccc COPY --from=gobuilder /minimega/bin/miniccc.exe /opt/minimega/bin/miniccc.exe -# For the sake of consistency, let's go ahead and include protonuke in the image -# too so we can easily grab a copy if/when necessary. +# For the sake of consistency, let's go ahead and include protonuke and +# minirouter in the image too so we can easily grab a copy if/when necessary. COPY --from=gobuilder /minimega/bin/protonuke /opt/minimega/bin/protonuke COPY --from=gobuilder /minimega/bin/protonuke.exe /opt/minimega/bin/protonuke.exe +COPY --from=gobuilder /minimega/bin/minirouter /opt/minimega/bin/minirouter COPY ./misc/web /opt/minimega/misc/web -ADD docker/minimega.service /etc/systemd/system/minimega.service -ADD docker/miniweb.service /etc/systemd/system/miniweb.service +COPY ./docker/start-minimega.sh /start-minimega.sh -WORKDIR /etc/systemd/system/multi-user.target.wants - -RUN ln -s ../minimega.service \ - && ln -s ../miniweb.service +RUN chmod +x /usr/local/bin/mm \ + && chmod +x /start-minimega.sh WORKDIR /opt/minimega + +CMD ["/start-minimega.sh"] diff --git a/docker/README.md b/docker/README.md index dd1f4985f..8351dd94f 100644 --- a/docker/README.md +++ b/docker/README.md @@ -8,9 +8,12 @@ ### Build the minimega docker image -> NOTE: Currently, only minimega, miniweb, miniccc, and protonuke will exist in the minimega docker image. If you need additional binaries, add them to the Dockerfile using the `COPY --from=gobuilder …` directive. +> NOTE: Currently, only minimega, miniweb, miniccc, and protonuke will exist in +> the minimega docker image. If you need additional binaries, add them to the +> Dockerfile using the `COPY --from=gobuilder …` directive. -> NOTE: The docker image needs to be built from the base directory of the minimega repository. +> NOTE: The docker image needs to be built from the base directory of the +> minimega repository. ```bash $ docker build -t minimega -f docker/Dockerfile . @@ -18,10 +21,12 @@ ### Start the minimega docker container -> NOTE: The additional privileges and system mounts (e.g. /dev) are required for the openvswitch process to run inside the container and to allow minimega to perform file injections. +> NOTE: The additional privileges and system mounts (e.g. /dev) are required for +> the openvswitch process to run inside the container and to allow minimega to +> perform file injections. ```bash -docker run -d -it \ +docker run -d \ --name minimega \ --hostname minimega \ --privileged \ @@ -33,11 +38,13 @@ docker run -d -it \ -v /dev:/dev \ -v /lib/modules:/lib/modules:ro \ -v /sys/fs/cgroup:/sys/fs/cgroup:ro \ - --health-cmd "minimega -e version" \ + --health-cmd "mm version" \ minimega ``` -The container runs systemd as PID 1, which takes care of starting openvswitch, minimega, and miniweb. +The container runs the `start-minimega.sh` script as PID 1, which takes care of +starting openvswitch, miniweb, and finally minimega. This means the minimega +logs will be available in the container logs via Docker. --- @@ -75,3 +82,25 @@ $ source ~/.bash_aliases miniweb gets started in the container automatically. +### minimega configuration + +By default, the following values are set for minimega: + +``` +MM_BASE=/tmp/minimega +MM_FILEPATH=/tmp/minimega/files +MM_BROADCAST=255.255.255.255 +MM_PORT=9000 +MM_DEGREE=2 +MM_CONTEXT=minimega +MM_LOGLEVEL=info +MM_LOGFILE=/var/log/minimega.log +``` + +These values can be overwritten either by passing environment variables to +Docker when starting the container or by binding a file to +`/etc/default/minimega` in the container that contains updated values. + +> NOTE: If a value is specified both as an environment variable to Docker and in +> the file bound to `/etc/default/minimega`, the value in +> `/etc/default/minimega` will be used. diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index a05bc2a3c..567ce8bf4 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,6 +1,9 @@ version: '3.7' services: minimega: + build: + context: ../ + dockerfile: docker/Dockerfile image: minimega container_name: minimega hostname: minimega @@ -19,10 +22,9 @@ services: volumes: - /dev:/dev - /lib/modules:/lib/modules:ro - - /sys/fs/cgroup:/sys/fs/cgroup:ro - /etc/localtime:/etc/localtime:ro - /tmp/minimega:/tmp/minimega - /var/log/minimega:/var/log/minimega - - /root/.ssh:/root/.ssh:ro + - /phenix:/phenix healthcheck: - test: minimega -e version + test: mm version diff --git a/docker/minimega.service b/docker/minimega.service deleted file mode 100644 index 4d54558c5..000000000 --- a/docker/minimega.service +++ /dev/null @@ -1,30 +0,0 @@ -[Unit] -Description=minimega Service -After=multi-user.target - -[Service] -Environment="MM_BASE=/tmp/minimega" -Environment="MM_FILEPATH=/tmp/minimega/files" -Environment="MM_BROADCAST=255.255.255.255" -Environment="MM_PORT=9000" -Environment="MM_DEGREE=2" -Environment="MM_CONTEXT=minimega" -Environment="MM_LOGLEVEL=info" -Environment="MM_LOGFILE=/var/log/minimega.log" -EnvironmentFile=-/etc/default/minimega -ExecStart=/opt/minimega/bin/minimega \ - -force \ - -nostdin \ - -base=${MM_BASE} \ - -filepath=${MM_FILEPATH} \ - -broadcast=${MM_BROADCAST} \ - -port=${MM_PORT} \ - -degree=${MM_DEGREE} \ - -context=${MM_CONTEXT} \ - -level=${MM_LOGLEVEL} \ - -logfile=${MM_LOGFILE} -Restart=always -RestartSec=3 - -[Install] -WantedBy=multi-user.target diff --git a/docker/miniweb.service b/docker/miniweb.service deleted file mode 100644 index af7ee15b6..000000000 --- a/docker/miniweb.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=miniweb Service -After=multi-user.target - -[Service] -ExecStart=/opt/minimega/bin/miniweb -addr=0.0.0.0:9001 -root=/opt/minimega/misc/web -WorkingDirectory=/opt/minimega -Restart=always -RestartSec=3 - -[Install] -WantedBy=multi-user.target diff --git a/docker/start-minimega.sh b/docker/start-minimega.sh new file mode 100644 index 000000000..f7c925c6f --- /dev/null +++ b/docker/start-minimega.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +/usr/share/openvswitch/scripts/ovs-ctl start + +/opt/minimega/bin/miniweb -root=/opt/minimega/misc/web -addr=0.0.0.0:9001 & + +: "${MM_BASE:=/tmp/minimega}" +: "${MM_FILEPATH:=/tmp/minimega/files}" +: "${MM_BROADCAST:=255.255.255.255}" +: "${MM_PORT:=9000}" +: "${MM_DEGREE:=2}" +: "${MM_CONTEXT:=minimega}" +: "${MM_LOGLEVEL:=info}" +: "${MM_LOGFILE:=/var/log/minimega.log}" + +[[ -f "/etc/default/minimega" ]] && source "/etc/default/minimega" + +/opt/minimega/bin/minimega \ + -force \ + -nostdin \ + -base=${MM_BASE} \ + -filepath=${MM_FILEPATH} \ + -broadcast=${MM_BROADCAST} \ + -port=${MM_PORT} \ + -degree=${MM_DEGREE} \ + -context=${MM_CONTEXT} \ + -level=${MM_LOGLEVEL} \ + -logfile=${MM_LOGFILE}