Skip to content

Commit

Permalink
Use Docker Compose for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome committed Aug 16, 2023
1 parent c108338 commit 717cc31
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 77 deletions.
28 changes: 8 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ on:
schedule:
- cron: "0 5 * * *" # runs every day at 5am UTC

env:
DOCKER_NETWORK: ${{ github.run_id }}
DOCKER_NETWORK_ALIAS: nginx-plus-test
DOCKER_NGINX_PLUS: nginx-plus-${{ github.run_id }}
DOCKER_NGINX_PLUS_HELPER: nginx-plus-helper-${{ github.run_id }}
defaults:
run:
shell: bash

concurrency:
group: ${{ github.ref_name }}-ci
Expand All @@ -36,17 +34,14 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

- name: Determine NGINX Plus version
run: echo "NGINX_PLUS_VERSION=$(cat Makefile | grep -m1 NGINX_PLUS_VERSION | cut -d "=" -f2)" >> $GITHUB_ENV

- name: Switch Repository (Nightly)
if: (github.event_name == 'schedule')
run: |
sed -i 's|pkgs.nginx.com|pkgs-test.nginx.com|g' docker/Dockerfile
sed -i '16d' docker/Dockerfile
sed -i "17i sed -i 's|pkgs|pkgs-test|g' /etc/apt/apt.conf.d/90pkgs-nginx" docker/Dockerfile
sed -i 's|deb https|deb [trusted=yes] https|g' docker/Dockerfile
sed -i 's|\${NGINX_PLUS_VERSION^^}/||g' docker/Dockerfile
sed -i 's|\${NGINX_PLUS_VERSION}/||g' docker/Dockerfile
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@4c0219f9ac95b02789c1075625400b2acbff50b1 # v2.9.1
Expand All @@ -55,25 +50,18 @@ jobs:
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4.1.1
with:
file: docker/Dockerfile
context: "docker"
tags: nginx-plus:${{ env.NGINX_PLUS_VERSION }}
tags: nginx-plus
cache-from: type=gha
cache-to: type=gha,mode=max
load: true
secrets: |
"nginx-repo.crt=${{ secrets.NGINX_CRT }}"
"nginx-repo.key=${{ secrets.NGINX_KEY }}"
build-args: NGINX_PLUS_VERSION=${{ env.NGINX_PLUS_VERSION }}
- name: Test Client
if: (github.event_name != 'schedule')
run: make test

- name: Test Client (Nightly)
if: (github.event_name == 'schedule')
run: make test
env:
NGINX_PLUS_VERSION: nightly
run: |
docker compose up -d
docker compose logs -f test-nginx test-client test-no-stream
- name: Create/Update Draft
uses: lucacome/draft-release@f6dc37dcdf44be100a649b72c62c628776750190 # v0.2.2
Expand Down
54 changes: 10 additions & 44 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,53 +1,19 @@
NGINX_PLUS_VERSION=r30
DOCKER_NETWORK?=test
DOCKER_NETWORK_ALIAS=nginx-plus-test
DOCKER_NGINX_PLUS?=nginx-plus
DOCKER_NGINX_PLUS_HELPER?=nginx-plus-helper

GOLANG_CONTAINER=golang:1.19

export TEST_API_ENDPOINT=http://$(DOCKER_NGINX_PLUS):8080/api
export TEST_API_ENDPOINT_OF_HELPER=http://$(DOCKER_NGINX_PLUS_HELPER):8080/api
export TEST_UNAVAILABLE_STREAM_ADDRESS=$(DOCKER_NGINX_PLUS):8081

test: run-nginx-plus test-run configure-no-stream-block test-run-no-stream-block clean
test: test-all clean

lint:
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

docker-build:
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

run-nginx-plus:
docker network create --driver bridge $(DOCKER_NETWORK)
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)
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)
test-all:
docker compose up -d --build
docker compose logs -f test-nginx test-client test-no-stream

test-run:
docker run --rm \
--network=$(DOCKER_NETWORK) \
-e TEST_API_ENDPOINT \
-e TEST_API_ENDPOINT_OF_HELPER \
-e TEST_UNAVAILABLE_STREAM_ADDRESS \
-v $(shell pwd):/go/src/github.com/nginxinc/nginx-plus-go-client \
-w /go/src/github.com/nginxinc/nginx-plus-go-client \
$(GOLANG_CONTAINER) /bin/sh -c "go test client/*; go clean -testcache; go test tests/client_test.go"

configure-no-stream-block:
docker cp docker/nginx_no_stream.conf $(DOCKER_NGINX_PLUS):/etc/nginx/nginx.conf
docker exec $(DOCKER_NGINX_PLUS) nginx -s reload
docker compose up -d --build test-nginx test-client
docker compose logs -f test-nginx test-client

