Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions .github/workflows/nginx_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Nginx test

on: [push, pull_request]

jobs:

test:
name: Run compose tests
runs-on: ubuntu-22.04
Comment thread
nydr marked this conversation as resolved.
Resolved

steps:
- uses: actions/checkout@v3
- name: Run test
run: |
sudo apt update
sudo apt install -y bats
{
cd nginx
make test
}
Comment thread
mrjones-plip marked this conversation as resolved.
Resolved
14 changes: 9 additions & 5 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# base build
FROM nginx:1.19.6-alpine as base_nginx
FROM nginx:1.25-alpine as base_nginx
Comment thread
nydr marked this conversation as resolved.
Resolved
RUN apk add --update --no-cache \
curl \
socat \
Expand All @@ -12,17 +12,21 @@ RUN chmod 755 /docker-entrypoint.d/ssl-install.sh
COPY templates /etc/nginx/templates
COPY nginx.conf /etc/nginx/nginx.conf
COPY mime.types /etc/nginx/mime.types
COPY conf.d/ /etc/nginx/conf.d/
COPY nginx_error_pages/ /usr/share/nginx/nginx_error_pages/

# test build
FROM ghcr.io/ffurrer2/bats:1.6.0 as test_nginx
RUN apk --no-cache add curl openssl
FROM alpine:3 as test_nginx
RUN apk --no-cache add bats curl openssl
Comment thread
nydr marked this conversation as resolved.
Resolved
RUN mkdir -p /app/bash-shellmock
RUN curl -LJO https://raw.githubusercontent.com/capitalone/bash_shell_mock/main/bin/shellmock
RUN cp shellmock /app/bash-shellmock/shellmock
RUN chmod +x /app/bash-shellmock/shellmock
COPY ssl-install.sh /app/ssl-install.sh
COPY tests /app/tests
COPY ssl-install.sh /app/tests/ssl-install.sh
RUN bats /app/tests/tests.bats
ENV PATH="${PATH}:/app/"
ENTRYPOINT [ "/bin/bash", "/usr/local/bin/bats", "/app/tests.bats" ]
ENTRYPOINT [ "/bin/bash", "/usr/bin/bats", "/app/tests/tests.bats" ]
Comment thread
nydr marked this conversation as resolved.
Resolved

# Final
FROM base_nginx AS cht-nginx
Expand Down
14 changes: 14 additions & 0 deletions nginx/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
COMPOSE_FILE=docker-compose.test.yml

docker_build:
docker build --target test_nginx .

start: docker_build
env BUILD_TARGET=cht-nginx docker compose -f ${COMPOSE_FILE} up --wait --wait-timeout 15 --build

test: start
bats tests/compose.bats
$(MAKE) stop

stop:
docker compose -f ${COMPOSE_FILE} stop
Comment thread
nydr marked this conversation as resolved.
Resolved
40 changes: 40 additions & 0 deletions nginx/conf.d/error_pages.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
error_page 301 =301 /nginx_error_pages/301.$error_extension;
error_page 302 =302 /nginx_error_pages/302.$error_extension;
error_page 303 =303 /nginx_error_pages/303.$error_extension;
error_page 307 =307 /nginx_error_pages/307.$error_extension;
error_page 308 =308 /nginx_error_pages/308.$error_extension;
error_page 400 =400 /nginx_error_pages/400.$error_extension;
error_page 401 =401 /nginx_error_pages/401.$error_extension;
error_page 402 =402 /nginx_error_pages/402.$error_extension;
error_page 403 =403 /nginx_error_pages/403.$error_extension;
error_page 404 =404 /nginx_error_pages/404.$error_extension;
error_page 405 =405 /nginx_error_pages/405.$error_extension;
error_page 406 =406 /nginx_error_pages/406.$error_extension;
error_page 408 =408 /nginx_error_pages/408.$error_extension;
error_page 409 =409 /nginx_error_pages/409.$error_extension;
error_page 410 =410 /nginx_error_pages/410.$error_extension;
error_page 411 =411 /nginx_error_pages/411.$error_extension;
error_page 412 =412 /nginx_error_pages/412.$error_extension;
error_page 413 =413 /nginx_error_pages/413.$error_extension;
error_page 414 =414 /nginx_error_pages/414.$error_extension;
error_page 415 =415 /nginx_error_pages/415.$error_extension;
error_page 416 =416 /nginx_error_pages/416.$error_extension;
error_page 421 =421 /nginx_error_pages/421.$error_extension;
error_page 429 =429 /nginx_error_pages/429.$error_extension;
error_page 494 =494 /nginx_error_pages/494.$error_extension;
error_page 495 =495 /nginx_error_pages/495.$error_extension;
error_page 496 =496 /nginx_error_pages/496.$error_extension;
error_page 497 =497 /nginx_error_pages/497.$error_extension;
error_page 500 =500 /nginx_error_pages/500.$error_extension;
error_page 501 =501 /nginx_error_pages/501.$error_extension;
error_page 502 =502 /nginx_error_pages/502.$error_extension;
error_page 503 =503 /nginx_error_pages/503.$error_extension;
error_page 504 =504 /nginx_error_pages/504.$error_extension;
error_page 505 =505 /nginx_error_pages/505.$error_extension;
error_page 507 =507 /nginx_error_pages/507.$error_extension;

location /nginx_error_pages {
internal;
root /usr/share/nginx;
}

