Skip to content

Use Docker Compose for tests #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 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 @@ -26,6 +24,25 @@ permissions:
contents: read

jobs:
unit-test:
name: Unit Test
runs-on: ubuntu-22.04
permissions:
contents: read
strategy:
matrix:
go-version: ["1.19", "1.20", "1.21"]
steps:
- name: Checkout Repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

- name: Setup Golang Environment
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
go-version: ${{ matrix.go-version }}

- name: Run Unit Tests
run: make unit-test
build:
name: Build Client
runs-on: ubuntu-22.04
Expand All @@ -36,17 +53,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 +69,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 test-no-stream

- name: Create/Update Draft
uses: lucacome/draft-release@f6dc37dcdf44be100a649b72c62c628776750190 # v0.2.2
Expand Down
55 changes: 10 additions & 45 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,53 +1,18 @@
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: unit-test test-integration test-integration-no-stream-block 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-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"
unit-test:
go test -v -shuffle=on -race client/*.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
test-integration:
docker compose up -d --build test
docker compose logs -f test

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-integration-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
62 changes: 62 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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:
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: go test -v -shuffle=on -race tests/client_test.go
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-no-stream:
extends:
service: test
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
9 changes: 4 additions & 5 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM debian:12-slim

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

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,20 +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

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