From 391bbf69d7e56f9d6b8b744c98e7697e3d5427bb Mon Sep 17 00:00:00 2001 From: Tin Lam Date: Wed, 10 Jan 2018 00:35:09 -0600 Subject: [PATCH] Provide ability to specify proxy This patch set provides ability to configure the proxy setting in the ansible playbook used to run the gate. Change-Id: I7ae66cb16fa6db7d46a0a3f23c289cc625e583c4 Signed-off-by: Tin Lam --- .../build-images/tasks/kubeadm-aio.yaml | 23 ++++++++++++++++++- .../playbooks/deploy-docker/tasks/main.yaml | 14 +++++++++++ .../templates/http-proxy.conf.j2 | 4 ++++ .../playbooks/deploy-package/tasks/pip.yaml | 4 ++++ .../deploy-python-pip/tasks/main.yaml | 4 ++++ tools/gate/playbooks/vars.yaml | 5 ++++ tools/images/kubeadm-aio/Dockerfile | 12 ++++++++++ .../roles/deploy-package/tasks/pip.yaml | 6 +++-- 8 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 tools/gate/playbooks/deploy-docker/templates/http-proxy.conf.j2 diff --git a/tools/gate/playbooks/build-images/tasks/kubeadm-aio.yaml b/tools/gate/playbooks/build-images/tasks/kubeadm-aio.yaml index d56c54bca..ed3ed149b 100644 --- a/tools/gate/playbooks/build-images/tasks/kubeadm-aio.yaml +++ b/tools/gate/playbooks/build-images/tasks/kubeadm-aio.yaml @@ -35,7 +35,28 @@ # CNI_VERSION: "{{ version.cni }}" # HELM_VERSION: "{{ version.helm }}" # CHARTS: "calico,flannel,tiller,kube-dns" + - name: Kubeadm-AIO image build path with proxy + when: proxy.http is defined and (proxy.http | trim != "") + shell: |- + set -e + docker build \ + --network host \ + --force-rm \ + --tag "{{ images.kubernetes.kubeadm_aio }}" \ + --file tools/images/kubeadm-aio/Dockerfile \ + --build-arg KUBE_VERSION="{{ version.kubernetes }}" \ + --build-arg CNI_VERSION="{{ version.cni }}" \ + --build-arg HELM_VERSION="{{ version.helm }}" \ + --build-arg CHARTS="calico,flannel,tiller,kube-dns" \ + --build-arg HTTP_PROXY="{{ proxy.http }}" \ + --build-arg HTTPS_PROXY="{{ proxy.https }}" \ + --build-arg NO_PROXY="{{ proxy.noproxy }}" \ + . + args: + chdir: "{{ kubeadm_aio_path.stdout }}/" + executable: /bin/bash - name: Kubeadm-AIO image build path + when: proxy.http is undefined or (proxy.http | trim == "") shell: |- set -e docker build \ @@ -50,4 +71,4 @@ . args: chdir: "{{ kubeadm_aio_path.stdout }}/" - executable: /bin/bash + executable: /bin/bash \ No newline at end of file diff --git a/tools/gate/playbooks/deploy-docker/tasks/main.yaml b/tools/gate/playbooks/deploy-docker/tasks/main.yaml index dc8d27c90..4d33d2000 100644 --- a/tools/gate/playbooks/deploy-docker/tasks/main.yaml +++ b/tools/gate/playbooks/deploy-docker/tasks/main.yaml @@ -38,6 +38,20 @@ dest: /etc/systemd/system/docker.service mode: 0640 +# NOTE: (lamt) Setting up the proxy before installing docker +- name: ensure docker.service.d directory exists + when: proxy.http is defined and (proxy.http | trim != "") + file: + path: /etc/systemd/system/docker.service.d + state: directory + +- name: proxy | moving proxy systemd unit into place + when: ( need_docker | failed ) and ( proxy.http is defined and (proxy.http | trim != "") ) + template: + src: http-proxy.conf.j2 + dest: /etc/systemd/system/docker.service.d/http-proxy.conf + mode: 0640 + - name: deploy docker packages when: need_docker | failed include_role: diff --git a/tools/gate/playbooks/deploy-docker/templates/http-proxy.conf.j2 b/tools/gate/playbooks/deploy-docker/templates/http-proxy.conf.j2 new file mode 100644 index 000000000..90d8e1d53 --- /dev/null +++ b/tools/gate/playbooks/deploy-docker/templates/http-proxy.conf.j2 @@ -0,0 +1,4 @@ +[Service] +Environment="HTTP_PROXY={{ proxy.http }}" +Environment="HTTPS_PROXY={{ proxy.https }}" +Environment="NO_PROXY={{ proxy.noproxy }}" diff --git a/tools/gate/playbooks/deploy-package/tasks/pip.yaml b/tools/gate/playbooks/deploy-package/tasks/pip.yaml index f0c60206d..429bb50b3 100644 --- a/tools/gate/playbooks/deploy-package/tasks/pip.yaml +++ b/tools/gate/playbooks/deploy-package/tasks/pip.yaml @@ -15,6 +15,10 @@ - name: managing pip packages become: true become_user: root + environment: + http_proxy: "{{ proxy.http }}" + https_proxy: "{{ proxy.https }}" + no_proxy: "{{ proxy.noproxy }}" vars: state: present pip: diff --git a/tools/gate/playbooks/deploy-python-pip/tasks/main.yaml b/tools/gate/playbooks/deploy-python-pip/tasks/main.yaml index 19cf5af98..a48868a54 100644 --- a/tools/gate/playbooks/deploy-python-pip/tasks/main.yaml +++ b/tools/gate/playbooks/deploy-python-pip/tasks/main.yaml @@ -39,6 +39,10 @@ - name: ensuring pip is the latest version become: true become_user: root + environment: + http_proxy: "{{ proxy.http }}" + https_proxy: "{{ proxy.https }}" + no_proxy: "{{ proxy.noproxy }}" pip: name: pip state: latest diff --git a/tools/gate/playbooks/vars.yaml b/tools/gate/playbooks/vars.yaml index a08910110..31ea631df 100644 --- a/tools/gate/playbooks/vars.yaml +++ b/tools/gate/playbooks/vars.yaml @@ -17,6 +17,11 @@ version: helm: v2.7.2 cni: v0.6.0 +proxy: + http: null + https: null + noproxy: null + images: kubernetes: kubeadm_aio: openstackhelm/kubeadm-aio:dev diff --git a/tools/images/kubeadm-aio/Dockerfile b/tools/images/kubeadm-aio/Dockerfile index 726393a14..2c68e52a3 100644 --- a/tools/images/kubeadm-aio/Dockerfile +++ b/tools/images/kubeadm-aio/Dockerfile @@ -28,6 +28,18 @@ ENV HELM_VERSION ${HELM_VERSION} ARG CHARTS="calico,flannel,tiller,kube-dns" ENV CHARTS ${CHARTS} +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} + ENV container="docker" \ DEBIAN_FRONTEND="noninteractive" \ CNI_BIN_DIR="/opt/cni/bin" diff --git a/tools/images/kubeadm-aio/assets/opt/playbooks/roles/deploy-package/tasks/pip.yaml b/tools/images/kubeadm-aio/assets/opt/playbooks/roles/deploy-package/tasks/pip.yaml index ff500c552..efaf2a87e 100644 --- a/tools/images/kubeadm-aio/assets/opt/playbooks/roles/deploy-package/tasks/pip.yaml +++ b/tools/images/kubeadm-aio/assets/opt/playbooks/roles/deploy-package/tasks/pip.yaml @@ -1,7 +1,9 @@ - - - name: "installing python {{ package }}" become: true become_user: root + environment: + http_proxy: "{{ proxy.http }}" + https_proxy: "{{ proxy.https }}" + no_proxy: "{{ proxy.noproxy }}" pip: name: "{{ package }}"