Skip to content

Commit

Permalink
Introduce a Dockerfile for running integration tests (envoyproxy#156)
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Diego Erdody <diego@medallia.com>
  • Loading branch information
dweitzman authored and Diego Erdody committed Sep 24, 2020
1 parent af7b234 commit 6e8dda7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 28 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,10 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: deps
run: sudo apt-get update -y && sudo apt-get install stunnel4 redis -y

- name: build and push docker image
run: |
redis-server --port 6380 &
redis-server --port 6381 --requirepass password123 &
redis-server --port 6382 --requirepass password123 &
redis-server --port 6384 --requirepass password123 &
redis-server --port 6385 --requirepass password123 &
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
make bootstrap bootstrap_redis_tls docker_push
make docker_push
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
Expand Down
10 changes: 1 addition & 9 deletions .github/workflows/pullrequest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: deps
run: sudo apt-get update -y && sudo apt-get install stunnel4 redis -y

- name: build and test
run: |
redis-server --port 6380 &
redis-server --port 6381 --requirepass password123 &
redis-server --port 6382 --requirepass password123 &
redis-server --port 6384 --requirepass password123 &
redis-server --port 6385 --requirepass password123 &
make bootstrap bootstrap_redis_tls tests_unit tests
make docker_tests
10 changes: 1 addition & 9 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,10 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: deps
run: sudo apt-get update -y && sudo apt-get install stunnel4 redis -y

- name: build and push docker image
run: |
redis-server --port 6380 &
redis-server --port 6381 --requirepass password123 &
redis-server --port 6382 --requirepass password123 &
redis-server --port 6384 --requirepass password123 &
redis-server --port 6385 --requirepass password123 &
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
make bootstrap bootstrap_redis_tls docker_push
make docker_push
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
17 changes: 17 additions & 0 deletions Dockerfile.integration
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Running this docker image runs the integration tests.
FROM golang:1.14

RUN apt-get update -y && apt-get install sudo stunnel4 redis -y && rm -rf /var/lib/apt/lists/*

WORKDIR /workdir

ENV GOPROXY=https://proxy.golang.org
COPY go.mod go.sum /workdir/
RUN go mod download

COPY Makefile /workdir
RUN make bootstrap

COPY src /workdir/src
COPY test /workdir/test
CMD make tests_with_redis
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export GO111MODULE=on
PROJECT = ratelimit
REGISTRY ?= envoyproxy
IMAGE := $(REGISTRY)/$(PROJECT)
INTEGRATION_IMAGE := $(REGISTRY)/$(PROJECT)_integration
MODULE = github.com/envoyproxy/ratelimit
GIT_REF = $(shell git describe --tags || git rev-parse --short=8 --verify HEAD)
VERSION ?= $(GIT_REF)
Expand Down Expand Up @@ -70,8 +71,23 @@ tests_unit: compile
tests: compile
go test -race -tags=integration $(MODULE)/...

.PHONY: tests_with_redis
tests_with_redis: bootstrap_redis_tls tests_unit
redis-server --port 6379 &
redis-server --port 6380 &
redis-server --port 6381 --requirepass password123 &
redis-server --port 6382 --requirepass password123 &
redis-server --port 6384 --requirepass password123 &
redis-server --port 6385 --requirepass password123 &
go test -race -tags=integration $(MODULE)/...

.PHONY: docker_tests
docker_tests:
docker build -f Dockerfile.integration . -t $(INTEGRATION_IMAGE):$(VERSION) && \
docker run $$(tty -s && echo "-it" || echo) $(INTEGRATION_IMAGE):$(VERSION)

.PHONY: docker_image
docker_image: tests
docker_image: docker_tests
docker build . -t $(IMAGE):$(VERSION)

.PHONY: docker_push
Expand Down

0 comments on commit 6e8dda7

Please sign in to comment.