Allow image builder and bootstrap_capo proxy customization

Add proxy/no_proxy in bootstrap_capo Makefile and correct/add
proxy/no_proxy in image builder docker proxy playbook

Change-Id: I3dcf3a3303e718f2f8bd5dfa24d9232599249d3f
This commit is contained in:
Dinesh Garg 2020-12-10 11:35:24 +00:00
parent 544e3c5230
commit 353b302eed
3 changed files with 34 additions and 6 deletions

View File

@ -13,6 +13,9 @@ DOCKER_IMAGE_TAG ?= latest
DOCKER_IMAGE ?= $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_PREFIX)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)
DOCKER_TARGET_STAGE ?= release
CONTAINER_TEMP = capo-ephemeral-temp
PROXY ?= http://proxy.foo.com:8000
NO_PROXY ?= localhost,127.0.0.1,.svc.cluster.local
USE_PROXY ?= false
.PHONY: all
all: build docker
@ -22,19 +25,43 @@ images: build docker
.PHONY: build
build: main.go go.mod go.sum config/openstack_cluster.go config/openstack_config.go Dockerfile
ifeq ($(USE_PROXY), true)
@docker build --target builder --network=host \
--build-arg http_proxy=$(PROXY) \
--build-arg https_proxy=$(PROXY) \
--build-arg HTTP_PROXY=$(PROXY) \
--build-arg HTTPS_PROXY=$(PROXY) \
--build-arg no_proxy=$(NO_PROXY) \
--build-arg NO_PROXY=$(NO_PROXY) \
--build-arg MAKE_TARGET=$(DOCKER_MAKE_TARGET) \
--tag $(DOCKER_IMAGE) .
else
@docker build --target builder --network=host \
--build-arg MAKE_TARGET=$(DOCKER_MAKE_TARGET) \
--tag $(DOCKER_IMAGE) .
endif
docker run --name $(CONTAINER_TEMP) $(DOCKER_IMAGE) /bin/true
docker cp $(CONTAINER_TEMP):/home/build/capo-ephemeral .
.PHONY: docker
docker: capo-ephemeral resource/create-k8s-cluster.sh resource/delete-k8s-cluster.sh resource/user-data.sh resource/help.txt Dockerfile
ifeq ($(USE_PROXY), true)
@docker build . --network=host \
--build-arg http_proxy=$(PROXY) \
--build-arg https_proxy=$(PROXY) \
--build-arg HTTP_PROXY=$(PROXY) \
--build-arg HTTPS_PROXY=$(PROXY) \
--build-arg no_proxy=$(NO_PROXY) \
--build-arg NO_PROXY=$(NO_PROXY) \
--build-arg MAKE_TARGET=$(DOCKER_MAKE_TARGET) \
--tag $(DOCKER_IMAGE) \
--force-rm=$(DOCKER_FORCE_CLEAN)
else
@docker build . --network=host \
--build-arg MAKE_TARGET=$(DOCKER_MAKE_TARGET) \
--tag $(DOCKER_IMAGE) \
--force-rm=$(DOCKER_FORCE_CLEAN)
endif
ifeq ($(PUSH_IMAGE), true)
docker push $(DOCKER_IMAGE)
endif
@ -52,4 +79,4 @@ lint:
tests: images
sudo rm -f $(HELP_FILE)
cp openstack-config.yaml /tmp
docker run -v /tmp:/kube --env-file bootstrap-env.list --name capo-bootstrap-test $(DOCKER_IMAGE)
docker run -v /tmp:/kube --env-file bootstrap-env.list --name capo-bootstrap-test $(DOCKER_IMAGE)

View File

@ -51,7 +51,7 @@ endif
build:
ifneq ($(PROXY), )
sudo -E ./tools/docker_proxy.sh $(PROXY)
sudo -E ./tools/docker_proxy.sh $(PROXY) $(NO_PROXY)
export http_proxy=$(PROXY)
export https_proxy=$(PROXY)
export no_proxy=$(NO_PROXY)
@ -86,7 +86,7 @@ endif
cut_image: install_prereqs
ifneq ($(PROXY), )
sudo -E ./tools/docker_proxy.sh $(PROXY)
sudo -E ./tools/docker_proxy.sh $(PROXY) $(NO_PROXY)
export http_proxy=$(PROXY)
export https_proxy=$(PROXY)
export no_proxy=$(NO_PROXY)

View File

@ -3,8 +3,9 @@
if [ ! -f /etc/systemd/system/docker.service.d/http-proxy.conf ]; then
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo sh -c 'echo "[Service]" > /etc/systemd/system/docker.service.d/http-proxy.conf'
sudo sh -c "echo \"Environment=\\\"HTTP_PROXY=http://$1/\\\"\" >> /etc/systemd/system/docker.service.d/http-proxy.conf"
sudo sh -c "echo \"Environment=\\\"HTTPS_PROXY=http://$1/\\\"\" >> /etc/systemd/system/docker.service.d/http-proxy.conf"
sudo sh -c "echo \"Environment=\\\"HTTP_PROXY=$1\\\"\" >> /etc/systemd/system/docker.service.d/http-proxy.conf"
sudo sh -c "echo \"Environment=\\\"HTTPS_PROXY=$1\\\"\" >> /etc/systemd/system/docker.service.d/http-proxy.conf"
sudo sh -c "echo \"Environment=\\\"NO_PROXY=$2\\\"\" >> /etc/systemd/system/docker.service.d/http-proxy.conf"
sudo systemctl daemon-reload
sudo systemctl restart docker
fi