Skip to content

Use docker to run helper servers in e2e #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ test: $(BUILD_DIRS)

test-tools:
@docker build -t $(REGISTRY)/test/test-sshd _test_tools/sshd
@docker build -t $(REGISTRY)/test/test-ncsvr _test_tools/ncsvr

# Help set up multi-arch build tools. This assumes you have the tools
# installed. If you already have a buildx builder available, you don't need
Expand Down
25 changes: 25 additions & 0 deletions _test_tools/ncsvr/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Stolen from https://github.com/linuxkit/linuxkit/tree/master/pkg/sshd/

FROM alpine AS base

RUN mkdir -p /out/etc/apk && cp -r /etc/apk/* /out/etc/apk/
RUN apk add --no-cache --initdb -p /out \
alpine-baselayout \
apk-tools \
busybox \
util-linux \
netcat-openbsd \
&& true

###############

FROM scratch

ENTRYPOINT []
WORKDIR /

COPY --from=base /out/ /

COPY ncsvr.sh /

ENTRYPOINT ["/ncsvr.sh"]
38 changes: 38 additions & 0 deletions _test_tools/ncsvr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# A simple server for tests

DO NOT USE THIS FOR ANYTHING BUT TESTING!!!

## How to use it

Build yourself a test image. We use example.com so you can't accidentally push
it.

```
$ docker build -t example.com/test/test-ncvsr .
...lots of output...
Successfully tagged example.com/test/test-ncsvr:latest
```

Run it.

```
$ docker run -d example.com/test/test-ncsvr 9376 "echo hello"
6d05b4111b03c66907031e3cd7587763f0e4fab6c50fac33c4a8284732b448ae
```

Find your IP.

```
$ docker inspect 6d05b4111b03c66907031e3cd7587763f0e4fab6c50fac33c4a8284732b448ae | jq -r .[0].NetworkSettings.IPAddress
192.168.1.2
```

Connect to it.

```
$ echo "" | nc 192.168.9.2 9376
hello
```

If you want to know how many times it was accessed, mount a file on
/var/log/hits. This will log one line per hit.
11 changes: 11 additions & 0 deletions _test_tools/ncsvr/ncsvr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

if [ -z "$1" -o -z "$2" ]; then
echo "usage: $0 <port> <shell-command>"
exit 1
fi

while true; do
sh -c "$2" | nc -l -p "$1" -N -w0 >/dev/null
date >> /var/log/hits
done
Loading