Skip to content

Commit 1983240

Browse files
authored
test: Refactor docker-compose files in container tests (#3524)
* Initial refactoring * Add the base file to the solution * Remove unnecessary networking from smoketest compose file
1 parent cea14e8 commit 1983240

10 files changed

Lines changed: 117 additions & 234 deletions

tests/Agent/IntegrationTests/ContainerApplications/CustomBaseContainerBuild/Dockerfile.AmazonBaseImage renamed to tests/Agent/IntegrationTests/ContainerApplications/CustomBaseContainerBuild/Dockerfile.CustomBaseImage

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM amazonlinux:latest AS base
1+
ARG BASE_IMAGE
2+
FROM ${BASE_IMAGE} AS base
23

34
# configure dnf and upgrade all packages
45
RUN echo "max_parallel_downloads=10" >> /etc/dnf/dnf.conf

tests/Agent/IntegrationTests/ContainerApplications/CustomBaseContainerBuild/Dockerfile.FedoraBaseImage

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/Agent/IntegrationTests/ContainerApplications/CustomBaseContainerBuild/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ docker buildx create --use
3030
3. Build the base images. The images will be pushed to the container registry with tags per .NET version
3131

3232
```
33-
docker buildx build --build-arg DOTNET_VERSION="8.0" --build-arg DOTNET_QUALITY="GA" -f Dockerfile.AmazonBaseImage --tag $acrName/amazonlinux-aspnet:8.0 --platform linux/amd64,linux/arm64/v8 --push .
34-
docker buildx build --build-arg DOTNET_VERSION="10.0" --build-arg DOTNET_QUALITY="GA" -f Dockerfile.AmazonBaseImage --tag $acrName/amazonlinux-aspnet:10.0 --platform linux/amd64,linux/arm64/v8 --push .
33+
docker buildx build --build-arg BASE_IMAGE="amazonlinux:latest" --build-arg DOTNET_VERSION="8.0" --build-arg DOTNET_QUALITY="GA" -f Dockerfile.CustomBaseImage --tag $acrName/amazonlinux-aspnet:8.0 --platform linux/amd64,linux/arm64/v8 --push .
34+
docker buildx build --build-arg BASE_IMAGE="amazonlinux:latest" --build-arg DOTNET_VERSION="10.0" --build-arg DOTNET_QUALITY="GA" -f Dockerfile.CustomBaseImage --tag $acrName/amazonlinux-aspnet:10.0 --platform linux/amd64,linux/arm64/v8 --push .
3535
36-
docker buildx build --build-arg DOTNET_VERSION="8.0" --build-arg DOTNET_QUALITY="GA" -f Dockerfile.FedoraBaseImage --tag $acrName/fedora-aspnet:8.0 --platform linux/amd64,linux/arm64/v8 --push .
37-
docker buildx build --build-arg DOTNET_VERSION="10.0" --build-arg DOTNET_QUALITY="GA" -f Dockerfile.FedoraBaseImage --tag $acrName/fedora-aspnet:10.0 --platform linux/amd64,linux/arm64/v8 --push .
36+
docker buildx build --build-arg BASE_IMAGE="fedora:latest" --build-arg DOTNET_VERSION="8.0" --build-arg DOTNET_QUALITY="GA" -f Dockerfile.CustomBaseImage --tag $acrName/fedora-aspnet:8.0 --platform linux/amd64,linux/arm64/v8 --push .
37+
docker buildx build --build-arg BASE_IMAGE="fedora:latest" --build-arg DOTNET_VERSION="10.0" --build-arg DOTNET_QUALITY="GA" -f Dockerfile.CustomBaseImage --tag $acrName/fedora-aspnet:10.0 --platform linux/amd64,linux/arm64/v8 --push .
3838
```
3939

4040
4. Disable buildx in Docker Desktop

tests/Agent/IntegrationTests/ContainerApplications/docker-compose-awssdk.yml

Lines changed: 45 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,56 @@
11
# The following must be set either in environment variables or via a .env file in the same folder as this file:
22
#
3-
# AGENT_PATH host path to the Agent linux home folder - will map to /usr/local/newrelic-dotnet-agent in the container
4-
# LOG_PATH host path for Agent logfile output - will map to /app/logs in the container
5-
# DISTRO_TAG distro tag for build, not including the architecture suffix
6-
# TARGET_ARCH the target architecture for the run -- either amd64 or arm64
7-
# BUILD_ARCH the build architecture-- either amd64 or arm64
8-
# PORT external port for the smoketest API
9-
# CONTAINER_NAME The name for the container
10-
# PLATFORM The platform that the service runs on -- linux/amd64 or linux/arm64/v8
11-
# DOTNET_VERSION The dotnet version number to use (8.0, etc)
12-
# NETWORK_NAME The network name to use for containers in this app. Should be unique among all running instances.
13-
# TEST_DOCKERFILE The path and dockerfile to use for the service.
14-
#
15-
# and the usual suspects:
16-
# NEW_RELIC_LICENSE_KEY
17-
# NEW_RELIC_HOST
18-
# NEW_RELIC_APP_NAME
3+
# See docker-compose-base.yml for common required variables.
4+
# CONTAINER_NAME The name for the container
5+
# AWSSDK_INITCOLLECTIONS
6+
# LOCALSTACK_VOLUME_DIR
197
#
20-
#
21-
# To build and run, execute `docker compose -f <path to docker-compose.yml> up`
8+
# To build and run, execute `docker compose -f <path to docker-compose.yml> up`
229
# Alternatively, set COMPOSE_FILE environment variable to the path and omit the -f parameter
2310

2411
services:
25-
localstack:
26-
image: localstack/localstack:4.14.0@sha256:3ebc37595918b8accb852f8048fef2aff047d465167edd655528065b07bc364a
27-
expose: # ports are only available internal to the service, not external so there's no chance for conflicts
28-
- "4566" # LocalStack Gateway
29-
- "4559" # external services port range
30-
environment:
31-
# LocalStack configuration: https://docs.localstack.cloud/references/configuration/
32-
- DEBUG=${DEBUG:-0}
33-
# firehose depends on s3 and sts
34-
- SERVICES=sqs,sns,ses,kinesis,firehose,s3,sts # http://localhost:4566/_localstack/health to see the entire list of possible services and their status
35-
volumes:
36-
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
37-
- "/var/run/docker.sock:/var/run/docker.sock"
38-
healthcheck:
39-
test: ["CMD", "curl", "-f", "http://localhost:4566/_localstack/health"]
40-
interval: 5s
41-
timeout: 5s
42-
retries: 10
43-
start_period: 10s
12+
localstack:
13+
image: localstack/localstack:4.14.0@sha256:3ebc37595918b8accb852f8048fef2aff047d465167edd655528065b07bc364a
14+
expose: # ports are only available internal to the service, not external so there's no chance for conflicts
15+
- "4566" # LocalStack Gateway
16+
- "4559" # external services port range
17+
environment:
18+
# LocalStack configuration: https://docs.localstack.cloud/references/configuration/
19+
- DEBUG=${DEBUG:-0}
20+
# firehose depends on s3 and sts
21+
- SERVICES=sqs,sns,ses,kinesis,firehose,s3,sts # http://localhost:4566/_localstack/health to see the entire list of possible services and their status
22+
volumes:
23+
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
24+
- "/var/run/docker.sock:/var/run/docker.sock"
25+
healthcheck:
26+
test: ["CMD", "curl", "-f", "http://localhost:4566/_localstack/health"]
27+
interval: 5s
28+
timeout: 5s
29+
retries: 10
30+
start_period: 10s
4431

45-
dynamodb:
46-
command: "-jar DynamoDBLocal.jar -inMemory"
47-
image: "amazon/dynamodb-local:latest"
48-
expose: # ports are only available internal to the service, not external so there's no chance for conflicts
49-
- "8000"
50-
working_dir: /home/dynamodblocal
32+
dynamodb:
33+
command: "-jar DynamoDBLocal.jar -inMemory"
34+
image: "amazon/dynamodb-local:latest"
35+
expose: # ports are only available internal to the service, not external so there's no chance for conflicts
36+
- "8000"
37+
working_dir: /home/dynamodblocal
5138

52-
awssdktestapp:
53-
depends_on:
54-
localstack:
55-
condition: service_healthy
56-
dynamodb:
57-
condition: service_started
58-
container_name: ${CONTAINER_NAME}
59-
image: ${CONTAINER_NAME}
60-
platform: ${PLATFORM}
61-
build:
62-
context: .
63-
dockerfile: ${TEST_DOCKERFILE}
64-
args:
65-
DISTRO_TAG: ${DISTRO_TAG}
66-
TARGET_ARCH: ${TARGET_ARCH}
67-
BUILD_ARCH: ${BUILD_ARCH}
68-
NEW_RELIC_LICENSE_KEY: ${NEW_RELIC_LICENSE_KEY}
69-
NEW_RELIC_APP_NAME: ${NEW_RELIC_APP_NAME}
70-
NEW_RELIC_HOST: ${NEW_RELIC_HOST}
71-
DOTNET_VERSION: ${DOTNET_VERSION}
72-
APP_DOTNET_VERSION: ${APP_DOTNET_VERSION}
73-
AWSSDK_INITCOLLECTIONS: ${AWSSDK_INITCOLLECTIONS}
74-
ports:
75-
- "${PORT}:80"
76-
volumes:
77-
- ${AGENT_PATH}:/usr/local/newrelic-dotnet-agent # AGENT_PATH from .env, points to newrelichome_linux_x64
78-
- ${LOG_PATH}:/app/logs # LOG_PATH from .env, should be a folder unique to this run of the smoketest app
39+
awssdktestapp:
40+
extends:
41+
file: docker-compose-base.yml
42+
service: base-app
43+
depends_on:
44+
localstack:
45+
condition: service_healthy
46+
dynamodb:
47+
condition: service_started
48+
container_name: ${CONTAINER_NAME}
49+
image: ${CONTAINER_NAME}
50+
platform: ${PLATFORM}
51+
build:
52+
args:
53+
AWSSDK_INITCOLLECTIONS: ${AWSSDK_INITCOLLECTIONS}
7954

8055
networks:
8156
default:
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Base service definition for New Relic .NET Agent container integration tests.
2+
# Individual docker-compose files extend this service via the 'extends' keyword.
3+
# See https://docs.docker.com/compose/how-tos/multiple-compose-files/extends/
4+
#
5+
# Common required variables (set in environment or .env file):
6+
#
7+
# AGENT_PATH host path to the Agent linux home folder - will map to /usr/local/newrelic-dotnet-agent in the container
8+
# LOG_PATH host path for Agent logfile output - will map to /app/logs in the container
9+
# DISTRO_TAG distro tag for build, not including the architecture suffix
10+
# TARGET_ARCH the target architecture for the run -- either amd64 or arm64
11+
# BUILD_ARCH the build architecture -- either amd64 or arm64
12+
# PORT external port for the test API
13+
# PLATFORM The platform that the service runs on -- linux/amd64 or linux/arm64/v8
14+
# DOTNET_VERSION The dotnet version number to use (8.0, etc)
15+
# APP_DOTNET_VERSION The dotnet version number to use for the app (8.0, etc)
16+
# TEST_DOCKERFILE The path and dockerfile to use for the service
17+
# CONTAINER_TEST_ACR_NAME The name of the Azure Container Registry to use for custom base images
18+
# NEW_RELIC_LICENSE_KEY
19+
# NEW_RELIC_HOST
20+
# NEW_RELIC_APP_NAME
21+
22+
services:
23+
base-app:
24+
build:
25+
context: .
26+
dockerfile: ${TEST_DOCKERFILE}
27+
args:
28+
DISTRO_TAG: ${DISTRO_TAG}
29+
TARGET_ARCH: ${TARGET_ARCH}
30+
BUILD_ARCH: ${BUILD_ARCH}
31+
NEW_RELIC_LICENSE_KEY: ${NEW_RELIC_LICENSE_KEY}
32+
NEW_RELIC_APP_NAME: ${NEW_RELIC_APP_NAME}
33+
NEW_RELIC_HOST: ${NEW_RELIC_HOST}
34+
DOTNET_VERSION: ${DOTNET_VERSION}
35+
APP_DOTNET_VERSION: ${APP_DOTNET_VERSION}
36+
CONTAINER_TEST_ACR_NAME: ${CONTAINER_TEST_ACR_NAME}
37+
ports:
38+
- "${PORT}:80"
39+
volumes:
40+
- ${AGENT_PATH}:/usr/local/newrelic-dotnet-agent # AGENT_PATH from .env, points to newrelichome_linux_x64
41+
- ${LOG_PATH}:/app/logs # LOG_PATH from .env, should be a folder unique to this run of the test app

tests/Agent/IntegrationTests/ContainerApplications/docker-compose-kafka.yml

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,20 @@
11
# The following must be set either in environment variables or via a .env file in the same folder as this file:
22
#
3-
# AGENT_PATH host path to the Agent linux home folder - will map to /usr/local/newrelic-dotnet-agent in the container
4-
# LOG_PATH host path for Agent logfile output - will map to /app/logs in the container
5-
# DISTRO_TAG distro tag for build, not including the architecture suffix
6-
# TARGET_ARCH the target architecture for the run -- either amd64 or arm64
7-
# BUILD_ARCH the build architecture -- either amd64 or arm64
8-
# PORT external port for the smoketest API
3+
# See docker-compose-base.yml for common required variables.
94
# CONTAINER_NAME The name for the container
10-
# PLATFORM The platform that the service runs on -- linux/amd64 or linux/arm64/v8
11-
# DOTNET_VERSION The dotnet version number to use (8.0, etc)
12-
# TEST_DOCKERFILE The path and dockerfile to use for the service.
13-
#
145
# NEW_RELIC_KAFKA_TOPIC
15-
#
16-
# and the usual suspects:
17-
# NEW_RELIC_LICENSE_KEY
18-
# NEW_RELIC_HOST
19-
# NEW_RELIC_APP_NAME
20-
#
216
#
22-
# To build and run, execute `docker compose -f <path to docker-compose.yml> up`
7+
# To build and run, execute `docker compose -f <path to docker-compose.yml> up`
238
# Alternatively, set COMPOSE_FILE environment variable to the path and omit the -f parameter
249

2510
services:
2611
LinuxSmokeTestApp:
12+
extends:
13+
file: docker-compose-base.yml
14+
service: base-app
2715
container_name: ${CONTAINER_NAME}
2816
image: ${CONTAINER_NAME}
2917
platform: ${PLATFORM}
30-
build:
31-
context: .
32-
dockerfile: ${TEST_DOCKERFILE}
33-
args:
34-
DISTRO_TAG: ${DISTRO_TAG}
35-
TARGET_ARCH: ${TARGET_ARCH}
36-
BUILD_ARCH: ${BUILD_ARCH}
37-
NEW_RELIC_LICENSE_KEY: ${NEW_RELIC_LICENSE_KEY}
38-
NEW_RELIC_APP_NAME: ${NEW_RELIC_APP_NAME}
39-
NEW_RELIC_HOST: ${NEW_RELIC_HOST}
40-
DOTNET_VERSION: ${DOTNET_VERSION}
41-
APP_DOTNET_VERSION: ${APP_DOTNET_VERSION}
42-
ports:
43-
- "${PORT}:80"
44-
volumes:
45-
- ${AGENT_PATH}:/usr/local/newrelic-dotnet-agent # AGENT_PATH from .env, points to newrelichome_linux_x64
46-
- ${LOG_PATH}:/app/logs # LOG_PATH from .env, should be a folder unique to this run of the smoketest app
4718
depends_on:
4819
- kafka-broker
4920
environment:
@@ -68,8 +39,7 @@ services:
6839
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
6940
KAFKA_LOG_DIRS: /tmp/kraft-combined-logs
7041
CLUSTER_ID: MkU3OEVBNTcwNTJENDM2Qk
71-
72-
42+
7343
networks:
7444
default:
7545
driver: bridge

tests/Agent/IntegrationTests/ContainerApplications/docker-compose-memcached.yml

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,25 @@
11
# The following must be set either in environment variables or via a .env file in the same folder as this file:
22
#
3-
# AGENT_PATH host path to the Agent linux home folder - will map to /usr/local/newrelic-dotnet-agent in the container
4-
# LOG_PATH host path for Agent logfile output - will map to /app/logs in the container
5-
# DISTRO_TAG distro tag for build, not including the architecture suffix
6-
# TARGET_ARCH the target architecture for the run -- either amd64 or arm64
7-
# BUILD_ARCH the build architecture -- either amd64 or arm64
8-
# PORT external port for the smoketest API
3+
# See docker-compose-base.yml for common required variables.
94
# CONTAINER_NAME The name for the container
10-
# PLATFORM The platform that the service runs on -- linux/amd64 or linux/arm64/v8
11-
# DOTNET_VERSION The dotnet version number to use (8.0, etc)
12-
# TEST_DOCKERFILE The path and dockerfile to use for the service.
135
#
14-
# NEW_RELIC_KAFKA_TOPIC
15-
#
16-
# and the usual suspects:
17-
# NEW_RELIC_LICENSE_KEY
18-
# NEW_RELIC_HOST
19-
# NEW_RELIC_APP_NAME
20-
#
21-
#
22-
# To build and run, execute `docker compose -f <path to docker-compose.yml> up`
6+
# To build and run, execute `docker compose -f <path to docker-compose.yml> up`
237
# Alternatively, set COMPOSE_FILE environment variable to the path and omit the -f parameter
248

259
services:
2610
MemcachedTestApp:
11+
extends:
12+
file: docker-compose-base.yml
13+
service: base-app
2714
container_name: ${CONTAINER_NAME}
2815
image: ${CONTAINER_NAME}
2916
platform: ${PLATFORM}
30-
build:
31-
context: .
32-
dockerfile: ${TEST_DOCKERFILE}
33-
args:
34-
DISTRO_TAG: ${DISTRO_TAG}
35-
TARGET_ARCH: ${TARGET_ARCH}
36-
BUILD_ARCH: ${BUILD_ARCH}
37-
NEW_RELIC_LICENSE_KEY: ${NEW_RELIC_LICENSE_KEY}
38-
NEW_RELIC_APP_NAME: ${NEW_RELIC_APP_NAME}
39-
NEW_RELIC_HOST: ${NEW_RELIC_HOST}
40-
DOTNET_VERSION: ${DOTNET_VERSION}
41-
APP_DOTNET_VERSION: ${APP_DOTNET_VERSION}
42-
ports:
43-
- "${PORT}:80"
44-
volumes:
45-
- ${AGENT_PATH}:/usr/local/newrelic-dotnet-agent # AGENT_PATH from .env, points to newrelichome_linux_x64
46-
- ${LOG_PATH}:/app/logs # LOG_PATH from .env, should be a folder unique to this run of the smoketest app
4717
depends_on:
4818
- memcached-server
4919

5020
memcached-server:
5121
image: memcached:1.6.31
5222

53-
5423
networks:
5524
default:
5625
driver: bridge
Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,16 @@
1-
version: "3"
2-
31
# The following must be set either in environment variables or via a .env file in the same folder as this file:
42
#
5-
# AGENT_PATH host path to the Agent linux home folder - will map to /usr/local/newrelic-dotnet-agent in the container
6-
# LOG_PATH host path for Agent logfile output - will map to /app/logs in the container
7-
# DISTRO_TAG distro tag for build, not including the architecture suffix - possible values 8.0-bookworm-slim, 8.0-alpine, 8.0-jammy
8-
# TARGET_ARCH the target architecture for the build and run -- either amd64 or arm64
9-
# PORT external port for the smoketest API
3+
# See docker-compose-base.yml for common required variables.
104
# CONTAINER_NAME The name for the container
11-
# PLATFORM The platform that the service runs on -- linux/amd64 or linux/arm64/v8
12-
# DOTNET_VERSION The dotnet version number to use (8.0, etc)
13-
# NETWORK_NAME The network name to use for containers in this app. Should be unique among all running instances.
14-
# TEST_DOCKERFILE The path and dockerfile to use for the service.
15-
#
16-
# and the usual suspects:
17-
# NEW_RELIC_LICENSE_KEY
18-
# NEW_RELIC_HOST
19-
# NEW_RELIC_APP_NAME
20-
#
215
#
22-
# To build and run, execute `docker compose -f <path to docker-compose.yml> up`
6+
# To build and run, execute `docker compose -f <path to docker-compose.yml> up`
237
# Alternatively, set COMPOSE_FILE environment variable to the path and omit the -f parameter
248

259
services:
2610
smoketestapp:
11+
extends:
12+
file: docker-compose-base.yml
13+
service: base-app
2714
container_name: ${CONTAINER_NAME}
2815
image: ${CONTAINER_NAME}
2916
platform: ${PLATFORM}
30-
build:
31-
context: .
32-
dockerfile: ${TEST_DOCKERFILE}
33-
args:
34-
DISTRO_TAG: ${DISTRO_TAG}
35-
TARGET_ARCH: ${TARGET_ARCH}
36-
NEW_RELIC_LICENSE_KEY: ${NEW_RELIC_LICENSE_KEY}
37-
NEW_RELIC_APP_NAME: ${NEW_RELIC_APP_NAME}
38-
NEW_RELIC_HOST: ${NEW_RELIC_HOST}
39-
DOTNET_VERSION: ${DOTNET_VERSION}
40-
APP_DOTNET_VERSION: ${APP_DOTNET_VERSION}
41-
ports:
42-
- "${PORT}:80"
43-
volumes:
44-
- ${AGENT_PATH}:/usr/local/newrelic-dotnet-agent # AGENT_PATH from .env, points to newrelichome_linux_x64
45-
- ${LOG_PATH}:/app/logs # LOG_PATH from .env, should be a folder unique to this run of the smoketest app

0 commit comments

Comments
 (0)