Skip to content

Commit 0aa3291

Browse files
committed
Use Docker Compose for tests
1 parent c108338 commit 0aa3291

File tree

6 files changed

+97
-77
lines changed

6 files changed

+97
-77
lines changed

.github/workflows/ci.yml

Lines changed: 9 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
@@ -36,17 +34,14 @@ jobs:
3634
- name: Checkout Repository
3735
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
3836

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-
4237
- name: Switch Repository (Nightly)
4338
if: (github.event_name == 'schedule')
4439
run: |
4540
sed -i 's|pkgs.nginx.com|pkgs-test.nginx.com|g' docker/Dockerfile
4641
sed -i '16d' docker/Dockerfile
4742
sed -i "17i sed -i 's|pkgs|pkgs-test|g' /etc/apt/apt.conf.d/90pkgs-nginx" docker/Dockerfile
4843
sed -i 's|deb https|deb [trusted=yes] https|g' docker/Dockerfile
49-
sed -i 's|\${NGINX_PLUS_VERSION^^}/||g' docker/Dockerfile
44+
sed -i 's|\${NGINX_PLUS_VERSION}/||g' docker/Dockerfile
5045
5146
- name: Set up Docker Buildx
5247
uses: docker/setup-buildx-action@4c0219f9ac95b02789c1075625400b2acbff50b1 # v2.9.1
@@ -55,25 +50,19 @@ jobs:
5550
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4.1.1
5651
with:
5752
file: docker/Dockerfile
58-
context: "docker"
59-
tags: nginx-plus:${{ env.NGINX_PLUS_VERSION }}
53+
tags: nginx-plus
6054
cache-from: type=gha
6155
cache-to: type=gha,mode=max
6256
load: true
6357
secrets: |
6458
"nginx-repo.crt=${{ secrets.NGINX_CRT }}"
6559
"nginx-repo.key=${{ secrets.NGINX_KEY }}"
66-
build-args: NGINX_PLUS_VERSION=${{ env.NGINX_PLUS_VERSION }}
6760
6861
- 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
62+
run: |
63+
docker compose -v
64+
docker compose up -d
65+
docker compose logs -f test-nginx test-client test-no-strea
7766
7867
- name: Create/Update Draft
7968
uses: lucacome/draft-release@f6dc37dcdf44be100a649b72c62c628776750190 # v0.2.2

Makefile

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,19 @@
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: test-all 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)
6+
test-all:
7+
docker compose up -d --build
8+
docker compose logs -f test-nginx test-client test-no-stream
259

2610
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"
35-
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
11+
docker compose up -d --build test-nginx test-client
12+
docker compose logs -f test-nginx test-client
3913

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"
14+
test-run-no-stream-block:
15+
docker compose up -d --build test-no-stream
16+
docker compose logs -f test-no-stream
4917

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

compose.yaml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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-nginx:
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: /bin/sh -c "go test -v -shuffle=on -race client/*"
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-client:
47+
extends:
48+
service: test-nginx
49+
depends_on:
50+
- nginx
51+
- nginx-helper
52+
command: go test -v -shuffle=on -race tests/client_test.go
53+
54+
test-no-stream:
55+
extends:
56+
service: test-nginx
57+
command: go test -v -shuffle=on -race tests/client_no_stream_test.go
58+
depends_on:
59+
- nginx-no-stream
60+
- nginx-helper
61+
environment:
62+
- TEST_API_ENDPOINT=http://nginx-no-stream:8080/api
63+
- TEST_API_ENDPOINT_OF_HELPER=http://nginx-helper:8080/api
64+
- TEST_UNAVAILABLE_STREAM_ADDRESS=nginx-no-stream:8081
65+
66+
secrets:
67+
nginx-repo.crt:
68+
file: ./docker/nginx-repo.crt
69+
nginx-repo.key:
70+
file: ./docker/nginx-repo.key

docker/Dockerfile

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM debian:bullseye-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,24 +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-
# Forward request logs to Docker log collector
28-
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
29-
&& ln -sf /dev/stderr /var/log/nginx/error.log
30-
31-
EXPOSE 80
27+
EXPOSE 8080 8081
3228

3329
STOPSIGNAL SIGQUIT
3430

3531
RUN rm -rf /etc/nginx/conf.d/*
36-
COPY --link test.conf /etc/nginx/conf.d/
37-
COPY --link nginx.conf /etc/nginx/
32+
COPY --link docker/test.conf /etc/nginx/conf.d/
3833

3934
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)