diff --git a/docker/Dockerfile.arm64 b/docker/Dockerfile.arm64 new file mode 100644 index 0000000..34e11c2 --- /dev/null +++ b/docker/Dockerfile.arm64 @@ -0,0 +1,144 @@ +FROM ubuntu:jammy + +# set environment variables for tzdata +ARG TZ=America/New_York +ENV TZ=${TZ} + +# include manual pages and documentation +ARG DEBIAN_FRONTEND=noninteractive +RUN apt-get update &&\ + yes | unminimize + +# copy new sources.list +COPY --chown=root:root sources.list /etc/apt/sources.list + +# include multiarch support +RUN apt-get -y install binfmt-support &&\ + dpkg --add-architecture amd64 &&\ + apt-get update &&\ + apt-get upgrade + +# install GCC-related packages +RUN apt-get -y install\ + binutils-doc\ + cpp-doc\ + gcc-doc\ + g++\ + gdb\ + gdb-doc\ + glibc-doc\ + libblas-dev\ + liblapack-dev\ + liblapack-doc\ + libstdc++-12-doc\ + make\ + make-doc + +# install clang-related packages +RUN apt-get -y install\ + clang\ + clang-14-doc\ + lldb + +# install qemu for WeensyOS (sadly, this pulls in a lot of crap) +RUN apt-get -y install\ + qemu-system-x86 + +# install programs used for system exploration +RUN apt-get -y install\ + blktrace\ + linux-tools-generic\ + strace\ + tcpdump + +# install interactive programs (emacs, vim, nano, man, sudo, etc.) +RUN apt-get -y install\ + bc\ + curl\ + dc\ + emacs-nox\ + git\ + git-doc\ + man\ + micro\ + nano\ + psmisc\ + sudo\ + vim\ + wget + +# set up libraries +RUN apt-get -y install\ + libreadline-dev\ + locales\ + wamerican + +# install programs used for networking +RUN apt-get -y install\ + dnsutils\ + inetutils-ping\ + iproute2\ + net-tools\ + netcat\ + telnet\ + time\ + traceroute + +# install GCC-related packages for amd64 +RUN apt-get -y install\ + g++-11-x86-64-linux-gnu\ + gdb-multiarch\ + libc6:amd64\ + libstdc++6:amd64\ + libasan5:amd64\ + libtsan0:amd64\ + libubsan1:amd64\ + libreadline-dev:amd64\ + libblas-dev:amd64\ + liblapack-dev:amd64\ + qemu-user + +# link x86-64 versions of common tools into /usr/x86_64-linux-gnu/bin +RUN for i in addr2line c++filt cpp-11 g++-11 gcc-11 gcov-11 gcov-dump-11 gcov-tool-11 size strings; do \ + ln -s /usr/bin/x86_64-linux-gnu-$i /usr/x86_64-linux-gnu/bin/$i; done && \ + ln -s /usr/bin/x86_64-linux-gnu-cpp-11 /usr/x86_64-linux-gnu/bin/cpp && \ + ln -s /usr/bin/x86_64-linux-gnu-g++-11 /usr/x86_64-linux-gnu/bin/c++ && \ + ln -s /usr/bin/x86_64-linux-gnu-g++-11 /usr/x86_64-linux-gnu/bin/g++ && \ + ln -s /usr/bin/x86_64-linux-gnu-gcc-11 /usr/x86_64-linux-gnu/bin/gcc && \ + ln -s /usr/bin/x86_64-linux-gnu-gcc-11 /usr/x86_64-linux-gnu/bin/cc && \ + ln -s /usr/bin/gdb-multiarch /usr/x86_64-linux-gnu/bin/gdb + +# set up default locale +RUN locale-gen en_US.UTF-8 +ENV LANG en_US.UTF-8 + +# remove unneeded .deb files +RUN rm -r /var/lib/apt/lists/* + +# set up passwordless sudo for user masstree-dev +RUN useradd -m -s /bin/bash masstree-dev && \ + echo "masstree-dev ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/masstree-init + +# create binary reporting version of dockerfile +RUN (echo '#\!/bin/sh'; echo 'if test "x$1" = x-n; then echo 13; else echo 13.arm64; fi') > /usr/bin/masstree-docker-version; chmod ugo+rx,u+w,go-w /usr/bin/masstree-docker-version + +# git build arguments +ARG USER=Masstree\ Dev +ARG EMAIL=nobody@example.com + +# configure your environment +USER masstree-dev +RUN git config --global user.name "${USER}" && \ + git config --global user.email "${EMAIL}" && \ + (echo "(custom-set-variables"; echo " '(c-basic-offset 4)"; echo " '(indent-tabs-mode nil))") > ~/.emacs && \ + (echo "set expandtab"; echo "set shiftwidth=4"; echo "set softtabstop=4") > ~/.vimrc && \ + (echo "if test -f /run/host-services/ssh-auth.sock; then"; echo " sudo chown masstree-dev:masstree-dev /run/host-services/ssh-auth.sock"; echo "fi") > ~/.bash_profile && \ + echo ". ~/.bashrc" >> ~/.bash_profile && \ + echo "export PATH=/usr/x86_64-linux-gnu/bin:\$PATH" >> ~/.bashrc && \ + rm -f ~/.bash_logout && \ + echo "add-auto-load-safe-path ~" > ~/.gdbinit + +WORKDIR /home/masstree-dev +CMD ["/bin/bash", "-l"] + +# Initial version of this Dockerfile based off of the one used for CS 61 and CS 161 at Harvard diff --git a/docker/build-docker b/docker/build-docker new file mode 100755 index 0000000..cf38b88 --- /dev/null +++ b/docker/build-docker @@ -0,0 +1,44 @@ +#! /bin/bash + +cd `dirname $0` + +arch="`arch`" +tag= +platform= +while test "$#" -ne 0; do + if test "$1" = "-a" -o "$1" = "--arm" -o "$1" = "--arm64"; then + if test "`arch`" = "arm64" -o "`arch`" = "aarch64"; then + platform=linux/arm64 + shift + else + echo "\`build-docker --arm\` only works on ARM64 hosts" 1>&2 + exit 1 + fi + elif test "$1" = "-x" -o "$1" = "--x86-64" -o "$1" = "--x86_64" -o "$1" = "--amd64"; then + platform=linux/amd64 + shift + else + armtext= + if test "`arch`" = "arm64" -o "`arch`" = "aarch64"; then + armtext=" [-a|--arm] [-x|--x86-64]" + fi + echo "Usage: build-docker$armtext" 1>&2 + exit 1 + fi +done +if test -z "$platform" -a \( "$arch" = "arm64" -o "$arch" = "aarch64" \); then + platform=linux/arm64 +elif test -z "$platform"; then + platform=linux/amd64 +fi +if test -z "$tag" -a "$platform" = linux/arm64; then + tag=masstree:arm64 +elif test -z "$tag"; then + tag=masstree:latest +fi + +if test $platform = linux/arm64; then + exec docker build -t "$tag" -f Dockerfile.arm64 --platform linux/arm64 . +else + exec docker build -t "$tag" -f Dockerfile --platform linux/amd64 . +fi diff --git a/docker/sources.list b/docker/sources.list new file mode 100644 index 0000000..c727813 --- /dev/null +++ b/docker/sources.list @@ -0,0 +1,20 @@ +deb [ arch=arm64 ] http://ports.ubuntu.com/ubuntu-ports/ jammy main restricted +deb [ arch=arm64 ] http://ports.ubuntu.com/ubuntu-ports/ jammy-updates main restricted +deb [ arch=arm64 ] http://ports.ubuntu.com/ubuntu-ports/ jammy universe +deb [ arch=arm64 ] http://ports.ubuntu.com/ubuntu-ports/ jammy-updates universe +deb [ arch=arm64 ] http://ports.ubuntu.com/ubuntu-ports/ jammy multiverse +deb [ arch=arm64 ] http://ports.ubuntu.com/ubuntu-ports/ jammy-updates multiverse +deb [ arch=arm64 ] http://ports.ubuntu.com/ubuntu-ports/ jammy-backports main restricted universe multiverse +deb [ arch=arm64 ] http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted +deb [ arch=arm64 ] http://ports.ubuntu.com/ubuntu-ports/ jammy-security universe +deb [ arch=arm64 ] http://ports.ubuntu.com/ubuntu-ports/ jammy-security multiverse +deb [ arch=amd64 ] http://archive.ubuntu.com/ubuntu/ jammy main restricted +deb [ arch=amd64 ] http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted +deb [ arch=amd64 ] http://archive.ubuntu.com/ubuntu/ jammy universe +deb [ arch=amd64 ] http://archive.ubuntu.com/ubuntu/ jammy-updates universe +deb [ arch=amd64 ] http://archive.ubuntu.com/ubuntu/ jammy multiverse +deb [ arch=amd64 ] http://archive.ubuntu.com/ubuntu/ jammy-updates multiverse +deb [ arch=amd64 ] http://archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse +deb [ arch=amd64 ] http://security.ubuntu.com/ubuntu/ jammy-security main restricted +deb [ arch=amd64 ] http://security.ubuntu.com/ubuntu/ jammy-security universe +deb [ arch=amd64 ] http://security.ubuntu.com/ubuntu/ jammy-security multiverse diff --git a/run-docker b/run-docker new file mode 100755 index 0000000..ae219cf --- /dev/null +++ b/run-docker @@ -0,0 +1,122 @@ +#! /bin/bash + +maindir="" +destdir=masstree + +fresh= +verbose=false +arch="`arch`" +tag= +platform= +while test "$#" -ne 0; do + if test "$1" = "-f" -o "$1" = "--fresh"; then + fresh=1 + shift + elif test "$1" = "-V" -o "$1" = "--verbose"; then + verbose=true + shift + elif test "$1" = "-a" -o "$1" = "--arm" -o "$1" = "--arm64"; then + if test "$arch" = "arm64" -o "$arch" = "aarch64"; then + platform=linux/arm64 + shift + else + echo "\`run-docker --arm\` only works on ARM64 hosts" 1>&2 + exit 1 + fi + elif test "$1" = "-x" -o "$1" = "--x86-64" -o "$1" = "--x86_64" -o "$1" = "--amd64"; then + platform=linux/amd64 + shift + else + armtext= + if test "$arch" = "arm64" -o "$arch" = "aarch64"; then + armtext=" [-a|--arm] [-x|--x86-64]" + fi + echo "Usage: run-docker [-f|--fresh]$armtext [-V|--verbose]" 1>&2 + exit 1 + fi +done +if test -z "$platform" -a \( "$arch" = "arm64" -o "$arch" = "aarch64" \); then + platform=linux/arm64 +elif test -z "$platform"; then + platform=linux/amd64 +fi +if test -z "$tag" -a "$platform" = linux/arm64; then + tag=masstree:arm64 +elif test -z "$tag"; then + tag=masstree:latest +fi + + +vexec () { + if $verbose; then + echo "$@" + fi + exec "$@" +} + +if stat --format %i / >/dev/null 2>&1; then + statformatarg="--format" +else + statformatarg="-f" +fi +myfileid=`stat $statformatarg %d:%i "${BASH_SOURCE[0]}" 2>/dev/null` + +dir="`pwd`" +subdir="" +while test "$dir" != / -a "$dir" != ""; do + thisfileid=`stat $statformatarg %d:%i "$dir"/run-docker 2>/dev/null` + if test -n "$thisfileid" -a "$thisfileid" = "$myfileid"; then + maindir="$dir" + break + fi + subdir="/`basename "$dir"`$subdir" + dir="`dirname "$dir"`" +done + +if test -z "$maindir" && expr "${BASH_SOURCE[0]}" : / >/dev/null 2>&1; then + maindir="`dirname "${BASH_SOURCE[0]}"`" + subdir="" +fi + +ssharg= +sshenvarg= +if test -n "$SSH_AUTH_SOCK" -a "`uname`" = Darwin; then + ssharg=" --mount type=bind,src=/run/host-services/ssh-auth.sock,target=/run/host-services/ssh-auth.sock" + sshenvarg=" -e SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock" +fi + +if test -n "$maindir" -a -z "$fresh"; then + existing_image="`docker ps -f status=running -f ancestor=$tag -f volume=/host_mnt"$maindir" --no-trunc --format "{{.CreatedAt}},{{.ID}}" | sort -r | head -n 1`" + if test -n "$existing_image"; then + created_at="`echo $existing_image | sed 's/,.*//'`" + image="`echo $existing_image | sed 's/^.*,//'`" + image12="`echo $image | head -c 12`" + echo "* Using running container $image12, created $created_at" 1>&2 + echo "- To start a new container, exit then \`run-docker -f\`" 1>&2 + echo "- To kill this container, exit then \`docker kill $image12\`" 1>&2 + vexec docker exec -it$sshenvarg $image /bin/bash + fi +fi + +netarg= +if test `uname` = Darwin; then + if ! netstat -n -a -p tcp | grep '\.6169[ ].*LISTEN' >/dev/null; then + netarg="$netarg "'--expose=6169/tcp -p 6169:6169/tcp' + fi + if ! netstat -n -a -p tcp | grep '\.12949[ ].*LISTEN' >/dev/null; then + netarg="$netarg "'--expose=12949/tcp -p 12949:12949/tcp' + fi +elif test -x /bin/netstat; then + if ! netstat -n -a -p tcp | grep '\.6169[ ].*LISTEN' >/dev/null; then + netarg="$netarg "'--expose=6169/tcp -p 6169:6169/tcp' + fi + if ! netstat -n -l -t | grep ':12949[ ]' >/dev/null; then + netarg="$netarg "'--expose=12949/tcp -p 12949:12949/tcp' + fi +fi + +if test -n "$maindir"; then + vexec docker run -it --platform $platform --rm --privileged --cap-add=SYS_PTRACE --cap-add=NET_ADMIN --security-opt seccomp=unconfined -v "$maindir":/home/masstree-user/$destdir$ssharg -w "/home/masstree-user/$destdir$subdir" $netarg$sshenvarg $tag +else + vexec docker run -it --platform $platform --rm --privileged --cap-add=SYS_PTRACE --cap-add=NET_ADMIN --security-opt seccomp=unconfined $netarg$sshenvarg $tag +fi