Skip to content

Commit 22fc11b

Browse files
authored
Use Docker Compose for tests (#152)
1 parent 91d142e commit 22fc11b

File tree

6 files changed

+107
-74
lines changed

6 files changed

+107
-74
lines changed

.github/workflows/ci.yml

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ on:
1212
schedule:
1313
- cron: "0 5 * * *" # runs every day at 5am UTC
1414

15-
env:
16-
DOCKER_NETWORK: ${{ github.run_id }}
17-
DOCKER_NETWORK_ALIAS: nginx-plus-test
18-
DOCKER_NGINX_PLUS: nginx-plus-${{ github.run_id }}
19-
DOCKER_NGINX_PLUS_HELPER: nginx-plus-helper-${{ github.run_id }}
15+
defaults:
16+
run:
17+
shell: bash
2018

2119
concurrency:
2220
group: ${{ github.ref_name }}-ci
@@ -26,6 +24,25 @@ permissions:
2624
contents: read
2725

2826
jobs:
27+
unit-test:
28+
name: Unit Test
29+
runs-on: ubuntu-22.04
30+
permissions:
31+
contents: read
32+
strategy:
33+
matrix:
34+
go-version: ["1.19", "1.20", "1.21"]
35+
steps:
36+
- name: Checkout Repository
37+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
38+
39+
- name: Setup Golang Environment
40+
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
41+
with:
42+
go-version: ${{ matrix.go-version }}
43+
44+
- name: Run Unit Tests
45+
run: make unit-test
2946
build:
3047
name: Build Client
3148
runs-on: ubuntu-22.04
@@ -36,17 +53,14 @@ jobs:
3653
- name: Checkout Repository
3754
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
3855

39-
- name: Determine NGINX Plus version
40-
run: echo "NGINX_PLUS_VERSION=$(cat Makefile | grep -m1 NGINX_PLUS_VERSION | cut -d "=" -f2)" >> $GITHUB_ENV
41-
4256
- name: Switch Repository (Nightly)
4357
if: (github.event_name == 'schedule')
4458
run: |
4559
sed -i 's|pkgs.nginx.com|pkgs-test.nginx.com|g' docker/Dockerfile
4660
sed -i '16d' docker/Dockerfile
4761
sed -i "17i sed -i 's|pkgs|pkgs-test|g' /etc/apt/apt.conf.d/90pkgs-nginx" docker/Dockerfile
4862
sed -i 's|deb https|deb [trusted=yes] https|g' docker/Dockerfile
49-
sed -i 's|\${NGINX_PLUS_VERSION^^}/||g' docker/Dockerfile
63+
sed -i 's|\${NGINX_PLUS_VERSION}/||g' docker/Dockerfile
5064
5165
- name: Set up Docker Buildx
5266
uses: docker/setup-buildx-action@4c0219f9ac95b02789c1075625400b2acbff50b1 # v2.9.1
@@ -55,25 +69,18 @@ jobs:
5569
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4.1.1
5670
with:
5771
file: docker/Dockerfile
58-
context: "docker"
59-
tags: nginx-plus:${{ env.NGINX_PLUS_VERSION }}
72+
tags: nginx-plus
6073
cache-from: type=gha
6174
cache-to: type=gha,mode=max
6275
load: true
6376
secrets: |
6477
"nginx-repo.crt=${{ secrets.NGINX_CRT }}"
6578
"nginx-repo.key=${{ secrets.NGINX_KEY }}"
66-
build-args: NGINX_PLUS_VERSION=${{ env.NGINX_PLUS_VERSION }}
6779
6880
- name: Test Client
69-
if: (github.event_name != 'schedule')
70-
run: make test
71-
72-
- name: Test Client (Nightly)
73-
if: (github.event_name == 'schedule')
74-
run: make test
75-
env:
76-
NGINX_PLUS_VERSION: nightly
81+
run: |
82+
docker compose up -d
83+
docker compose logs -f test test-no-stream
7784
7885
- name: Create/Update Draft
7986
uses: lucacome/draft-release@f6dc37dcdf44be100a649b72c62c628776750190 # v0.2.2

Makefile

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,18 @@
1-
NGINX_PLUS_VERSION=r30
2-
DOCKER_NETWORK?=test
3-
DOCKER_NETWORK_ALIAS=nginx-plus-test
4-
DOCKER_NGINX_PLUS?=nginx-plus
5-
DOCKER_NGINX_PLUS_HELPER?=nginx-plus-helper
6-
7-
GOLANG_CONTAINER=golang:1.19
8-
9-
export TEST_API_ENDPOINT=http://$(DOCKER_NGINX_PLUS):8080/api
10-
export TEST_API_ENDPOINT_OF_HELPER=http://$(DOCKER_NGINX_PLUS_HELPER):8080/api
11-
export TEST_UNAVAILABLE_STREAM_ADDRESS=$(DOCKER_NGINX_PLUS):8081
12-
13-
test: run-nginx-plus test-run configure-no-stream-block test-run-no-stream-block clean
1+
test: unit-test test-integration test-integration-no-stream-block clean
142

153
lint:
164
docker run --pull always --rm -v $(shell pwd):/nginx-plus-go-client -w /nginx-plus-go-client -v $(shell go env GOCACHE):/cache/go -e GOCACHE=/cache/go -e GOLANGCI_LINT_CACHE=/cache/go -v $(shell go env GOPATH)/pkg:/go/pkg golangci/golangci-lint:latest golangci-lint --color always run
175

18-
docker-build:
19-
docker build --secret id=nginx-repo.crt,src=docker/nginx-repo.crt --secret id=nginx-repo.key,src=docker/nginx-repo.key --build-arg NGINX_PLUS_VERSION=$(NGINX_PLUS_VERSION) -t nginx-plus:$(NGINX_PLUS_VERSION) docker
20-
21-
run-nginx-plus:
22-
docker network create --driver bridge $(DOCKER_NETWORK)
23-
docker run --network=$(DOCKER_NETWORK) -d --name $(DOCKER_NGINX_PLUS) --network-alias=$(DOCKER_NETWORK_ALIAS) --rm -p 8080:8080 -p 8081:8081 nginx-plus:$(NGINX_PLUS_VERSION)
24-
docker run --network=$(DOCKER_NETWORK) -d --name $(DOCKER_NGINX_PLUS_HELPER) --network-alias=$(DOCKER_NETWORK_ALIAS) --rm -p 8090:8080 -p 8091:8081 nginx-plus:$(NGINX_PLUS_VERSION)
25-
26-
test-run:
27-
docker run --rm \
28-
--network=$(DOCKER_NETWORK) \
29-
-e TEST_API_ENDPOINT \
30-
-e TEST_API_ENDPOINT_OF_HELPER \
31-
-e TEST_UNAVAILABLE_STREAM_ADDRESS \
32-
-v $(shell pwd):/go/src/github.com/nginxinc/nginx-plus-go-client \
33-
-w /go/src/github.com/nginxinc/nginx-plus-go-client \
34-
$(GOLANG_CONTAINER) /bin/sh -c "go test client/*; go clean -testcache; go test tests/client_test.go"
6+
unit-test:
7+
go test -v -shuffle=on -race client/*.go
358

36-
configure-no-stream-block:
37-
docker cp docker/nginx_no_stream.conf $(DOCKER_NGINX_PLUS):/etc/nginx/nginx.conf
38-
docker exec $(DOCKER_NGINX_PLUS) nginx -s reload
9+
test-integration:
10+
docker compose up -d --build test
11+
docker compose logs -f test
3912

40-
test-run-no-stream-block: configure-no-stream-block
41-
docker run --rm \
42-
--network=$(DOCKER_NETWORK) \
43-
-e TEST_API_ENDPOINT \
44-
-e TEST_API_ENDPOINT_OF_HELPER \
45-
-e TEST_UNAVAILABLE_STREAM_ADDRESS \
46-
-v $(shell pwd):/go/src/github.com/nginxinc/nginx-plus-go-client \
47-
-w /go/src/github.com/nginxinc/nginx-plus-go-client \
48-
$(GOLANG_CONTAINER) /bin/sh -c "go clean -testcache; go test tests/client_no_stream_test.go"
13+
test-integration-no-stream-block:
14+
docker compose up -d --build test-no-stream
15+
docker compose logs -f test-no-stream
4916

5017
clean:
51-
-docker kill $(DOCKER_NGINX_PLUS)
52-
-docker kill $(DOCKER_NGINX_PLUS_HELPER)
53-
-docker network rm $(DOCKER_NETWORK)
18+
docker compose down --remove-orphans

compose.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
services:
2+
nginx:
3+
image: nginx-plus
4+
build:
5+
dockerfile: docker/Dockerfile
6+
secrets:
7+
- nginx-repo.crt
8+
- nginx-repo.key
9+
volumes:
10+
- type: bind
11+
source: ./docker/nginx.conf
12+
target: /etc/nginx/nginx.conf
13+
networks:
14+
default:
15+
aliases:
16+
- nginx-plus-test
17+
18+
nginx-no-stream:
19+
extends:
20+
service: nginx
21+
volumes:
22+
- type: bind
23+
source: ./docker/nginx_no_stream.conf
24+
target: /etc/nginx/nginx.conf
25+
26+
nginx-helper:
27+
extends:
28+
service: nginx
29+
30+
test:
31+
image: golang:1.21
32+
volumes:
33+
- type: bind
34+
source: ./
35+
target: /go/src/github.com/nginxinc/nginx-plus-go-client
36+
working_dir: /go/src/github.com/nginxinc/nginx-plus-go-client
37+
command: go test -v -shuffle=on -race tests/client_test.go
38+
depends_on:
39+
- nginx
40+
- nginx-helper
41+
environment:
42+
- TEST_API_ENDPOINT=http://nginx:8080/api
43+
- TEST_API_ENDPOINT_OF_HELPER=http://nginx-helper:8080/api
44+
- TEST_UNAVAILABLE_STREAM_ADDRESS=nginx:8081
45+
46+
test-no-stream:
47+
extends:
48+
service: test
49+
command: go test -v -shuffle=on -race tests/client_no_stream_test.go
50+
depends_on:
51+
- nginx-no-stream
52+
- nginx-helper
53+
environment:
54+
- TEST_API_ENDPOINT=http://nginx-no-stream:8080/api
55+
- TEST_API_ENDPOINT_OF_HELPER=http://nginx-helper:8080/api
56+
- TEST_UNAVAILABLE_STREAM_ADDRESS=nginx-no-stream:8081
57+
58+
secrets:
59+
nginx-repo.crt:
60+
file: ./docker/nginx-repo.crt
61+
nginx-repo.key:
62+
file: ./docker/nginx-repo.key

docker/Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM debian:12-slim
33

44
LABEL maintainer="NGINX Docker Maintainers <integrations@nginx.com>"
55

6-
ARG NGINX_PLUS_VERSION
6+
ARG NGINX_PLUS_VERSION=R30
77

88
# Install NGINX Plus
99
# Download certificate and key from the customer portal (https://my.f5.com)
@@ -16,20 +16,19 @@ RUN --mount=type=secret,id=nginx-repo.crt,dst=/etc/ssl/nginx/nginx-repo.crt,mode
1616
curl -fsSL https://cs.nginx.com/static/keys/nginx_signing.key | gpg --dearmor > /etc/apt/trusted.gpg.d/nginx_signing.gpg
1717
curl -fsSL -o /etc/apt/apt.conf.d/90pkgs-nginx https://cs.nginx.com/static/files/90pkgs-nginx
1818
DEBIAN_VERSION=$(awk -F '=' '/^VERSION_CODENAME=/ {print $2}' /etc/os-release)
19-
printf "%s\n" "deb https://pkgs.nginx.com/plus/${NGINX_PLUS_VERSION^^}/debian ${DEBIAN_VERSION} nginx-plus" > /etc/apt/sources.list.d/nginx-plus.list
19+
printf "%s\n" "deb https://pkgs.nginx.com/plus/${NGINX_PLUS_VERSION}/debian ${DEBIAN_VERSION} nginx-plus" > /etc/apt/sources.list.d/nginx-plus.list
2020
apt-get update
2121
apt-get install -y nginx-plus
2222
apt-get remove --purge --auto-remove -y gnupg
2323
rm -rf /var/lib/apt/lists/*
2424
rm /etc/apt/apt.conf.d/90pkgs-nginx /etc/apt/sources.list.d/nginx-plus.list
2525
eot
2626

27-
EXPOSE 80
27+
EXPOSE 8080 8081
2828

2929
STOPSIGNAL SIGQUIT
3030

3131
RUN rm -rf /etc/nginx/conf.d/*
32-
COPY --link test.conf /etc/nginx/conf.d/
33-
COPY --link nginx.conf /etc/nginx/
32+
COPY --link docker/test.conf /etc/nginx/conf.d/
3433

3534
CMD ["nginx", "-g", "daemon off;"]

docker/nginx.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
user nginx;
33
worker_processes auto;
44

5-
error_log /var/log/nginx/error.log notice;
5+
error_log stderr notice;
66
pid /var/run/nginx.pid;
77

88

@@ -19,7 +19,7 @@ http {
1919
'$status $body_bytes_sent "$http_referer" '
2020
'"$http_user_agent" "$http_x_forwarded_for"';
2121

22-
access_log /var/log/nginx/access.log main;
22+
access_log /dev/stdout main;
2323

2424
sendfile on;
2525
#tcp_nopush on;

docker/nginx_no_stream.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
user nginx;
33
worker_processes auto;
44

5-
error_log /var/log/nginx/error.log notice;
5+
error_log stderr notice;
66
pid /var/run/nginx.pid;
77

88

@@ -19,7 +19,7 @@ http {
1919
'$status $body_bytes_sent "$http_referer" '
2020
'"$http_user_agent" "$http_x_forwarded_for"';
2121

22-
access_log /var/log/nginx/access.log main;
22+
access_log /dev/stdout main;
2323

2424
sendfile on;
2525
#tcp_nopush on;

0 commit comments

Comments
 (0)