From 04af1414f77c156d1c85c1a2f69286e086cbdde7 Mon Sep 17 00:00:00 2001 From: Aphral Griffin Date: Tue, 24 Jan 2023 15:48:38 +0000 Subject: [PATCH 1/2] add oss dockerfile for use by api integration test --- Makefile | 2 +- .../api => scripts/docker/nginx-oss/ubuntu}/Dockerfile | 3 ++- test/integration/api/api_test.go | 5 +++-- test/integration/api/docker-compose.yml | 3 ++- test/integration/go.mod | 1 - 5 files changed, 8 insertions(+), 6 deletions(-) rename {test/docker/integration/api => scripts/docker/nginx-oss/ubuntu}/Dockerfile (96%) diff --git a/Makefile b/Makefile index 379cbff0a..213f19daa 100644 --- a/Makefile +++ b/Makefile @@ -168,7 +168,7 @@ performance-test: ## Run performance tests docker run -v ${PWD}:/home/nginx/ --rm nginx-agent-benchmark:1.0.0 integration-test: local-deb-package - PACKAGE=${PACKAGE_NAME} go test ./test/integration/api + PACKAGE=${PACKAGE_NAME} DOCKER_IMAGE=${DOCKER_IMAGE} go test ./test/integration/api test-bench: ## Run benchmark tests cd test/performance && GOWORK=off CGO_ENABLED=0 go test -mod=vendor -count 5 -timeout 2m -bench=. -benchmem metrics_test.go diff --git a/test/docker/integration/api/Dockerfile b/scripts/docker/nginx-oss/ubuntu/Dockerfile similarity index 96% rename from test/docker/integration/api/Dockerfile rename to scripts/docker/nginx-oss/ubuntu/Dockerfile index d309f818d..a1050360b 100644 --- a/test/docker/integration/api/Dockerfile +++ b/scripts/docker/nginx-oss/ubuntu/Dockerfile @@ -1,4 +1,5 @@ -FROM ubuntu:22.04 as install +ARG DOCKER_IMAGE +FROM ${DOCKER_IMAGE} as install LABEL maintainer="NGINX Agent Maintainers " ARG PACKAGE diff --git a/test/integration/api/api_test.go b/test/integration/api/api_test.go index 1f34336d0..47d2f8784 100644 --- a/test/integration/api/api_test.go +++ b/test/integration/api/api_test.go @@ -12,7 +12,7 @@ import ( "github.com/go-resty/resty/v2" "github.com/stretchr/testify/assert" - "github.com/testcontainers/testcontainers-go/modules/compose" + "github.com/testcontainers/testcontainers-go/modules/compose" wait "github.com/testcontainers/testcontainers-go/wait" ) @@ -33,7 +33,8 @@ func TestAPI_setupTestContainer(t *testing.T) { assert.NoError(t, comp. WaitForService("agent", wait.ForLog("OneTimeRegistration completed")).WithEnv(map[string]string{ - "PACKAGE": os.Getenv("PACKAGE"), + "PACKAGE": os.Getenv("PACKAGE"), + "DOCKER_IMAGE": os.Getenv("DOCKER_IMAGE"), }). Up(ctx, compose.Wait(true)), "compose.Up()") } diff --git a/test/integration/api/docker-compose.yml b/test/integration/api/docker-compose.yml index b9a985d2c..b1a4bc257 100644 --- a/test/integration/api/docker-compose.yml +++ b/test/integration/api/docker-compose.yml @@ -8,9 +8,10 @@ services: agent: build: context: ../../../ - dockerfile: ./test/docker/integration/api/Dockerfile + dockerfile: ./scripts/docker/nginx-oss/ubuntu/Dockerfile args: - PACKAGE + - DOCKER_IMAGE ports: - 9091:9091 networks: diff --git a/test/integration/go.mod b/test/integration/go.mod index 316b3f910..05f7e56da 100644 --- a/test/integration/go.mod +++ b/test/integration/go.mod @@ -149,7 +149,6 @@ require ( ) replace ( - // https://github.com/cucumber/godog/releases/tag/v0.12.0 - this version breaks github.com/cucumber/godog => github.com/cucumber/godog v0.11.0 github.com/docker/cli => github.com/docker/cli v20.10.3-0.20221013132413-1d6c6e2367e2+incompatible // 22.06 master branch From 52c9e5ff16ca88b14fc3740b09b59cd2a3ed7160 Mon Sep 17 00:00:00 2001 From: Aphral Griffin Date: Wed, 25 Jan 2023 10:49:26 +0000 Subject: [PATCH 2/2] Dockerfile changes --- scripts/docker/nginx-oss/entrypoint.sh | 49 ++++++++++++++++++++++ scripts/docker/nginx-oss/ubuntu/Dockerfile | 9 ++-- test/integration/api/docker-compose.yml | 7 +++- 3 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 scripts/docker/nginx-oss/entrypoint.sh diff --git a/scripts/docker/nginx-oss/entrypoint.sh b/scripts/docker/nginx-oss/entrypoint.sh new file mode 100644 index 000000000..ab2dd356c --- /dev/null +++ b/scripts/docker/nginx-oss/entrypoint.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +set -e +set -x +set -euxo pipefail + +handle_term() +{ + echo "received TERM signal" + echo "stopping nginx-agent ..." + kill -TERM "${agent_pid}" 2>/dev/null + echo "stopping nginx ..." + kill -TERM "${nginx_pid}" 2>/dev/null +} + +trap 'handle_term' TERM + +# Launch nginx +echo "starting nginx ..." +/usr/sbin/nginx -g "daemon off;" & + +nginx_pid=$! + +cp /agent/nginx-agent.conf /etc/nginx-agent/nginx-agent.conf +cat /etc/nginx-agent/nginx-agent.conf + +# start nginx-agent, pass args +echo "starting nginx-agent ..." +nginx-agent "$@" & + +agent_pid=$! + +if [ $? != 0 ]; then + echo "couldn't start the agent, please check the log file" + exit 1 +fi + +wait_term() +{ + wait ${agent_pid} + trap - TERM + kill -QUIT "${nginx_pid}" 2>/dev/null + echo "waiting for nginx to stop..." + wait ${nginx_pid} +} + +wait_term + +echo "nginx-agent process has stopped, exiting." diff --git a/scripts/docker/nginx-oss/ubuntu/Dockerfile b/scripts/docker/nginx-oss/ubuntu/Dockerfile index a1050360b..5299a6e48 100644 --- a/scripts/docker/nginx-oss/ubuntu/Dockerfile +++ b/scripts/docker/nginx-oss/ubuntu/Dockerfile @@ -3,12 +3,15 @@ FROM ${DOCKER_IMAGE} as install LABEL maintainer="NGINX Agent Maintainers " ARG PACKAGE +ARG AGENT_CONF +ARG NGINX_CONF +ARG ENTRY_POINT WORKDIR /agent COPY ./ /agent -COPY ./test/testdata/entrypoint.sh /agent/entrypoint.sh -COPY ./test/testdata/configs/integration/api/nginx-agent.conf /agent/nginx-agent.conf -COPY ./test/testdata/configs/integration/api/nginx.conf /agent/nginx.conf +COPY $ENTRY_POINT /agent/entrypoint.sh +COPY $AGENT_CONF /agent/nginx-agent.conf +COPY $NGINX_CONF /agent/nginx.conf RUN set -x \ && addgroup --system --gid 101 nginx \ diff --git a/test/integration/api/docker-compose.yml b/test/integration/api/docker-compose.yml index b1a4bc257..ea7d0fc40 100644 --- a/test/integration/api/docker-compose.yml +++ b/test/integration/api/docker-compose.yml @@ -10,8 +10,11 @@ services: context: ../../../ dockerfile: ./scripts/docker/nginx-oss/ubuntu/Dockerfile args: - - PACKAGE - - DOCKER_IMAGE + PACKAGE: ${PACKAGE} + DOCKER_IMAGE: ${DOCKER_IMAGE} + AGENT_CONF: "./test/testdata/configs/integration/api/nginx-agent.conf" + NGINX_CONF: "./test/testdata/configs/integration/api/nginx.conf" + ENTRY_POINT: "./scripts/docker/nginx-oss/entrypoint.sh" ports: - 9091:9091 networks: