Skip to content

Commit 60af777

Browse files
authored
Introduce a Dockerfile for running integration tests (#156)
This diff creates Dockerfile.integration for running integration tests with clearly-defined dependencies. Previously the dependencies of the integration tests were defined within the github actions config. The new "make docker_tests" target should work for any developer with Docker installed. Previously there was no single command that would run integration tests across platforms, which makes development and onboarding harder. Even copying the command from github actions wouldn't have worked before, since that command quietly assumed that redis was already running on port 6379. Signed-off-by: David Weitzman <dweitzman@pinterest.com>
1 parent 25e3d14 commit 60af777

File tree

5 files changed

+37
-28
lines changed

5 files changed

+37
-28
lines changed

.github/workflows/master.yaml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,10 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v2
1919

20-
- name: deps
21-
run: sudo apt-get update -y && sudo apt-get install stunnel4 redis -y
22-
2320
- name: build and push docker image
2421
run: |
25-
redis-server --port 6380 &
26-
redis-server --port 6381 --requirepass password123 &
27-
redis-server --port 6382 --requirepass password123 &
28-
redis-server --port 6384 --requirepass password123 &
29-
redis-server --port 6385 --requirepass password123 &
3022
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
31-
make bootstrap bootstrap_redis_tls docker_push
23+
make docker_push
3224
env:
3325
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
3426
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}

.github/workflows/pullrequest.yaml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v2
1818

19-
- name: deps
20-
run: sudo apt-get update -y && sudo apt-get install stunnel4 redis -y
21-
2219
- name: build and test
2320
run: |
24-
redis-server --port 6380 &
25-
redis-server --port 6381 --requirepass password123 &
26-
redis-server --port 6382 --requirepass password123 &
27-
redis-server --port 6384 --requirepass password123 &
28-
redis-server --port 6385 --requirepass password123 &
29-
make bootstrap bootstrap_redis_tls tests_unit tests
21+
make docker_tests

.github/workflows/release.yaml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,10 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v2
1919

20-
- name: deps
21-
run: sudo apt-get update -y && sudo apt-get install stunnel4 redis -y
22-
2320
- name: build and push docker image
2421
run: |
25-
redis-server --port 6380 &
26-
redis-server --port 6381 --requirepass password123 &
27-
redis-server --port 6382 --requirepass password123 &
28-
redis-server --port 6384 --requirepass password123 &
29-
redis-server --port 6385 --requirepass password123 &
3022
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
31-
make bootstrap bootstrap_redis_tls docker_push
23+
make docker_push
3224
env:
3325
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
3426
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}

Dockerfile.integration

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Running this docker image runs the integration tests.
2+
FROM golang:1.14
3+
4+
RUN apt-get update -y && apt-get install sudo stunnel4 redis -y && rm -rf /var/lib/apt/lists/*
5+
6+
WORKDIR /workdir
7+
8+
ENV GOPROXY=https://proxy.golang.org
9+
COPY go.mod go.sum /workdir/
10+
RUN go mod download
11+
12+
COPY Makefile /workdir
13+
RUN make bootstrap
14+
15+
COPY src /workdir/src
16+
COPY test /workdir/test
17+
CMD make tests_with_redis

Makefile

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export GO111MODULE=on
22
PROJECT = ratelimit
33
REGISTRY ?= envoyproxy
44
IMAGE := $(REGISTRY)/$(PROJECT)
5+
INTEGRATION_IMAGE := $(REGISTRY)/$(PROJECT)_integration
56
MODULE = github.com/envoyproxy/ratelimit
67
GIT_REF = $(shell git describe --tags || git rev-parse --short=8 --verify HEAD)
78
VERSION ?= $(GIT_REF)
@@ -70,8 +71,23 @@ tests_unit: compile
7071
tests: compile
7172
go test -race -tags=integration $(MODULE)/...
7273

74+
.PHONY: tests_with_redis
75+
tests_with_redis: bootstrap_redis_tls tests_unit
76+
redis-server --port 6379 &
77+
redis-server --port 6380 &
78+
redis-server --port 6381 --requirepass password123 &
79+
redis-server --port 6382 --requirepass password123 &
80+
redis-server --port 6384 --requirepass password123 &
81+
redis-server --port 6385 --requirepass password123 &
82+
go test -race -tags=integration $(MODULE)/...
83+
84+
.PHONY: docker_tests
85+
docker_tests:
86+
docker build -f Dockerfile.integration . -t $(INTEGRATION_IMAGE):$(VERSION) && \
87+
docker run $$(tty -s && echo "-it" || echo) $(INTEGRATION_IMAGE):$(VERSION)
88+
7389
.PHONY: docker_image
74-
docker_image: tests
90+
docker_image: docker_tests
7591
docker build . -t $(IMAGE):$(VERSION)
7692

7793
.PHONY: docker_push

0 commit comments

Comments
 (0)