blob: 8bdc4257969087817815fe8cb94f0195d36927b2 [file] [log] [blame]
Peter Kolbuse4e2d3a2018-12-24 09:04:54 -06001#!/bin/bash -eu
2
3# docker_env.sh
4#
Peter Kolbuse4e2d3a2018-12-24 09:04:54 -06005# Purpose
6# -------
7#
8# This is a helper script to enable running tests under a Docker container,
9# thus making it easier to get set up as well as isolating test dependencies
10# (which include legacy/insecure configurations of openssl and gnutls).
11#
12# Notes for users
13# ---------------
14# This script expects a Linux x86_64 system with a recent version of Docker
15# installed and available for use, as well as http/https access. If a proxy
16# server must be used, invoke this script with the usual environment variables
Peter Kolbus718c74c2019-06-29 11:26:51 -050017# (http_proxy and https_proxy) set appropriately. If an alternate Docker
18# registry is needed, specify MBEDTLS_DOCKER_REGISTRY to point at the
19# host name.
20#
Peter Kolbuse4e2d3a2018-12-24 09:04:54 -060021#
22# Running this script directly will check for Docker availability and set up
23# the Docker image.
24
Peter Kolbus4225b1a2019-05-31 06:38:06 -050025# Copyright (C) 2006-2019, Arm Limited (or its affiliates), All Rights Reserved.
26# SPDX-License-Identifier: Apache-2.0
27#
28# Licensed under the Apache License, Version 2.0 (the "License"); you may
29# not use this file except in compliance with the License.
30# You may obtain a copy of the License at
31#
32# http://www.apache.org/licenses/LICENSE-2.0
33#
34# Unless required by applicable law or agreed to in writing, software
35# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
36# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37# See the License for the specific language governing permissions and
38# limitations under the License.
39#
40# This file is part of Mbed TLS (https://tls.mbed.org)
41
Peter Kolbuse4e2d3a2018-12-24 09:04:54 -060042
43# default values, can be overridden by the environment
Peter Kolbus49c24352019-06-01 08:44:30 -050044: ${MBEDTLS_DOCKER_GUEST:=bionic}
Peter Kolbuse4e2d3a2018-12-24 09:04:54 -060045
46
47DOCKER_IMAGE_TAG="armmbed/mbedtls-test:${MBEDTLS_DOCKER_GUEST}"
48
49# Make sure docker is available
50if ! which docker > /dev/null; then
51 echo "Docker is required but doesn't seem to be installed. See https://www.docker.com/ to get started"
52 exit 1
53fi
54
55# Figure out if we need to 'sudo docker'
56if groups | grep docker > /dev/null; then
57 DOCKER="docker"
58else
59 echo "Using sudo to invoke docker since you're not a member of the docker group..."
60 DOCKER="sudo docker"
61fi
62
63# Build the Docker image
64echo "Getting docker image up to date (this may take a few minutes)..."
65${DOCKER} image build \
66 -t ${DOCKER_IMAGE_TAG} \
67 --cache-from=${DOCKER_IMAGE_TAG} \
68 --build-arg MAKEFLAGS_PARALLEL="-j $(nproc)" \
Peter Kolbus718c74c2019-06-29 11:26:51 -050069 --network host \
Peter Kolbuse4e2d3a2018-12-24 09:04:54 -060070 ${http_proxy+--build-arg http_proxy=${http_proxy}} \
71 ${https_proxy+--build-arg https_proxy=${https_proxy}} \
Peter Kolbus718c74c2019-06-29 11:26:51 -050072 ${MBEDTLS_DOCKER_REGISTRY+--build-arg MY_REGISTRY="${MBEDTLS_DOCKER_REGISTRY}/"} \
Peter Kolbuse4e2d3a2018-12-24 09:04:54 -060073 tests/docker/${MBEDTLS_DOCKER_GUEST}
74
75run_in_docker()
76{
77 ENV_ARGS=""
78 while [ "$1" == "-e" ]; do
79 ENV_ARGS="${ENV_ARGS} $1 $2"
80 shift 2
81 done
82
83 ${DOCKER} container run -it --rm \
84 --cap-add SYS_PTRACE \
85 --user "$(id -u):$(id -g)" \
86 --volume $PWD:$PWD \
87 --workdir $PWD \
88 -e MAKEFLAGS \
89 -e PYLINTHOME=/tmp/.pylintd \
90 ${ENV_ARGS} \
91 ${DOCKER_IMAGE_TAG} \
92 $@
93}