blob: 3e1ce6125b287e2ffe7e8bb0f1a972e7fd1157cf [file] [log] [blame]
Peter Kolbuse4e2d3a2018-12-24 09:04:54 -06001#!/bin/bash -eu
2
3# docker_env.sh
4#
5# This file is part of mbed TLS (https://tls.mbed.org)
6#
7# Copyright (c) 2018-2019, ARM Limited, All Rights Reserved
8#
9# Purpose
10# -------
11#
12# This is a helper script to enable running tests under a Docker container,
13# thus making it easier to get set up as well as isolating test dependencies
14# (which include legacy/insecure configurations of openssl and gnutls).
15#
16# Notes for users
17# ---------------
18# This script expects a Linux x86_64 system with a recent version of Docker
19# installed and available for use, as well as http/https access. If a proxy
20# server must be used, invoke this script with the usual environment variables
21# (http_proxy and https_proxy) set appropriately.
22#
23# Running this script directly will check for Docker availability and set up
24# the Docker image.
25
26
27# default values, can be overridden by the environment
28: ${MBEDTLS_DOCKER_GUEST:=xenial}
29
30
31DOCKER_IMAGE_TAG="armmbed/mbedtls-test:${MBEDTLS_DOCKER_GUEST}"
32
33# Make sure docker is available
34if ! which docker > /dev/null; then
35 echo "Docker is required but doesn't seem to be installed. See https://www.docker.com/ to get started"
36 exit 1
37fi
38
39# Figure out if we need to 'sudo docker'
40if groups | grep docker > /dev/null; then
41 DOCKER="docker"
42else
43 echo "Using sudo to invoke docker since you're not a member of the docker group..."
44 DOCKER="sudo docker"
45fi
46
47# Build the Docker image
48echo "Getting docker image up to date (this may take a few minutes)..."
49${DOCKER} image build \
50 -t ${DOCKER_IMAGE_TAG} \
51 --cache-from=${DOCKER_IMAGE_TAG} \
52 --build-arg MAKEFLAGS_PARALLEL="-j $(nproc)" \
53 ${http_proxy+--build-arg http_proxy=${http_proxy}} \
54 ${https_proxy+--build-arg https_proxy=${https_proxy}} \
55 tests/docker/${MBEDTLS_DOCKER_GUEST}
56
57run_in_docker()
58{
59 ENV_ARGS=""
60 while [ "$1" == "-e" ]; do
61 ENV_ARGS="${ENV_ARGS} $1 $2"
62 shift 2
63 done
64
65 ${DOCKER} container run -it --rm \
66 --cap-add SYS_PTRACE \
67 --user "$(id -u):$(id -g)" \
68 --volume $PWD:$PWD \
69 --workdir $PWD \
70 -e MAKEFLAGS \
71 -e PYLINTHOME=/tmp/.pylintd \
72 ${ENV_ARGS} \
73 ${DOCKER_IMAGE_TAG} \
74 $@
75}