blob: 04efa82e4a5af641a7e7cbd26dc08805b8da4143 [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
17# (http_proxy and https_proxy) set appropriately.
18#
19# Running this script directly will check for Docker availability and set up
20# the Docker image.
21
Peter Kolbus4225b1a2019-05-31 06:38:06 -050022# Copyright (C) 2006-2019, Arm Limited (or its affiliates), All Rights Reserved.
23# SPDX-License-Identifier: Apache-2.0
24#
25# Licensed under the Apache License, Version 2.0 (the "License"); you may
26# not use this file except in compliance with the License.
27# You may obtain a copy of the License at
28#
29# http://www.apache.org/licenses/LICENSE-2.0
30#
31# Unless required by applicable law or agreed to in writing, software
32# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
33# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34# See the License for the specific language governing permissions and
35# limitations under the License.
36#
37# This file is part of Mbed TLS (https://tls.mbed.org)
38
Peter Kolbuse4e2d3a2018-12-24 09:04:54 -060039
40# default values, can be overridden by the environment
Peter Kolbus49c24352019-06-01 08:44:30 -050041: ${MBEDTLS_DOCKER_GUEST:=bionic}
Peter Kolbuse4e2d3a2018-12-24 09:04:54 -060042
43
44DOCKER_IMAGE_TAG="armmbed/mbedtls-test:${MBEDTLS_DOCKER_GUEST}"
45
46# Make sure docker is available
47if ! which docker > /dev/null; then
48 echo "Docker is required but doesn't seem to be installed. See https://www.docker.com/ to get started"
49 exit 1
50fi
51
52# Figure out if we need to 'sudo docker'
53if groups | grep docker > /dev/null; then
54 DOCKER="docker"
55else
56 echo "Using sudo to invoke docker since you're not a member of the docker group..."
57 DOCKER="sudo docker"
58fi
59
60# Build the Docker image
61echo "Getting docker image up to date (this may take a few minutes)..."
62${DOCKER} image build \
63 -t ${DOCKER_IMAGE_TAG} \
64 --cache-from=${DOCKER_IMAGE_TAG} \
65 --build-arg MAKEFLAGS_PARALLEL="-j $(nproc)" \
66 ${http_proxy+--build-arg http_proxy=${http_proxy}} \
67 ${https_proxy+--build-arg https_proxy=${https_proxy}} \
68 tests/docker/${MBEDTLS_DOCKER_GUEST}
69
70run_in_docker()
71{
72 ENV_ARGS=""
73 while [ "$1" == "-e" ]; do
74 ENV_ARGS="${ENV_ARGS} $1 $2"
75 shift 2
76 done
77
78 ${DOCKER} container run -it --rm \
79 --cap-add SYS_PTRACE \
80 --user "$(id -u):$(id -g)" \
81 --volume $PWD:$PWD \
82 --workdir $PWD \
83 -e MAKEFLAGS \
84 -e PYLINTHOME=/tmp/.pylintd \
85 ${ENV_ARGS} \
86 ${DOCKER_IMAGE_TAG} \
87 $@
88}