From 2ea322822ad9b722afad3994b38125fb87d864e2 Mon Sep 17 00:00:00 2001 From: Felipe Monteiro Date: Thu, 7 Jun 2018 17:36:35 +0100 Subject: [PATCH] Allow Deckhand image to be built behind proxy This patchset allows Deckhand image to be built behind proxy by adding appropriate variables to Dockerfile and to the Ansible build image script. Change-Id: Idff4adb4762b8062072a2da066044ecd7782ed9d --- images/deckhand/Dockerfile | 12 +++++++ .../roles/build-images/defaults/main.yaml | 18 ++++++++++ .../tasks/build-deckhand-image.yaml | 36 +++++++++++++++++-- 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 tools/gate/roles/build-images/defaults/main.yaml diff --git a/images/deckhand/Dockerfile b/images/deckhand/Dockerfile index 1198756b..bd902b49 100644 --- a/images/deckhand/Dockerfile +++ b/images/deckhand/Dockerfile @@ -18,6 +18,18 @@ ENV DEBIAN_FRONTEND noninteractive ENV container docker ENV PORT 9000 +ARG HTTP_PROXY="" +ENV HTTP_PROXY ${HTTP_PROXY} +ENV http_proxy ${HTTP_PROXY} + +ARG HTTPS_PROXY="" +ENV HTTPS_PROXY ${HTTPS_PROXY} +ENV https_proxy ${HTTPS_PROXY} + +ARG NO_PROXY="127.0.0.1,localhost,.svc.cluster.local" +ENV NO_PROXY ${NO_PROXY} +ENV no_proxy ${NO_PROXY} + # Expose port 9000 for application EXPOSE $PORT diff --git a/tools/gate/roles/build-images/defaults/main.yaml b/tools/gate/roles/build-images/defaults/main.yaml new file mode 100644 index 00000000..29f96561 --- /dev/null +++ b/tools/gate/roles/build-images/defaults/main.yaml @@ -0,0 +1,18 @@ +# Copyright 2018 AT&T Intellectual Property. All other rights reserved. +# +# 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. + +proxy: + http: null + https: null + noproxy: null diff --git a/tools/gate/roles/build-images/tasks/build-deckhand-image.yaml b/tools/gate/roles/build-images/tasks/build-deckhand-image.yaml index a685618e..46682bea 100644 --- a/tools/gate/roles/build-images/tasks/build-deckhand-image.yaml +++ b/tools/gate/roles/build-images/tasks/build-deckhand-image.yaml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: set zuul_site_mirror_fqdn from env var if not defined +- name: Set zuul_site_mirror_fqdn from env var if not defined when: zuul_site_mirror_fqdn is not defined set_fact: zuul_site_mirror_fqdn: "{{ lookup('env','zuul_site_mirror_fqdn') }}" @@ -29,7 +29,8 @@ vars: work_dir: "{{ zuul.project.src_dir }}/{{ zuul_airship_deckhand_relative_path | default('') }}" - - name: Airship-Deckhand image build path + - name: Build Airship-Deckhand Image + when: proxy.http is undefined or (proxy.http | trim == "") shell: |- set -ex; docker build \ @@ -47,11 +48,42 @@ args: chdir: "{{ airship_deckhand_path.stdout }}" executable: /bin/bash + register: result + failed_when: "'permission denied' in result.stdout" + become: yes + + - name: Build Airship-Deckhand Image Behind Proxy + when: proxy.http is defined and (proxy.http | trim != "") + shell: |- + set -ex; + docker build \ + --network host \ + --force-rm \ + --label zuul \ + --file images/deckhand/Dockerfile \ + --build-arg HTTP_PROXY="{{ proxy.http }}" \ + --build-arg HTTPS_PROXY="{{ proxy.https }}" \ + --build-arg NO_PROXY="{{ proxy.noproxy }}" \ + {% if zuul_site_mirror_fqdn is defined and zuul_site_mirror_fqdn %} + --build-arg UBUNTU_URL="http://{{ zuul_site_mirror_fqdn }}/ubuntu/" \ + --build-arg ALLOW_UNAUTHENTICATED="true" \ + --build-arg PIP_INDEX_URL="http://{{ zuul_site_mirror_fqdn }}/pypi/simple" \ + --build-arg PIP_TRUSTED_HOST="{{ zuul_site_mirror_fqdn }}" \ + {% endif %} + . + args: + chdir: "{{ airship_deckhand_path.stdout }}" + executable: /bin/bash + register: result + failed_when: "'permission denied' in result.stdout" + become: yes - name: Register Deckhand Image ID shell: |- set -e; echo $( docker images --filter label=zuul | awk '{print $3}' | head -2 | tail -1 ) register: airship_deckhand_image_id + failed_when: "'permission denied' in airship_deckhand_image_id.stdout" args: chdir: "{{ airship_deckhand_path.stdout }}" + become: yes