2018-12-24 16:04:54 +01:00
|
|
|
#!/bin/bash -eu
|
|
|
|
|
|
|
|
# docker_env.sh
|
|
|
|
#
|
|
|
|
# Purpose
|
|
|
|
# -------
|
|
|
|
#
|
|
|
|
# This is a helper script to enable running tests under a Docker container,
|
|
|
|
# thus making it easier to get set up as well as isolating test dependencies
|
|
|
|
# (which include legacy/insecure configurations of openssl and gnutls).
|
|
|
|
#
|
2022-12-15 10:08:26 +01:00
|
|
|
# WARNING: the Dockerfile used by this script is no longer maintained! See
|
|
|
|
# https://github.com/Mbed-TLS/mbedtls-test/blob/master/README.md#quick-start
|
|
|
|
# for the set of Docker images we use on the CI.
|
|
|
|
#
|
2018-12-24 16:04:54 +01:00
|
|
|
# Notes for users
|
|
|
|
# ---------------
|
|
|
|
# This script expects a Linux x86_64 system with a recent version of Docker
|
|
|
|
# installed and available for use, as well as http/https access. If a proxy
|
|
|
|
# server must be used, invoke this script with the usual environment variables
|
2019-06-29 18:26:51 +02:00
|
|
|
# (http_proxy and https_proxy) set appropriately. If an alternate Docker
|
|
|
|
# registry is needed, specify MBEDTLS_DOCKER_REGISTRY to point at the
|
|
|
|
# host name.
|
|
|
|
#
|
2018-12-24 16:04:54 +01:00
|
|
|
#
|
|
|
|
# Running this script directly will check for Docker availability and set up
|
|
|
|
# the Docker image.
|
|
|
|
|
2020-08-07 13:07:28 +02:00
|
|
|
# Copyright The Mbed TLS Contributors
|
2019-05-31 13:38:06 +02:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2018-12-24 16:04:54 +01:00
|
|
|
|
|
|
|
# default values, can be overridden by the environment
|
2019-06-01 15:44:30 +02:00
|
|
|
: ${MBEDTLS_DOCKER_GUEST:=bionic}
|
2018-12-24 16:04:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
DOCKER_IMAGE_TAG="armmbed/mbedtls-test:${MBEDTLS_DOCKER_GUEST}"
|
|
|
|
|
|
|
|
# Make sure docker is available
|
|
|
|
if ! which docker > /dev/null; then
|
|
|
|
echo "Docker is required but doesn't seem to be installed. See https://www.docker.com/ to get started"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Figure out if we need to 'sudo docker'
|
|
|
|
if groups | grep docker > /dev/null; then
|
|
|
|
DOCKER="docker"
|
|
|
|
else
|
|
|
|
echo "Using sudo to invoke docker since you're not a member of the docker group..."
|
|
|
|
DOCKER="sudo docker"
|
|
|
|
fi
|
|
|
|
|
2020-06-02 11:04:15 +02:00
|
|
|
# Figure out the number of processors available
|
|
|
|
if [ "$(uname)" == "Darwin" ]; then
|
|
|
|
NUM_PROC="$(sysctl -n hw.logicalcpu)"
|
|
|
|
else
|
|
|
|
NUM_PROC="$(nproc)"
|
|
|
|
fi
|
|
|
|
|
2018-12-24 16:04:54 +01:00
|
|
|
# Build the Docker image
|
|
|
|
echo "Getting docker image up to date (this may take a few minutes)..."
|
|
|
|
${DOCKER} image build \
|
|
|
|
-t ${DOCKER_IMAGE_TAG} \
|
|
|
|
--cache-from=${DOCKER_IMAGE_TAG} \
|
2020-06-02 11:04:15 +02:00
|
|
|
--build-arg MAKEFLAGS_PARALLEL="-j ${NUM_PROC}" \
|
2019-06-29 18:26:51 +02:00
|
|
|
--network host \
|
2018-12-24 16:04:54 +01:00
|
|
|
${http_proxy+--build-arg http_proxy=${http_proxy}} \
|
|
|
|
${https_proxy+--build-arg https_proxy=${https_proxy}} \
|
2019-06-29 18:26:51 +02:00
|
|
|
${MBEDTLS_DOCKER_REGISTRY+--build-arg MY_REGISTRY="${MBEDTLS_DOCKER_REGISTRY}/"} \
|
2018-12-24 16:04:54 +01:00
|
|
|
tests/docker/${MBEDTLS_DOCKER_GUEST}
|
|
|
|
|
|
|
|
run_in_docker()
|
|
|
|
{
|
|
|
|
ENV_ARGS=""
|
|
|
|
while [ "$1" == "-e" ]; do
|
|
|
|
ENV_ARGS="${ENV_ARGS} $1 $2"
|
|
|
|
shift 2
|
|
|
|
done
|
|
|
|
|
|
|
|
${DOCKER} container run -it --rm \
|
|
|
|
--cap-add SYS_PTRACE \
|
|
|
|
--user "$(id -u):$(id -g)" \
|
|
|
|
--volume $PWD:$PWD \
|
|
|
|
--workdir $PWD \
|
|
|
|
-e MAKEFLAGS \
|
|
|
|
-e PYLINTHOME=/tmp/.pylintd \
|
|
|
|
${ENV_ARGS} \
|
|
|
|
${DOCKER_IMAGE_TAG} \
|
|
|
|
$@
|
|
|
|
}
|