test-run-no-stream-block: configure-no-stream-block
docker run --rm \
--network=$(DOCKER_NETWORK) \
-e TEST_API_ENDPOINT \
-e TEST_API_ENDPOINT_OF_HELPER \
-e TEST_UNAVAILABLE_STREAM_ADDRESS \
-v $(shell pwd):/go/src/github.com/nginxinc/nginx-plus-go-client \
-w /go/src/github.com/nginxinc/nginx-plus-go-client \
$(GOLANG_CONTAINER) /bin/sh -c "go clean -testcache; go test tests/client_no_stream_test.go"
test-run-no-stream-block:
docker compose up -d --build test-no-stream
docker compose logs -f test-no-stream

clean:
-docker kill $(DOCKER_NGINX_PLUS)
-docker kill $(DOCKER_NGINX_PLUS_HELPER)
-docker network rm $(DOCKER_NETWORK)
docker compose down --remove-orphans
70 changes: 70 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
services:
nginx:
image: nginx-plus
build:
dockerfile: docker/Dockerfile
secrets:
- nginx-repo.crt
- nginx-repo.key
volumes:
- type: bind
source: ./docker/nginx.conf
target: /etc/nginx/nginx.conf
networks:
default:
aliases:
- nginx-plus-test

nginx-no-stream:
extends:
service: nginx
volumes:
- type: bind
source: ./docker/nginx_no_stream.conf
target: /etc/nginx/nginx.conf

nginx-helper:
extends:
service: nginx

test-nginx:
image: golang:1.21
volumes:
- type: bind
source: ./
target: /go/src/github.com/nginxinc/nginx-plus-go-client
working_dir: /go/src/github.com/nginxinc/nginx-plus-go-client
command: /bin/sh -c "go test -v -shuffle=on -race client/*"
depends_on:
- nginx
- nginx-helper
environment:
- TEST_API_ENDPOINT=http://nginx:8080/api
- TEST_API_ENDPOINT_OF_HELPER=http://nginx-helper:8080/api
- TEST_UNAVAILABLE_STREAM_ADDRESS=nginx:8081

test-client:
extends:
service: test-nginx
depends_on:
- nginx
- nginx-helper
command: go test -v -shuffle=on -race tests/client_test.go

test-no-stream:
extends:
service: test-nginx
command: go test -v -shuffle=on -race tests/client_no_stream_test.go
depends_on:
- nginx-no-stream
- nginx-helper
environment:
- TEST_API_ENDPOINT=http://nginx-no-stream:8080/api
- TEST_API_ENDPOINT_OF_HELPER=http://nginx-helper:8080/api
- TEST_UNAVAILABLE_STREAM_ADDRESS=nginx-no-stream:8081

secrets:
nginx-repo.crt:
file: ./docker/nginx-repo.crt
nginx-repo.key:
file: ./docker/nginx-repo.key
13 changes: 4 additions & 9 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM debian:bullseye-slim

LABEL maintainer="NGINX Docker Maintainers <[email protected]>"

ARG NGINX_PLUS_VERSION
ARG NGINX_PLUS_VERSION=R30

# Install NGINX Plus
# Download certificate and key from the customer portal (https://my.f5.com)
Expand All @@ -16,24 +16,19 @@ RUN --mount=type=secret,id=nginx-repo.crt,dst=/etc/ssl/nginx/nginx-repo.crt,mode
curl -fsSL https://cs.nginx.com/static/keys/nginx_signing.key | gpg --dearmor > /etc/apt/trusted.gpg.d/nginx_signing.gpg
curl -fsSL -o /etc/apt/apt.conf.d/90pkgs-nginx https://cs.nginx.com/static/files/90pkgs-nginx
DEBIAN_VERSION=$(awk -F '=' '/^VERSION_CODENAME=/ {print $2}' /etc/os-release)
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
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
apt-get update
apt-get install -y nginx-plus
apt-get remove --purge --auto-remove -y gnupg
rm -rf /var/lib/apt/lists/*
rm /etc/apt/apt.conf.d/90pkgs-nginx /etc/apt/sources.list.d/nginx-plus.list
eot

# Forward request logs to Docker log collector
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log

EXPOSE 80
EXPOSE 8080 8081

STOPSIGNAL SIGQUIT

RUN rm -rf /etc/nginx/conf.d/*
COPY --link test.conf /etc/nginx/conf.d/
COPY --link nginx.conf /etc/nginx/
COPY --link docker/test.conf /etc/nginx/conf.d/

CMD ["nginx", "-g", "daemon off;"]
4 changes: 2 additions & 2 deletions docker/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log notice;
error_log stderr notice;
pid /var/run/nginx.pid;


Expand All @@ -19,7 +19,7 @@ http {
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;
access_log /dev/stdout main;

sendfile on;
#tcp_nopush on;
Expand Down
4 changes: 2 additions & 2 deletions docker/nginx_no_stream.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log notice;
error_log stderr notice;
pid /var/run/nginx.pid;


Expand All @@ -19,7 +19,7 @@ http {
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;
access_log /dev/stdout main;

sendfile on;
#tcp_nopush on;
Expand Down

0 comments on commit 717cc31

Please sign in to comment.