run docker builds in travis instead of jenkins (#4526)

* docker experiment in travis

* let's run 'em all

* okay run as travis

* fine just use a number

* remove xenial since we test that elsewhere

* suspicion

* review feedback

* more comments

* use workdir

* heavy sigh
diff --git a/.travis.yml b/.travis.yml
index faa3527..87edf43 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -55,6 +55,56 @@
           env: TOXENV=py37 LIBRESSL=2.7.4
         - python: 3.7
           env: TOXENV=py37 LIBRESSL=2.8.2
+
+        - python: 2.7
+          services: docker
+          env: TOXENV=py27 DOCKER=pyca/cryptography-runner-centos7
+        - python: 2.7
+          services: docker
+          env: TOXENV=py27 DOCKER=pyca/cryptography-runner-wheezy
+        - python: 2.7
+          services: docker
+          env: TOXENV=py27 DOCKER=pyca/cryptography-runner-jessie
+        - python: 3.4
+          services: docker
+          env: TOXENV=py34 DOCKER=pyca/cryptography-runner-jessie
+        - python: 2.7
+          services: docker
+          env: TOXENV=py27 DOCKER=pyca/cryptography-runner-stretch
+        - python: 3.5
+          services: docker
+          env: TOXENV=py35 DOCKER=pyca/cryptography-runner-stretch
+        - python: 2.7
+          services: docker
+          env: TOXENV=py27 DOCKER=pyca/cryptography-runner-buster
+        - python: 3.6
+          services: docker
+          env: TOXENV=py36 DOCKER=pyca/cryptography-runner-buster
+        - python: 2.7
+          services: docker
+          env: TOXENV=py27 DOCKER=pyca/cryptography-runner-sid
+        - python: 3.6
+          services: docker
+          env: TOXENV=py36 DOCKER=pyca/cryptography-runner-sid
+        - python: 2.7
+          services: docker
+          env: TOXENV=py27 DOCKER=pyca/cryptography-runner-ubuntu-rolling
+        - python: 3.6
+          services: docker
+          env: TOXENV=py36 DOCKER=pyca/cryptography-runner-ubuntu-rolling
+        - python: 2.7
+          services: docker
+          env: TOXENV=randomorder DOCKER=pyca/cryptography-runner-ubuntu-rolling
+        - python: 2.7
+          services: docker
+          env: TOXENV=py27 DOCKER=pyca/cryptography-runner-fedora
+        - python: 3.6
+          services: docker
+          env: TOXENV=py36 DOCKER=pyca/cryptography-runner-fedora
+        - python: 3.6
+          services: docker
+          env: TOXENV=py36 DOCKER=pyca/cryptography-runner-alpine:latest
+
         - python: 3.6
           env: TOXENV=docs OPENSSL=1.1.0i
           addons:
diff --git a/.travis/install.sh b/.travis/install.sh
index 20a8831..def7343 100755
--- a/.travis/install.sh
+++ b/.travis/install.sh
@@ -46,6 +46,14 @@
     fi
 fi
 
+if [ -n "${DOCKER}" ]; then
+    if [ -n "${OPENSSL}" ] || [ -n "${LIBRESSL}" ]; then
+        echo "OPENSSL and LIBRESSL are not allowed when DOCKER is set."
+        exit 1
+    fi
+    docker pull "$DOCKER"
+fi
+
 if [ -z "${DOWNSTREAM}" ]; then
     git clone --depth=1 https://github.com/google/wycheproof "$HOME/wycheproof"
 fi
diff --git a/.travis/run.sh b/.travis/run.sh
index 5e0e56d..8f8dd68 100755
--- a/.travis/run.sh
+++ b/.travis/run.sh
@@ -22,7 +22,16 @@
 
 source ~/.venv/bin/activate
 
-if [ -n "${TOXENV}" ]; then
+if [ -n "${DOCKER}" ]; then
+    # We will be able to drop the -u once we switch the default container user in the
+    # dockerfiles.
+    docker run --rm -u 2000:2000 \
+        -v "${TRAVIS_BUILD_DIR}":"${TRAVIS_BUILD_DIR}" \
+        -v "${HOME}/wycheproof":/wycheproof \
+        -w "${TRAVIS_BUILD_DIR}" \
+        -e TOXENV "${DOCKER}" \
+        /bin/sh -c "tox -- --wycheproof-root='/wycheproof'"
+elif [ -n "${TOXENV}" ]; then
     tox -- --wycheproof-root="$HOME/wycheproof"
 else
     downstream_script="${TRAVIS_BUILD_DIR}/.travis/downstream.d/${DOWNSTREAM}.sh"
diff --git a/.travis/upload_coverage.sh b/.travis/upload_coverage.sh
index e960907..2f2cb3c 100755
--- a/.travis/upload_coverage.sh
+++ b/.travis/upload_coverage.sh
@@ -11,7 +11,7 @@
         docs);;
         *)
             source ~/.venv/bin/activate
-            codecov --env TRAVIS_OS_NAME,TOXENV,OPENSSL
+            codecov --env TRAVIS_OS_NAME,TOXENV,OPENSSL,DOCKER
             ;;
     esac
 fi
diff --git a/Jenkinsfile b/Jenkinsfile
index 8bb15d6..b9d8698 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -21,61 +21,11 @@
     ],
     [
         label: 'docker',
-        imageName: 'pyca/cryptography-runner-centos7',
-        toxenvs: ['py27'],
-    ],
-    [
-        label: 'docker',
-        imageName: 'pyca/cryptography-runner-wheezy',
-        toxenvs: ['py27'],
-    ],
-    [
-        label: 'docker',
-        imageName: 'pyca/cryptography-runner-jessie',
-        toxenvs: ['py27', 'py34'],
-    ],
-    [
-        label: 'docker',
-        imageName: 'pyca/cryptography-runner-stretch',
-        toxenvs: ['py27', 'py35'],
-    ],
-    [
-        label: 'docker',
-        imageName: 'pyca/cryptography-runner-buster',
-        toxenvs: ['py27', 'py36'],
-    ],
-    [
-        label: 'docker',
-        imageName: 'pyca/cryptography-runner-sid',
-        toxenvs: ['py27', 'py36'],
-    ],
-    [
-        label: 'docker',
-        imageName: 'pyca/cryptography-runner-ubuntu-xenial',
-        toxenvs: ['py27', 'py35'],
-    ],
-    [
-        label: 'docker',
-        imageName: 'pyca/cryptography-runner-ubuntu-rolling',
-        toxenvs: ['py27', 'py36', 'randomorder'],
-    ],
-    [
-        label: 'docker',
         imageName: 'pyca/cryptography-runner-sid',
         toxenvs: ['docs'],
         artifacts: 'cryptography/docs/_build/html/**',
         artifactExcludes: '**/*.doctree',
     ],
-    [
-        label: 'docker',
-        imageName: 'pyca/cryptography-runner-fedora',
-        toxenvs: ['py27', 'py36'],
-    ],
-    [
-        label: 'docker',
-        imageName: 'pyca/cryptography-runner-alpine:latest',
-        toxenvs: ['py36'],
-    ],
 ]
 
 /* Add the linkcheck job to our config list if we're on master */