24 changes: 7 additions & 17 deletions nginx/docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@ services:
container_name: cht-nginx
build:
context: .
target: ${BUILD_TARGET:-test_nginx}
ports:
- 80:80
- 443:443
- 127.0.0.1:1080:80
- 127.0.0.1:1443:443
Comment thread
nydr marked this conversation as resolved.
Resolved
environment:
API_HOST: cht-api
API_PORT: 5988
CERTIFICATE_MODE: SELF_SIGNED
volumes:
- cht-ssl:/root/.acme.sh/
- ./tests/tests.bats:/app/tests.bats
depends_on:
- cht-api
- haproxy
networks:
- cht-net

cht-api:
image: mockserver/mockserver
image: mockserver/mockserver:5.15.0
container_name: cht-api-mock
command: -serverPort 5988
environment:
Expand All @@ -29,18 +31,6 @@ services:
networks:
- cht-net

haproxy:
image: mockserver/mockserver
container_name: haproxy-mock
command: -serverPort 5984
environment:
MOCKSERVER_PROPERTY_FILE: /config/mockserver.properties
MOCKSERVER_INITIALIZATION_JSON_PATH: /config/initializerJson.json
volumes:
- ./mock-config:/config
networks:
- cht-net

Comment thread
mrjones-plip marked this conversation as resolved.
Resolved
volumes:
cht-ssl:
name: cht-ssl
Expand Down
38 changes: 23 additions & 15 deletions nginx/mock-config/initializerJson.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
[
{
"httpRequest": {
"path": "/"
},
"httpResponse": {
"body": "Hello from CHT api mock"
}
{
"httpRequest": {
"path": "/"
},
{
"httpRequest": {
"path": "/somepath"
},
"httpResponse": {
"body": "Test"
}
"httpResponse": {
"body": "Hello from CHT api mock"
}
]
},
{
"httpRequest": {
"path": "/somepath"
},
"httpResponse": {
"body": "Test"
}
},
{
"httpRequest": {
"path": "/error/drop"
},
"httpError": {
"dropConnection": true
}
}
]
9 changes: 9 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ http {
keepalive_timeout 3600;
proxy_read_timeout 3600;
client_max_body_size 32M;
server_tokens off;

map $http_accept $error_extension {
# Used by conf.d/error_pages.conf
default html;
~application/json json;
}
Comment thread
nydr marked this conversation as resolved.
Resolved

server {
listen 80;
Expand All @@ -23,6 +30,7 @@ http {
location / {
return 301 https://$host$request_uri;
}
include /etc/nginx/conf.d/error_pages.conf;
}

server {
Expand Down Expand Up @@ -58,6 +66,7 @@ http {
add_header X-Frame-Options SAMEORIGIN;

include /etc/nginx/conf.d/server.conf;
include /etc/nginx/conf.d/error_pages.conf;
}
}

Expand Down
15 changes: 15 additions & 0 deletions nginx/nginx_error_pages/301.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html>

<head>
<title>301 Moved Permanently</title>
</head>

<body>
<center>
<h1>301 Moved Permanently</h1>
</center>
<hr>
<center>nginx</center>
</body>

</html>
5 changes: 5 additions & 0 deletions nginx/nginx_error_pages/301.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "ERROR",
"error": "301 Moved Permanently",
"server": "nginx"
}
15 changes: 15 additions & 0 deletions nginx/nginx_error_pages/302.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html>

<head>
<title>302 Found</title>
</head>

<body>
<center>
<h1>302 Found</h1>
</center>
<hr>
<center>nginx</center>
</body>

</html>
5 changes: 5 additions & 0 deletions nginx/nginx_error_pages/302.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "ERROR",
"error": "302 Found",
"server": "nginx"
}
15 changes: 15 additions & 0 deletions nginx/nginx_error_pages/303.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html>

<head>
<title>303 See Other</title>
</head>

<body>
<center>
<h1>303 See Other</h1>
</center>
<hr>
<center>nginx</center>
</body>

</html>
5 changes: 5 additions & 0 deletions nginx/nginx_error_pages/303.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "ERROR",
"error": "303 See Other",
"server": "nginx"
}
15 changes: 15 additions & 0 deletions nginx/nginx_error_pages/307.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html>

<head>
<title>307 Temporary Redirect</title>
</head>

<body>
<center>
<h1>307 Temporary Redirect</h1>
</center>
<hr>
<center>nginx</center>
</body>

</html>
5 changes: 5 additions & 0 deletions nginx/nginx_error_pages/307.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "ERROR",
"error": "307 Temporary Redirect",
"server": "nginx"
}
15 changes: 15 additions & 0 deletions nginx/nginx_error_pages/308.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html>

<head>
<title>308 Permanent Redirect</title>
</head>

<body>
<center>
<h1>308 Permanent Redirect</h1>
</center>
<hr>
<center>nginx</center>
</body>

</html>
5 changes: 5 additions & 0 deletions nginx/nginx_error_pages/308.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "ERROR",
"error": "308 Permanent Redirect",
"server": "nginx"
}
15 changes: 15 additions & 0 deletions nginx/nginx_error_pages/400.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html>

<head>
<title>400 Bad Request</title>
</head>

<body>
<center>
<h1>400 Bad Request</h1>
</center>
<hr>
<center>nginx</center>
</body>

</html>
5 changes: 5 additions & 0 deletions nginx/nginx_error_pages/400.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "ERROR",
"error": "400 Bad Request",
"server": "nginx"
}
15 changes: 15 additions & 0 deletions nginx/nginx_error_pages/401.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html>

<head>
<title>401 Authorization Required</title>
</head>

<body>
<center>
<h1>401 Authorization Required</h1>
</center>
<hr>
<center>nginx</center>
</body>

</html>
5 changes: 5 additions & 0 deletions nginx/nginx_error_pages/401.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "ERROR",
"error": "401 Authorization Required",
"server": "nginx"
}
Loading