Add proxy options to Makefile docker build

Adds options relating to proxy settings in the Makefile to be used
during the execution of docker build. The settings are optional to be
used and are set up similarly to other Airship projects such as [0] and
[1].

To set proxy settings during docker build, execute the command as
follows:

```
make docker-image \
  -e PROXY=<The proxy URL> \
  -e NO_PROXY=<comma-separated list of URLs/IPs not using the proxy> \
  -e USE_PROXY=true
```

[0] https://opendev.org/airship/pegleg/src/branch/master/Makefile
[1] https://opendev.org/airship/promenade/src/branch/master/Makefile

Change-Id: I92258465d9638b40797d38ba5d8b835fc38df23f
This commit is contained in:
Ian H. Pittwood 2019-12-12 13:03:27 -06:00 committed by Ian Pittwood
parent 358a7e9882
commit 5b7de06eec
1 changed files with 23 additions and 1 deletions

View File

@ -28,6 +28,11 @@ TEST_FLAGS ?=
COVER_FLAGS ?=
COVER_PROFILE ?= cover.out
# proxy options
PROXY ?= http://proxy.foo.com:8000
NO_PROXY ?= localhost,127.0.0.1,.svc.cluster.local
USE_PROXY ?= false
.PHONY: get-modules
get-modules:
@go mod download
@ -67,7 +72,24 @@ tidy:
.PHONY: docker-image
docker-image:
@docker build . --build-arg MAKE_TARGET=$(DOCKER_MAKE_TARGET) --tag $(DOCKER_IMAGE) --target $(DOCKER_TARGET_STAGE)
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) \
--target $(DOCKER_TARGET_STAGE)
else
@docker build . --network=host \
--build-arg MAKE_TARGET=$(DOCKER_MAKE_TARGET) \
--tag $(DOCKER_IMAGE) \
--target $(DOCKER_TARGET_STAGE)
endif
.PHONY: print-docker-image-tag
print-docker-image-tag: