浏览代码

Docker quality of life improvements (#3615)

* merge conflicts

* add run command to readme

* keep apt commands consistent
Nate 7 年之前
父节点
当前提交
7ddc421647

+ 1 - 1
.gitattributes

@@ -1,2 +1,2 @@
 # Docker relies on lf in bash scripts - force it
-*.sh text eol=lf
+*.sh text eol=lf

+ 3 - 3
Dockerfile

@@ -2,10 +2,10 @@ FROM ubuntu:16.04
 
 # One -q produces output suitable for logging (mostly hides
 # progress indicators)
-RUN apt-get -yq update
+RUN apt update -yqq
 
 # WARNING: DONT PUT A SPACE AFTER ANY BACKSLASH OR APT WILL BREAK
-RUN apt-get -qqy install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \
+RUN apt -qqy install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \
   git-core \
   cloc dstat                    `# Collect resource usage statistics` \
   python-dev \
@@ -19,4 +19,4 @@ RUN pip install colorama==0.3.1 requests MySQL-python psycopg2-binary pymongo do
 ENV PYTHONPATH /FrameworkBenchmarks
 ENV FWROOT /FrameworkBenchmarks
 
-ENTRYPOINT ["python", "/FrameworkBenchmarks/toolset/run-tests.py"]
+ENTRYPOINT ["python", "/FrameworkBenchmarks/toolset/run-tests.py"]

+ 10 - 24
README.md

@@ -22,36 +22,22 @@ To get started developing you'll need to install [docker](https://docs.docker.co
 
         $ git clone https://github.com/TechEmpower/FrameworkBenchmarks.git
 
-2. Create the TFB Docker virtual network
+2. Run a test.
 
-        $ docker network create tfb
+        $ ./tfb --mode verify --test gemini
 
-3. Run a test.
+### Explanation of the `./tfb` script
 
-        $ docker run -it --network=tfb -v /var/run/docker.sock:/var/run/docker.sock --mount type=bind,source=[ABS PATH TO THIS DIR],target=/FrameworkBenchmarks techempower/tfb --mode verify --test gemini
+The run script is pretty wordy, but each and every flag is required. If you are using windows, either adapt the docker command at the end of the `./tfb` shell script (replacing `${SCRIPT_ROOT}` with `/c/path/to/FrameworkBenchmarks`), or use vagrant.
 
-### Explanation of the run script
-
-That run script is pretty wordy, but each and every flag is required. Unfortunately, because of the way that Docker runs processes, you **cannot** put this inside of a shell script without breaking how `ctrl+c` and `SIGTERM` work (the shell script would receive the signal, do nothing with the underlying python suite running, and exit, orphaning the toolset to continue running).
+The command looks like this: `docker run -it --rm --network tfb -v /var/run/docker.sock:/var/run/docker.sock -v [FWROOT]:/FrameworkBenchmarks techempower/tfb [ARGS]`
 
 - `-it` tells docker to run this in 'interactive' mode and simulate a TTY, so that `ctrl+c` is propagated.
+- `--rm` tells docker to remove the container as soon as the toolset finishes running, meaning there aren't hundreds of stopped containers lying around.
 - `--network=tfb` tells the container to join the 'tfb' Docker virtual network
-- `-v` specifies which Docker socket path to mount as a volume in the running container. This allows docker commands run inside this container to use the host container's docker to create/run/stop/remove containers.
-- `--mount` mounts the FrameworkBenchmarks source directory as a volume to share with the container so that rebuilding the toolset image is unnecessary and any changes you make on the host system are available in the running toolset container.
+- The first `-v` specifies which Docker socket path to mount as a volume in the running container. This allows docker commands run inside this container to use the host container's docker to create/run/stop/remove containers.
+- The second `-v` mounts the FrameworkBenchmarks source directory as a volume to share with the container so that rebuilding the toolset image is unnecessary and any changes you make on the host system are available in the running toolset container.
 - `techempower/tfb` is the name of toolset container to run
-- `--mode verify --test gemini` are the command to pass to the toolset.
-
-#### A note on Linux:
-
-You may not want to call step 4 from above every time. You can add an `alias` to your `~/.bash_aliases` file to shorten it since it will not change once configured:
-
-`$ alias tfb="docker network create tfb > /dev/null 2>&1; docker run -it --network=tfb -v /var/run/docker.sock:/var/run/docker.sock --mount type=bind,source=[ABS PATH TO THIS DIR],target=/FrameworkBenchmarks techempower/tfb"`
-
-`$ source ~/.bash_aliases`
-
-Now you can run the toolset via `tfb`:
-
-`$ tfb --mode verify --test gemini`
 
 #### A note on Windows:
 
@@ -84,9 +70,9 @@ required.
 
 ## Add a New Test
 
-Once you open an SSH connection to your vagrant box, start the new test initialization wizard.
+Either on your computer, or once you open an SSH connection to your vagrant box, start the new test initialization wizard.
 
-        vagrant@TFB-all:~/FrameworkBenchmarks$ tfb --new
+        vagrant@TFB-all:~/FrameworkBenchmarks$ ./tfb --new
 
 This will walk you through the entire process of creating a new test to include in the suite.
 

+ 1 - 2
deployment/vagrant/bootstrap.sh

@@ -39,10 +39,9 @@ Welcome to the FrameworkBenchmarks project!
 EOF
 
   cat <<EOF > /home/vagrant/.bash_aliases
-alias tfb="docker network create tfb > /dev/null 2>&1; docker run -it --network=tfb -v /var/run/docker.sock:/var/run/docker.sock --mount type=bind,source=/home/vagrant/FrameworkBenchmarks,target=/FrameworkBenchmarks techempower/tfb"
+alias tfb="/home/vagrant/FrameworkBenchmarks/tfb"
 EOF
 
   sudo mv motd /etc/
   sudo chmod 777 /var/run/docker.sock
-  docker network create tfb
 fi

+ 2 - 6
deployment/vagrant/core.rb

@@ -21,9 +21,7 @@ def provider_libvirt(config)
     virt.memory = ENV.fetch('TFB_KVM_MEM', 3022)
     virt.cpus = ENV.fetch('TFB_KVM_CPU', 2)
 
-    override.vm.synced_folder "../../toolset", "/home/vagrant/FrameworkBenchmarks/toolset", type: "nfs", nfs_udp: false
-    override.vm.synced_folder "../../frameworks", "/home/vagrant/FrameworkBenchmarks/frameworks", type: "nfs", nfs_udp: false
-    override.vm.synced_folder "../../results", "/home/vagrant/FrameworkBenchmarks/results", type: "nfs", nfs_udp: false, create: true
+    override.vm.synced_folder "../..", "/home/vagrant/FrameworkBenchmarks", type: "nfs", nfs_udp: false
   end
 end
 
@@ -55,8 +53,6 @@ def provider_virtualbox(config)
     # See mitchellh/vagrant#4997
     # See http://superuser.com/a/640028/136050
 
-    override.vm.synced_folder "../../toolset", "/home/vagrant/FrameworkBenchmarks/toolset"
-    override.vm.synced_folder "../../frameworks", "/home/vagrant/FrameworkBenchmarks/frameworks"
-    override.vm.synced_folder "../../results", "/home/vagrant/FrameworkBenchmarks/results", create: true
+    override.vm.synced_folder "../..", "/home/vagrant/FrameworkBenchmarks"
   end
 end

+ 1 - 1
frameworks/C++/silicon/silicon.dockerfile

@@ -4,7 +4,7 @@ RUN apt update -yqq && apt install -yqq software-properties-common unzip cmake
 
 RUN add-apt-repository -s "deb http://apt.llvm.org/`lsb_release -cs`/ llvm-toolchain-`lsb_release -cs`-3.9 main"
 RUN wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key| apt-key add -
-RUN apt -yq update
+RUN apt update -yqq
 RUN apt install -yqq clang-3.9 lldb-3.9
 
 ENV MICROHTTPD_VERSION=0.9.39

+ 1 - 1
frameworks/C++/ulib/ulib-json.dockerfile

@@ -23,7 +23,7 @@ ENV LC_ALL en_US.UTF-8
 ENV DEBIAN_FRONTEND noninteractive
 
 RUN add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
-    apt-get -yq update && \
+    apt update -yqq && \
     apt install -yqq gcc-6 g++-6
 
 ENV IROOT=/install

+ 1 - 1
frameworks/C++/ulib/ulib-json_fit.dockerfile

@@ -23,7 +23,7 @@ ENV LC_ALL en_US.UTF-8
 ENV DEBIAN_FRONTEND noninteractive
 
 RUN add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
-    apt-get -yq update && \
+    apt update -yqq && \
     apt install -yqq gcc-6 g++-6
 
 ENV IROOT=/install

+ 1 - 1
frameworks/C++/ulib/ulib-mongodb.dockerfile

@@ -23,7 +23,7 @@ ENV LC_ALL en_US.UTF-8
 ENV DEBIAN_FRONTEND noninteractive
 
 RUN add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
-    apt-get -yq update && \
+    apt update -yqq && \
     apt install -yqq gcc-6 g++-6
 
 ENV IROOT=/install

+ 1 - 1
frameworks/C++/ulib/ulib-mysql.dockerfile

@@ -23,7 +23,7 @@ ENV LC_ALL en_US.UTF-8
 ENV DEBIAN_FRONTEND noninteractive
 
 RUN add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
-    apt-get -yq update && \
+    apt update -yqq && \
     apt install -yqq gcc-6 g++-6
 
 ENV IROOT=/install

+ 1 - 1
frameworks/C++/ulib/ulib-plaintext_fit.dockerfile

@@ -23,7 +23,7 @@ ENV LC_ALL en_US.UTF-8
 ENV DEBIAN_FRONTEND noninteractive
 
 RUN add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
-    apt-get -yq update && \
+    apt update -yqq && \
     apt install -yqq gcc-6 g++-6
 
 ENV IROOT=/install

+ 1 - 1
frameworks/C++/ulib/ulib-postgres.dockerfile

@@ -23,7 +23,7 @@ ENV LC_ALL en_US.UTF-8
 ENV DEBIAN_FRONTEND noninteractive
 
 RUN add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
-    apt-get -yq update && \
+    apt update -yqq && \
     apt install -yqq gcc-6 g++-6
 
 ENV IROOT=/install

+ 1 - 1
frameworks/C++/ulib/ulib-postgres_fit.dockerfile

@@ -23,7 +23,7 @@ ENV LC_ALL en_US.UTF-8
 ENV DEBIAN_FRONTEND noninteractive
 
 RUN add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
-    apt-get -yq update && \
+    apt update -yqq && \
     apt install -yqq gcc-6 g++-6
 
 ENV IROOT=/install

+ 1 - 1
frameworks/C++/ulib/ulib.dockerfile

@@ -23,7 +23,7 @@ ENV LC_ALL en_US.UTF-8
 ENV DEBIAN_FRONTEND noninteractive
 
 RUN add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
-    apt-get -yq update && \
+    apt update -yqq && \
     apt install -yqq gcc-6 g++-6
 
 ENV IROOT=/install

+ 1 - 1
frameworks/C++/wt/wt-postgres.dockerfile

@@ -3,7 +3,7 @@ FROM buildpack-deps:xenial
 RUN apt update -yqq && apt install -yqq software-properties-common unzip cmake
 
 RUN add-apt-repository ppa:ubuntu-toolchain-r/test -y
-RUN apt-get -yq update
+RUN apt update -yqq
 RUN apt install -yqq gcc-6 g++-6
 
 ENV WT_VERSION 4.0.2

+ 1 - 1
frameworks/C++/wt/wt.dockerfile

@@ -3,7 +3,7 @@ FROM buildpack-deps:xenial
 RUN apt update -yqq && apt install -yqq software-properties-common unzip cmake
 
 RUN add-apt-repository ppa:ubuntu-toolchain-r/test -y
-RUN apt-get -yq update
+RUN apt update -yqq
 RUN apt install -yqq gcc-6 g++-6
 
 ENV WT_VERSION 4.0.2

+ 1 - 1
frameworks/Clojure/macchiato/macchiato.dockerfile

@@ -5,6 +5,6 @@ COPY src src
 COPY project.clj project.clj
 ENV NODE_ENV=production
 RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
-RUN apt install -y nodejs
+RUN apt install -yqq nodejs
 RUN lein package
 CMD ["node", "target/release/hello.js"]

+ 1 - 1
frameworks/Crystal/amber/amber.dockerfile

@@ -11,7 +11,7 @@ ENV GC_MARKERS 1
 ENV AMBER_ENV production
 ENV DATABASE_URL postgres://benchmarkdbuser:benchmarkdbpass@tfb-database:5432/hello_world
 
-RUN apt install -y libyaml-dev
+RUN apt install -yqq libyaml-dev
 RUN shards build amber --release --no-debug
 
 CMD bash run.sh

+ 1 - 1
frameworks/Java/play1/play1.dockerfile

@@ -6,5 +6,5 @@ COPY public public
 COPY test test
 RUN wget -nv https://downloads.typesafe.com/play/1.5.0/play-1.5.0.zip
 RUN unzip -q play-1.5.0.zip
-RUN apt install -y python
+RUN apt install -yqq python
 CMD ["play-1.5.0/play", "run", "--%prod"]

+ 1 - 1
frameworks/Java/revenj-jvm/revenj-jvm.dockerfile

@@ -7,7 +7,7 @@ COPY web.xml web.xml
 RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
 RUN echo "deb http://download.mono-project.com/repo/debian wheezy main" | tee /etc/apt/sources.list.d/mono-xamarin.list
 RUN apt update
-RUN apt install -y mono-complete mono-fastcgi-server
+RUN apt install -yqq mono-complete mono-fastcgi-server
 
 RUN wget -q https://github.com/ngs-doo/revenj/releases/download/1.4.2/dsl-compiler.zip
 RUN unzip -o dsl-compiler.zip

+ 1 - 1
frameworks/JavaScript/nodejs/mitol.dockerfile

@@ -2,7 +2,7 @@ FROM node:9.10.1
 
 COPY ./ ./
 
-RUN apt install -y wget
+RUN apt install -yqq wget
 RUN npm install
 RUN mkdir -p node_modules/mns & mkdir -p tmp
 RUN wget -q https://github.com/Helidium/Mitol/archive/v0.0.1.tar.gz -P tmp

+ 104 - 0
tfb

@@ -0,0 +1,104 @@
+#!/bin/sh
+
+################## https://github.com/mkropat/sh-realpath #####################
+#
+# The MIT License (MIT)
+#
+# Copyright (c) 2014 Michael Kropat
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+realpath() {
+    canonicalize_path "$(resolve_symlinks "$1")"
+}
+
+resolve_symlinks() {
+    _resolve_symlinks "$1"
+}
+
+_resolve_symlinks() {
+    _assert_no_path_cycles "$@" || return
+
+    local dir_context path
+    path=$(readlink -- "$1")
+    if [ $? = 0 ]; then
+        dir_context=$(dirname -- "$1")
+        _resolve_symlinks "$(_prepend_dir_context_if_necessary "$dir_context" "$path")" "$@"
+    else
+        printf '%s\n' "$1"
+    fi
+}
+
+_prepend_dir_context_if_necessary() {
+    if [ "$1" = . ]; then
+        printf '%s\n' "$2"
+    else
+        _prepend_path_if_relative "$1" "$2"
+    fi
+}
+
+_prepend_path_if_relative() {
+    case "$2" in
+        /* ) printf '%s\n' "$2" ;;
+         * ) printf '%s\n' "$1/$2" ;;
+    esac
+}
+
+_assert_no_path_cycles() {
+    local target path
+
+    target=$1
+    shift
+
+    for path in "$@"; do
+        if [ "$path" = "$target" ]; then
+            return 1
+        fi
+    done
+}
+
+canonicalize_path() {
+    if [ -d "$1" ]; then
+        _canonicalize_dir_path "$1"
+    else
+        _canonicalize_file_path "$1"
+    fi
+}
+
+_canonicalize_dir_path() {
+    (cd "$1" 2>/dev/null && pwd -P)
+}
+
+_canonicalize_file_path() {
+    local dir file
+    dir=$(dirname -- "$1")
+    file=$(basename -- "$1")
+    (cd "$dir" 2>/dev/null >/dev/null && printf '%s/%s\n' "$(pwd -P)" "$file")
+}
+
+##############################################################################
+
+SCRIPT_PATH="$(realpath "$0")"
+SCRIPT_ROOT="$(dirname "$SCRIPT_PATH")"
+
+if ! docker network inspect tfb >/dev/null 2>&1; then
+  docker network create tfb >/dev/null
+fi
+
+exec docker run -it --rm --network tfb -v /var/run/docker.sock:/var/run/docker.sock -v ${SCRIPT_ROOT}:/FrameworkBenchmarks techempower/tfb "${@}"

+ 2 - 2
toolset/databases/mongodb/mongodb.dockerfile

@@ -4,8 +4,8 @@ COPY ./ ./
 
 RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
 RUN echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.6.list
-RUN apt-get -y update
-RUN apt-get -y install mongodb-org
+RUN apt -y update
+RUN apt -y install mongodb-org
 
 RUN mkdir -p /data/db
 RUN chmod 777 /data/db

+ 1 - 1
toolset/databases/mysql/mysql.dockerfile

@@ -18,7 +18,7 @@ RUN apt update
 RUN ["/bin/bash", "-c", "debconf-set-selections <<< \"mysql-community-server mysql-community-server/data-dir select 'Y'\""]
 RUN ["/bin/bash", "-c", "debconf-set-selections <<< \"mysql-community-server mysql-community-server/root-pass password secret\""]
 RUN ["/bin/bash", "-c", "debconf-set-selections <<< \"mysql-community-server mysql-community-server/re-root-pass password secret\""]
-RUN DEBIAN_FRONTEND=noninteractive apt-get -y install mysql-server
+RUN DEBIAN_FRONTEND=noninteractive apt -y install mysql-server
 
 RUN mv /etc/mysql/my.cnf /etc/mysql/my.cnf.orig
 RUN cp my.cnf /etc/mysql/my.cnf

+ 2 - 2
toolset/databases/postgres/postgres.dockerfile

@@ -15,8 +15,8 @@ ADD create-postgres-database.sql create-postgres-database.sql
 ADD create-postgres.sql create-postgres.sql
 
 # install postgresql on database machine
-RUN apt-get -y update
-RUN apt-get -y install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" postgresql
+RUN apt -y update
+RUN apt -y install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" postgresql
 
 ENV PG_VERSION 9.5