Skip to content

Commit b765c62

Browse files
authored
Merge pull request #446 from input-output-hk/feature/dockerize_mantis
Dockerize Mantis
2 parents ad6040e + 1c36770 commit b765c62

13 files changed

+227
-0
lines changed

docker/Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
FROM mantis-dev:latest as CURRENTBUILD
3+
4+
ARG MANTIS_TAG
5+
ENV MANTIS_TAG ${MANTIS_TAG:-phase/iele_testnet}
6+
7+
# The command `sbt dist` generates a zip file in the `target/universal` directory.
8+
# The value of `MANTIS_DIST_ZIP_NAME` must be the name of the generated zip,
9+
# excluding the extension.
10+
# So, for example, currently (commit `35e06611`) the `sbt dist` command
11+
# produces `target/universal/mantis-1.0-daedalus-rc1.zip`, so we can set
12+
# `MANTIS_DIST_ZIP_NAME` to be `mantis-1.0-daedalus-rc1`.
13+
# A glob like `mantis-*` also works and is more convenient, since it is invariant
14+
# with respect to the other part, which dependens on the software version.
15+
ARG MANTIS_DIST_ZIP_NAME
16+
ENV MANTIS_DIST_ZIP_NAME ${MANTIS_DIST_ZIP_NAME:-mantis-*}
17+
18+
# Grab latest mantis, build the distribution and install it
19+
RUN ~/install-mantis.sh $MANTIS_TAG $MANTIS_DIST_ZIP_NAME
20+
# Now mantis is in /home/mantis/mantis-dist/app
21+
# or just /app
22+
23+
# Start over and keep what is needed.
24+
# Now the size optimization comes from `mantis-base`:
25+
# smaller `mantis-base` means smaller `mantis` image (this image).
26+
FROM mantis-base:latest
27+
28+
USER root
29+
COPY --from=CURRENTBUILD /home/mantis/mantis-dist /home/mantis/mantis-dist
30+
RUN chown -R mantis:mantis /home/mantis/mantis-dist
31+
32+
USER mantis
33+
WORKDIR /app
34+
VOLUME /app/conf

docker/Dockerfile-base

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM ubuntu:xenial
2+
3+
# This "base" image contains the base OS along with some extra programs.
4+
5+
# See the accompanying `build-base.sh` script for tagging details.
6+
7+
ENV DEBIAN_FRONTEND noninteractive
8+
9+
ADD scripts/install-base-system.sh /root/
10+
RUN /root/install-base-system.sh
11+
12+
ADD scripts/install-nix-common.sh /home/mantis/
13+
ADD scripts/install-nix-apps-base.sh /home/mantis/
14+
RUN chown mantis:mantis /home/mantis/install-*.sh
15+
16+
USER mantis
17+
WORKDIR /home/mantis
18+
ENV USER mantis
19+
20+
RUN ~/install-nix-apps-base.sh

docker/Dockerfile-dev

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM mantis-base:latest
2+
3+
# This "dev" image creates enough of a Mantis build environment,
4+
# so that the actual Mantis images can be built in less time.
5+
# We are particularly interested in caching the dependencies needed
6+
# during the build process. This means that whenever those change,
7+
# the "dev" image must be recreated.
8+
9+
# See the `Dockerfile-base` for the parent image details.
10+
# See the accompanying `build-dev.sh` script for tagging details.
11+
12+
ARG SBT_VERIFY_TAG
13+
ENV SBT_VERIFY_TAG ${SBT_VERIFY_TAG:-v0.4.1}
14+
15+
ARG MANTIS_TAG
16+
ENV MANTIS_TAG ${MANTIS_TAG:-phase/iele_testnet}
17+
18+
USER root
19+
20+
ADD scripts/install-nix-apps-dev.sh /home/mantis/
21+
ADD scripts/install-mantis-dev.sh /home/mantis/
22+
ADD scripts/install-mantis.sh /home/mantis/
23+
24+
RUN chown mantis:mantis /home/mantis/install-*.sh
25+
26+
USER mantis
27+
WORKDIR /home/mantis
28+
ENV USER mantis
29+
30+
RUN ~/install-nix-apps-dev.sh
31+
RUN ~/install-mantis-dev.sh $SBT_VERIFY_TAG $MANTIS_TAG

docker/build-base.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -eux
4+
5+
HERE=$(readlink -m $(dirname ${BASH_SOURCE[0]}))
6+
7+
exec $HERE/buildhelper.sh mantis-base Dockerfile-base latest

