Skip to content

Commit f79a172

Browse files
committed
chore: Dockerize E2E tests
Adds the e2e target to our Makefile which runs our e2e tests as a container. This ensures isolation. The e2e environment has Docker running so we can run docker build and docker push.
1 parent 81a8016 commit f79a172

File tree

5 files changed

+60
-14
lines changed

5 files changed

+60
-14
lines changed

.dockerignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
cf-custom-resources/node_modules
2-
bin
3-
.idea
2+
.idea

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ RUN apt-get update && apt-get install -y nodejs
88
WORKDIR /aws-amazon-ecs-cli-v2
99
COPY . .
1010
RUN go env -w GOPROXY=direct
11-
RUN make release
11+
RUN make release

Makefile

+9-11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ all: build
2323
.PHONY: build
2424
build: packr-build compile-local packr-clean
2525

26+
.PHONY: build-e2e
27+
build-e2e: packr-build compile-linux packr-clean
28+
2629
.PHONY: release
2730
release: packr-build compile-darwin compile-linux compile-windows packr-clean
2831

@@ -99,17 +102,12 @@ run-integ-test:
99102
# and runs tests which end in Integration.
100103
go test -v -count=1 -timeout 60m -tags=integration ${PACKAGES}
101104

102-
.PHONY: e2e-test
103-
e2e-test: build
104-
# the target assumes the AWS-* environment variables are exported
105-
# -p: The number of test binaries that can be run in parallel
106-
# -parallel: Within a single test binary, how many test functions can run in parallel
107-
env -i PATH="$$PATH" GOCACHE=$$(go env GOCACHE) GOPATH=$$(go env GOPATH) GOPROXY=direct \
108-
AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} \
109-
AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} \
110-
AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN} \
111-
AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION} \
112-
go test -v -p 1 -parallel 1 -tags=e2e ./e2e...
105+
.PHONY: e2e
106+
e2e: build-e2e
107+
@echo "Building E2E Docker Image" &&\
108+
docker build -t ecs-cli-v2/e2e . -f e2e/Dockerfile
109+
@echo "Running E2E Tests" &&\
110+
docker run --privileged -it -v ${HOME}/.aws:/home/.aws -e "HOME=/home" ecs-cli-v2/e2e:latest
113111

114112
.PHONY: e2e-test-update-golden-files
115113
e2e-test-update-golden-files:

e2e/Dockerfile

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM golang:1.13
2+
3+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go get -u github.com/onsi/ginkgo/ginkgo && go get -u github.com/onsi/gomega/...
4+
5+
FROM docker:stable-dind
6+
# Docker needs somewhere to put creds from docker login.
7+
RUN wget https://github.com/docker/docker-credential-helpers/releases/download/v0.6.0/docker-credential-pass-v0.6.0-amd64.tar.gz && tar -xf docker-credential-pass-v0.6.0-amd64.tar.gz && chmod +x docker-credential-pass && mv docker-credential-pass /bin
8+
ENV DOCKER_HOST=tcp://127.0.0.1:2375
9+
ENV GOPROXY direct
10+
11+
# Install Go, Git and other dependencies so we can run ginkgo
12+
RUN apk add --no-cache --virtual .build-deps bash gcc musl-dev openssl go git
13+
14+
# Copy the binary
15+
ADD bin/local/ecs-preview-amd64 /bin/ecs-preview
16+
17+
# Add the e2e directory and the project go.mod
18+
ADD e2e/ github.com/aws/amazon-ecs-cli-v2/e2e/
19+
ADD go.mod github.com/aws/amazon-ecs-cli-v2/
20+
ADD go.sum github.com/aws/amazon-ecs-cli-v2/
21+
22+
# Startup script which inits dockerd and then runs the e2e tests
23+
COPY e2e/e2e.sh /bin/
24+
25+
ENTRYPOINT ["/bin/e2e.sh"]

e2e/e2e.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
set -e
3+
# Start dockerd
4+
/usr/local/bin/dockerd \
5+
--host=unix:///var/run/docker.sock \
6+
--host=tcp://127.0.0.1:2375 \
7+
--storage-driver=overlay2 &>/var/log/docker.log &
8+
9+
# Wait until dockerd is spun up
10+
tries=0
11+
d_timeout=60
12+
until docker info >/dev/null 2>&1
13+
do
14+
if [ "$tries" -gt "$d_timeout" ]; then
15+
cat /var/log/docker.log
16+
echo 'Timed out trying to connect to internal docker host.' >&2
17+
exit 1
18+
fi
19+
tries=$(( $tries + 1 ))
20+
sleep 1
21+
done
22+
23+
#Run all the e2e tests
24+
cd /github.com/aws/amazon-ecs-cli-v2/e2e/ && ginkgo -v -r

0 commit comments

Comments
 (0)