VOL-546 Add support for proxy servers in build
- Propagate proxy environment variables into docker builds
- Generate mvn settings.xml based on proxy env vars and allow custom xml
- Update to latest docker installation within go-lang docker image (to avoid apt-key proxy issue)
- Allow additional parameters with DOCKER_BUILD_EXTRA_ARGS, for example --no-cache, --pull
- Also fixes 'overriding recipe for target' for voltha target
Change-Id: Ifa545a0262ecfe434ad230ddab4f61935c7244e0
diff --git a/docker/Dockerfile.golang b/docker/Dockerfile.golang
index 47765fe..0b6648c 100644
--- a/docker/Dockerfile.golang
+++ b/docker/Dockerfile.golang
@@ -1,12 +1,12 @@
FROM golang:1.9.2
MAINTAINER Alex Peters <info@alexanderpeters.de>
-RUN apt-get update && apt-get install -y apt-transport-https ca-certificates jq
+RUN apt-get update && apt-get install -y apt-transport-https ca-certificates jq curl gnupg2 software-properties-common
-RUN echo "deb https://apt.dockerproject.org/repo debian-jessie main" > /etc/apt/sources.list.d/docker.list
-RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
+RUN curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | apt-key add -
+RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") $(lsb_release -cs) stable"
-RUN apt-get update && apt-cache policy docker-engine && apt-get install -y upx-ucl docker-engine && apt-get clean
+RUN apt-get update && apt-cache policy docker-ce && apt-get install -y upx-ucl docker-ce && apt-get clean
RUN go get github.com/pwaller/goupx \
&& go get golang.org/x/tools/cmd/cover \
diff --git a/docker/Dockerfile.onos b/docker/Dockerfile.onos
index 4e9af3a..528d90b 100644
--- a/docker/Dockerfile.onos
+++ b/docker/Dockerfile.onos
@@ -9,8 +9,10 @@
# Build the applications
RUN mkdir -p ${DOWNLOAD_ROOT}
WORKDIR ${DOWNLOAD_ROOT}
+COPY config/mvn_settings.* ${DOWNLOAD_ROOT}/
+RUN ./mvn_settings.sh
ADD config/dependencies.xml .
-RUN mvn dependency:copy -Dmdep.useBaseVersion=true -DoutputDirectory=${DOWNLOAD_ROOT} -Dsilent=true -f dependencies.xml
+RUN mvn dependency:copy -Dmdep.useBaseVersion=true -DoutputDirectory=${DOWNLOAD_ROOT} -Dsilent=true -f dependencies.xml -s mvn_settings.xml
FROM onosproject/onos:1.10.9 as install
MAINTAINER Open Networking Foundation <info@opennetworking.org>
diff --git a/docker/config/mvn_settings.sh b/docker/config/mvn_settings.sh
new file mode 100755
index 0000000..771743f
--- /dev/null
+++ b/docker/config/mvn_settings.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+if [ -f mvn_settings.custom.xml ] ; then
+ cp mvn_settings.custom.xml mvn_settings.xml
+ exit 0
+fi
+
+if [ "$http_proxy$https_proxy" != "" ] ; then
+ echo " <proxies>" >> mvn_settings.proxy.xml
+ for PROTOCOL in http https ; do
+ proxy="${PROTOCOL}_proxy"
+ proxy="${!proxy}"
+ if [ "$proxy" = "" ] ; then continue ; fi
+
+ # username/password not yet included
+ PROXY_HOST=$(echo "$proxy" | sed "s@.*://@@;s/.*@//;s@:.*@@")
+ PROXY_PORT=$(echo "$proxy" | sed "s@.*://@@;s@.*:@@;s@/.*@@")
+ NON_PROXY=$(echo "$no_proxy" | sed "s@,@|@g")
+
+ echo " <proxy>
+ <id>$PROTOCOL</id>
+ <active>true</active>
+ <protocol>$PROTOCOL</protocol>
+ <host>$PROXY_HOST</host>
+ <port>$PROXY_PORT</port>
+ <nonProxyHosts>$NON_PROXY</nonProxyHosts>
+ </proxy>" >> mvn_settings.proxy.xml
+ done
+ echo " </proxies>" >> mvn_settings.proxy.xml
+
+ sed -i '/<!--PROXY-->/r mvn_settings.proxy.xml' mvn_settings.xml
+fi
+
+if [ -f mvn_settings.extra.xml ] ; then
+ sed -i 's/<!--EXTRA-->/r mvn_settings.extra.xml' mvn_settings.xml
+fi
diff --git a/docker/config/mvn_settings.xml b/docker/config/mvn_settings.xml
new file mode 100644
index 0000000..26f9926
--- /dev/null
+++ b/docker/config/mvn_settings.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you 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.
+-->
+
+<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
+ <!--PROXY-->
+ <!--EXTRA-->
+</settings>