docker/build-dev.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -eux
4+
5+
HERE=$(readlink -m $(dirname ${BASH_SOURCE[0]}))
6+
7+
exec $HERE/buildhelper.sh mantis-dev Dockerfile-dev latest

docker/build.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -eux
4+
5+
HERE=$(readlink -m $(dirname ${BASH_SOURCE[0]}))
6+
7+
$HERE/buildhelper.sh mantis Dockerfile

docker/buildhelper.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
set -eux
4+
5+
HERE=$(readlink -m $(dirname ${BASH_SOURCE[0]}))
6+
7+
IMAGE_NAME=$1
8+
DOCKERFILE=$2
9+
10+
# If IMAGE_TAG is not given in the command line, then compute one in the format
11+
#
12+
# YYYY-MM-DD '.' SHORT_HASH
13+
#
14+
# where the variable parts refer to the latest commit
15+
IMAGE_TAG=${3:-$(git log -1 --format=%cd.%h --date=short)}
16+
17+
# This is the commit that the image will be based on
18+
GIT_HASH=$(git log -1 --format=%H)
19+
20+
docker build --build-arg MANTIS_TAG=$GIT_HASH -t $IMAGE_NAME:$IMAGE_TAG -f $HERE/$DOCKERFILE $HERE

docker/scripts/install-base-system.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
apt-get update
6+
apt-get dist-upgrade -y
7+
apt-get install -y curl bzip2 locales
8+
locale-gen en_US.UTF-8
9+
update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
10+
11+
adduser --disabled-password --gecos '' mantis
12+
13+
mkdir /nix
14+
chown mantis:mantis /nix
15+
su mantis -c 'curl https://nixos.org/nix/install | sh \
16+
&& tail -n 1 ~/.profile >> ~/.bashrc'
17+
ln -s /home/mantis/mantis-dist/app /app
18+
19+
apt-get purge -y curl bzip2
20+
apt-get clean -y
21+
rm -rf /var/cache/debconf/* /var/lib/apt/lists/* /var/log/* /tmp/* /var/tmp/*

docker/scripts/install-mantis-dev.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
SBT_VERIFY_TAG=$1
6+
MANTIS_TAG=$2
7+
8+
HERE=$(readlink -m $(dirname ${BASH_SOURCE[0]}))
9+
. $HERE/install-nix-common.sh
10+
11+
mkdir ~/repos
12+
13+
cd ~/repos
14+
git clone https://github.com/input-output-hk/sbt-verify.git
15+
cd sbt-verify
16+
git checkout $SBT_VERIFY_TAG
17+
# This is needed, since the library is not published in binary form.
18+
sbt publishLocal
19+
20+
cd ~/repos
21+
git clone https://github.com/input-output-hk/mantis.git
22+
cd mantis
23+
git checkout $MANTIS_TAG
24+
git submodule update --init
25+
26+
# Trigger compilation, so that we get some dependencies from the internetz.
27+
sbt 'set test in Test := {}' compile

docker/scripts/install-mantis.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
MANTIS_TAG=$1
6+
MANTIS_DIST_ZIP_NAME=$2
7+
8+
HERE=$(readlink -m $(dirname ${BASH_SOURCE[0]}))
9+
. $HERE/install-nix-common.sh
10+
11+
cd ~/repos/mantis
12+
13+
git checkout $MANTIS_TAG
14+
git submodule update --init
15+
16+
sbt 'set test in Test := {}' dist
17+
mkdir -p ~/mantis-dist/app
18+
unzip -d ~/mantis-dist/app target/universal/${MANTIS_DIST_ZIP_NAME}.zip
19+
mv ~/mantis-dist/app/*/* ~/mantis-dist/app
20+
rmdir ~/mantis-dist/app/$MANTIS_DIST_ZIP_NAME
21+
rm -rf ~/repos ~/.ivy2 ~/.sbt
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
HERE=$(readlink -m $(dirname ${BASH_SOURCE[0]}))
6+
. $HERE/install-nix-common.sh
7+
8+
nix-install openjdk
9+
nix-collect-garbage -d
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
HERE=$(readlink -m $(dirname ${BASH_SOURCE[0]}))
6+
. $HERE/install-nix-common.sh
7+
8+
nix-install sbt gitMinimal unzip
9+
nix-collect-garbage -d

docker/scripts/install-nix-common.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
NIX_PROFILE=~/.nix-profile/etc/profile.d/nix.sh
6+
7+
export MANPATH=
8+
. $NIX_PROFILE
9+
10+
export NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-18.03.tar.gz
11+
12+
function nix-install() {
13+
nix-env -f '<nixpkgs>' -iA "$@"
14+
}

0 commit comments

Comments
 (0)