Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/bin
/.go
/.push-*
/.buildx-initialized
/.container-*
/.dockerfile-*
/.buildx-initialized
/.go
/.idea
/.licenses
/.push-*
/bin
56 changes: 56 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,59 @@ make all-container \
BUILD_IMAGE=$BUILD_IMAGE_IN_PRIVATE_REGISTRY \
BASEIMAGE=$BASEIMAGE_IN_PRIVATE_REGISTRY
```

## Running end-to-end tests using fully-qualified base images

By default the `_test_tools/*/Dockerfile` images used by the end-to-end tests are built in the `Makefile`'s `.container-test_tool.%` goals
using an unqualified `alpine` image.

In order to pull the `alpine` image from a private registry and/or with a fully-qualified name, and run the tests, you can
use for example:

```sh
docker login $YOUR_PRIVATE_REGISTRY
ALPINE_REGISTRY_PREFIX=$YOUR_PRIVATE_REGISTRY/$YOUR_ALPINE_NAMESPACE_PREFIX/ # Please note the final '/'
docker pull ${ALPINE_REGISTRY_PREFIX}alpine
make test ALPINE_REGISTRY_PREFIX=$ALPINE_REGISTRY_PREFIX
```

## Running end-to-end tests locally with docker configured behind a proxy

If you are using proxy configurations in your `~/.docker/config` file, you must add the `docker0` subnet (created by the
*bridge* network) as an exception in order for the containers executed by the tests to be able to call each other.

For example to get the subnets associated with the *bridge* network in a default Docker configuration you can run:

```bash
docker network ls # you can verify that a network called bridge is present
docker network inspect bridge --format '{{ range .IPAM.Config }}{{ .Subnet }}{{ end }}'
```

If for example your *bridge* subnet is `172.16.0.0/12`, then you'd want your `~/.docker/config.json` to look like this:

```json
{
"proxies": {
"default": {
"httpProxy": "...",
"httpsProxy": "...",
"noProxy": "...,172.16.0.0/12"
}
}
}
```

And you'd want to run the tests like this:

```bash
make test HTTP_PROXY="..." HTTPS_PROXY="..." NO_PROXY"...,172.16.0.0/12"
```

Or manually:

```bash
export HTTP_PROXY="..."
export HTTPS_PROXY="..."
export NO_PROXY"...,172.16.0.0/12"
VERBOSE=1 ./test_e2e.sh
```
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ DBG ?=
# These are passed to docker when building and testing.
HTTP_PROXY ?=
HTTPS_PROXY ?=
NO_PROXY ?=

# Allow some buildx adaptation for local builds
BUILDX_BUILDER_NAME := git-sync
BUILDX_BUILDER_SKIP_CREATION ?=

# Allow alpine to be pulled from a private registry when building the end-to-end tests images
ALPINE_REGISTRY_PREFIX ?=

###
### These variables should not need tweaking.
###
Expand Down Expand Up @@ -134,6 +138,7 @@ $(OUTBIN): .go/$(OUTBIN).stamp
-v $$(pwd)/.go/cache:/.cache \
--env HTTP_PROXY=$(HTTP_PROXY) \
--env HTTPS_PROXY=$(HTTPS_PROXY) \
--env NO_PROXY=$(NO_PROXY) \
$(BUILD_IMAGE) \
/bin/sh -c " \
ARCH=$(ARCH) \
Expand Down Expand Up @@ -190,6 +195,7 @@ container: .container-$(DOTFILE_IMAGE) container-name
--platform "$(OS)/$(ARCH)" \
--build-arg HTTP_PROXY=$(HTTP_PROXY) \
--build-arg HTTPS_PROXY=$(HTTPS_PROXY) \
--build-arg NO_PROXY=$(NO_PROXY) \
-t $(IMAGE):$(OS_ARCH_TAG) \
-f .dockerfile-$(OS)_$(ARCH) \
.
Expand Down Expand Up @@ -248,17 +254,27 @@ test: $(BUILD_DIRS)
-v $$(pwd)/.go/cache:/.cache \
--env HTTP_PROXY=$(HTTP_PROXY) \
--env HTTPS_PROXY=$(HTTPS_PROXY) \
--env NO_PROXY=$(NO_PROXY) \
$(BUILD_IMAGE) \
/bin/sh -c " \
./build/test.sh ./... \
"
@if [ -n "$(HTTP_PROXY)" ]; then \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this do anything? Each of these blocks runs in its own shell, so export has no meaning:

thockin@thockin-glaptop4:/tmp/m$ cat Makefile 
foo:
	@export FOO=bar
	@echo $$FOO

bar:
	@export FOO=bar; \
	echo $$FOO
thockin@thockin-glaptop4:/tmp/m$ make foo

thockin@thockin-glaptop4:/tmp/m$ make bar
bar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad. Let me add a commit to fix this.

I think someone who uses a proxy will have all three variables already configured in a dotenv file or profile, expecting the NO_PROXY standard variable to be passed alongside the two others. It looks strange when this one is not. So the goal here was to be consistent (and not having to debug why something will be routed through the proxy when the user's config contains an exclusion, for example: the private/local images registries, or the github project's local mirror).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with setting the variables for subprocesses. I don't understand what this specific change is doing.

If I apply this delta:

diff --git Makefile Makefile
index 4b1a9c0..3348685 100644
--- Makefile
+++ Makefile
@@ -278,6 +278,9 @@ test: $(BUILD_DIRS)
 	fi
 	VERBOSE=1 ./test_e2e.sh $(LIST_OF_E2E_TESTS)
 
+foo:
+	echo $$HTTP_PROXY $$HTTPS_PROXY $$NO_PROXY
+
 TEST_TOOLS := $(shell find _test_tools/* -type d -printf "%f ")
 test-tools: $(foreach tool, $(TEST_TOOLS), .container-test_tool.$(tool))
 

Here's what I see:

$ HTTP_PROXY=123 HTTPS_PROXY=456 NO_PROXY=789 make foo
123 456 789
$ make foo HTTP_PROXY=123 HTTPS_PROXY=456 NO_PROXY=789
123 456 789
$ sh -c "export HTTP_PROXY=123; export HTTPS_PROXY=456; export NO_PROXY=789; make foo"
123 456 789

In all 3 cases the variable are already passed down. Moreover, if I copy this pattern you have:

diff --git Makefile Makefile
index 4b1a9c0..1212d2f 100644
--- Makefile
+++ Makefile
@@ -278,6 +278,18 @@ test: $(BUILD_DIRS)
 	fi
 	VERBOSE=1 ./test_e2e.sh $(LIST_OF_E2E_TESTS)
 
+foo:
+	@if [ -n "$(HTTP_PROXY)" ]; then \
+		export HTTP_PROXY="111 $(HTTP_PROXY)"; \
+	fi
+	@if [ -n "$(HTTPS_PROXY)" ]; then \
+		export HTTPS_PROXY="222 $(HTTPS_PROXY)"; \
+	fi
+	@if [ -n "$(NO_PROXY)" ]; then \
+		export NO_PROXY="333 $(NO_PROXY)"; \
+	fi
+	echo $$HTTP_PROXY $$HTTPS_PROXY $$NO_PROXY
+
 TEST_TOOLS := $(shell find _test_tools/* -type d -printf "%f ")
 test-tools: $(foreach tool, $(TEST_TOOLS), .container-test_tool.$(tool))
 

I get:

$ HTTP_PROXY=123 HTTPS_PROXY=456 NO_PROXY=789 make foo
123 456 789
$ HTTP_PROXY=123 HTTPS_PROXY=456 NO_PROXY=789 make foo
123 456 789
$ sh -c "export HTTP_PROXY=123; export HTTPS_PROXY=456; export NO_PROXY=789; make foo"
123 456 789

The change you made to this rule doesn't DO anything. What problem spurred you to make this specific piece of the change?

export HTTP_PROXY="$(HTTP_PROXY)"; \
fi
@if [ -n "$(HTTPS_PROXY)" ]; then \
export HTTPS_PROXY="$(HTTPS_PROXY)"; \
fi
@if [ -n "$(NO_PROXY)" ]; then \
export NO_PROXY="$(NO_PROXY)"; \
fi
VERBOSE=1 ./test_e2e.sh

TEST_TOOLS := $(shell find _test_tools/* -type d -printf "%f ")
test-tools: $(foreach tool, $(TEST_TOOLS), .container-test_tool.$(tool))

.container-test_tool.%: _test_tools/% _test_tools/%/*
docker build -t $(REGISTRY)/test/$$(basename $<) $<
docker build --build-arg ALPINE_REGISTRY_PREFIX="$(ALPINE_REGISTRY_PREFIX)" -t $(REGISTRY)/test/$$(basename $<) $<
docker images -q $(REGISTRY)/test/$$(basename $<) > $@

# Help set up multi-arch build tools. This assumes you have the tools
Expand Down
3 changes: 2 additions & 1 deletion _test_tools/httpd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

# Stolen from https://github.com/linuxkit/linuxkit/tree/master/pkg/sshd/

FROM alpine AS base
ARG ALPINE_REGISTRY_PREFIX=""
FROM ${ALPINE_REGISTRY_PREFIX}alpine AS base

RUN mkdir -p /out/etc/apk && cp -r /etc/apk/* /out/etc/apk/
RUN apk add --no-cache --initdb -p /out \
Expand Down
3 changes: 2 additions & 1 deletion _test_tools/ncsvr/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

# Stolen from https://github.com/linuxkit/linuxkit/tree/master/pkg/sshd/

FROM alpine AS base
ARG ALPINE_REGISTRY_PREFIX=""
FROM ${ALPINE_REGISTRY_PREFIX}alpine AS base

RUN mkdir -p /out/etc/apk && cp -r /etc/apk/* /out/etc/apk/
RUN apk add --no-cache --initdb -p /out \
Expand Down
3 changes: 2 additions & 1 deletion _test_tools/sshd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

# Stolen from https://github.com/linuxkit/linuxkit/tree/master/pkg/sshd/

FROM alpine AS base
ARG ALPINE_REGISTRY_PREFIX=""
FROM ${ALPINE_REGISTRY_PREFIX}alpine AS base

RUN mkdir -p /out/etc/apk && cp -r /etc/apk/* /out/etc/apk/
RUN apk add --no-cache --initdb -p /out \
Expand Down
6 changes: 6 additions & 0 deletions test_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ set -o errexit
set -o nounset
set -o pipefail

# If the Makefile and/or the user do set up the upper-case flavor of a proxy variable,
# then let us also set up the lower-case flavor that is used by tools like the git CLI.
[ -n "${HTTP_PROXY:-}" ] && export http_proxy="$HTTP_PROXY"
[ -n "${HTTPS_PROXY:-}" ] && export https_proxy="$HTTPS_PROXY"
[ -n "${NO_PROXY:-}" ] && export no_proxy="$NO_PROXY"

# shellcheck disable=SC2120
function caller() {
local stack_skip=${1:-0}
Expand Down