Skip to content

Commit 949339a

Browse files
authored
Fix Nginx Testing (#1744)
* Move CI container to subfolder * Add docker CLI to CI image, no daemon * Add new nginx container started from within CI image
1 parent 9022f11 commit 949339a

6 files changed

Lines changed: 128 additions & 18 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
6363
zsh && \
6464
rm -rf /var/lib/apt/lists/*
6565

66+
# Install Docker CLI (no daemon) so jobs can drive the host runner's docker via a mounted socket
67+
RUN install -m 0755 -d /etc/apt/keyrings && \
68+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc && \
69+
chmod a+r /etc/apt/keyrings/docker.asc && \
70+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu noble stable" \
71+
> /etc/apt/sources.list.d/docker.list && \
72+
apt-get update && \
73+
apt-get install -y docker-ce-cli docker-buildx-plugin docker-compose-plugin && \
74+
rm -rf /var/lib/apt/lists/*
75+
6676
# Install addlicense binary
6777
ARG ADDLICENSE_VERSION=1.1.1
6878
RUN if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then export ARCH="x86_64"; else export ARCH="arm64"; fi && \
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# syntax=docker/dockerfile:1.4
2+
# Copyright 2010 New Relic, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
FROM nginx:latest
17+
18+
COPY <<"EOF" /etc/nginx/nginx.conf
19+
user nginx;
20+
worker_processes 1;
21+
22+
error_log /var/log/nginx/error.log notice;
23+
pid /var/run/nginx.pid;
24+
25+
events {
26+
worker_connections 1024;
27+
}
28+
29+
http {
30+
include /etc/nginx/mime.types;
31+
default_type text/plain;
32+
33+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
34+
'$status $body_bytes_sent "$http_referer" '
35+
'"$http_user_agent" "$http_x_forwarded_for"';
36+
37+
keepalive_timeout 65;
38+
# HTTP/1.1-3.0 server
39+
server {
40+
listen 8080 quic reuseport;
41+
listen 8080 ssl;
42+
http2 on;
43+
44+
add_header Alt-Svc 'h3=":8080"; ma=86400';
45+
46+
ssl_certificate /etc/nginx/ssl/cert.pem;
47+
ssl_certificate_key /etc/nginx/ssl/cert.pem;
48+
49+
location / {
50+
return 200 '{"http3": "$http3","http2": "$http2"}';
51+
}
52+
}
53+
}
54+
EOF
55+
56+
COPY --chmod=0755 <<"EOF" /docker-entrypoint.d/50-generate-cert.sh
57+
#!/bin/bash
58+
set -euo pipefail
59+
60+
echo "Generating self signed cert..."
61+
62+
CERTFILE=/etc/nginx/ssl/cert.pem
63+
mkdir -p $(dirname $CERTFILE)
64+
openssl req -nodes -newkey rsa:2048 -x509 -keyout $CERTFILE -out $CERTFILE -subj '/CN=localhost' -days 3650
65+
66+
echo "Self signed cert generated at $CERTFILE."
67+
EOF
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2010 New Relic, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
services:
16+
app:
17+
build: .
18+
image: nginx-hello-world:local
19+
ports:
20+
- 8080:8080
21+
- 8081:8081
22+
- 8082:8082
23+
healthcheck:
24+
test: ["CMD-SHELL", "service nginx status || exit 1"]
25+
interval: 10s
26+
timeout: 5s
27+
retries: 5

.github/workflows/build-ci-image.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ on:
2020
- cron: "15 16 * * 0" # At 16:15 UTC on Sunday
2121
pull_request: # Trigger test builds on pull requests, but only when relevant files change.
2222
paths:
23-
- ".github/containers/**"
23+
- ".github/containers/ci/**"
2424
- ".github/workflows/build-ci-image.yml"
2525
push: # Trigger rebuilds when pushing relevant files to main.
2626
paths:
27-
- ".github/containers/**"
27+
- ".github/containers/ci/**"
2828
- ".github/workflows/build-ci-image.yml"
2929
branches:
3030
- main
@@ -98,7 +98,7 @@ jobs:
9898
id: build
9999
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # 7.1.0
100100
with:
101-
context: .github/containers
101+
context: .github/containers/ci
102102
platforms: ${{ matrix.platform }}
103103
labels: ${{ steps.meta.outputs.labels }}
104104
outputs: type=image,name=ghcr.io/${{ steps.image-name.outputs.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true

.github/workflows/tests.yml

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
- mongodb8
6262
- mssql
6363
- mysql
64-
# - nginx
64+
- nginx
6565
- oracledb
6666
- postgres9
6767
- postgres16
@@ -1391,20 +1391,6 @@ jobs:
13911391
options: >-
13921392
--add-host=host.docker.internal:host-gateway
13931393
timeout-minutes: 30
1394-
services:
1395-
nginx:
1396-
image: tpansino1643652/nginx-hello-world:latest
1397-
ports:
1398-
- 8080:8080
1399-
- 8081:8081
1400-
- 8082:8082
1401-
# Set health checks to wait until container has started
1402-
options: >-
1403-
--health-cmd "service nginx status || exit 1"
1404-
--health-interval 10s
1405-
--health-timeout 5s
1406-
--health-retries 5
1407-
14081394
steps:
14091395
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # 6.0.2
14101396

@@ -1418,6 +1404,21 @@ jobs:
14181404
mkdir -p /github/home/.cache/pip
14191405
chown -R "$(whoami)" /github/home/.cache/pip
14201406
1407+
- name: Start nginx
1408+
run: |
1409+
# Build image & run container
1410+
docker compose \
1411+
-f .github/containers/nginx/docker-compose.yml \
1412+
up -d \
1413+
--build \
1414+
--wait \
1415+
--wait-timeout 60 \
1416+
&& exit 0
1417+
# If the container fails to start, dump logs and exit with failure
1418+
echo "nginx did not become healthy in time"
1419+
docker logs nginx
1420+
exit 1
1421+
14211422
- name: Get Environments
14221423
id: get-envs
14231424
run: |
@@ -1455,6 +1456,11 @@ jobs:
14551456
if-no-files-found: error
14561457
retention-days: 1
14571458

1459+
- name: Stop nginx
1460+
if: always()
1461+
run: |
1462+
docker compose -f .github/containers/nginx/docker-compose.yml down
1463+
14581464
oracledb:
14591465
env:
14601466
TOTAL_GROUPS: 1

0 commit comments

Comments
 (0)