Add Dockerfile, Makefile, specs, SSL certs

This commit is contained in:
Catalin Constantin Mititiuc 2025-06-24 14:24:38 -07:00
parent b5757a6c91
commit 6de5e6b847
4 changed files with 68 additions and 2 deletions

14
Dockerfile Normal file
View File

@ -0,0 +1,14 @@
FROM openresty/openresty:bookworm-buildpack
WORKDIR /opt/app
RUN luarocks install moonscript
RUN luarocks install busted
RUN luarocks install luajit-curl
RUN luarocks install luasocket # needed for testing nginx reverse proxy
RUN openssl req -x509 -newkey rsa:4096 -nodes \
-keyout /etc/ssl/private/domain.abc.pem \
-out /etc/ssl/certs/domain.abc.pem \
-sha256 -days 365 -subj '/CN=domain.abc' \
-addext "subjectAltName=DNS:domain.abc"

19
Makefile Normal file
View File

@ -0,0 +1,19 @@
image = test-nginx
loopback = 127.0.0.1
image-build:
docker build -t $(image) .
image-rm:
docker image rm $(image)
test:
@ct=$(shell docker run --rm -d \
-v $(PWD)/conf/conf.d:/etc/nginx/conf.d \
-v $(PWD)/html:/var/www \
-v $(PWD):/opt/app \
--network no-internet \
--add-host=domain.abc=$(loopback) \
$(image)); \
docker exec -t $$ct busted; \
docker exec $$ct openresty -s stop

View File

@ -11,10 +11,17 @@
# See https://github.com/openresty/docker-openresty/blob/master/README.md#nginx-config-files # See https://github.com/openresty/docker-openresty/blob/master/README.md#nginx-config-files
# #
server {
listen 80;
return 301 https://$host$request_uri;
}
server { server {
listen 80; listen 443 ssl;
server_name localhost; server_name domain.abc;
ssl_certificate /etc/ssl/certs/domain.abc.pem;
ssl_certificate_key /etc/ssl/private/domain.abc.pem;
#charset koi8-r; #charset koi8-r;
#access_log /var/log/nginx/host.access.log main; #access_log /var/log/nginx/host.access.log main;

26
spec/nginx_spec.moon Normal file
View File

@ -0,0 +1,26 @@
http = require "luajit-curl-helper.http"
req = (url) ->
request = http.init url
st = request\perform!
error request\lastError! if not st
request
describe "test environment", ->
it "can't connect to the internet", ->
assert.has_error (-> req "http://example.org"),
"Couldn't resolve host name"
describe "https://domain.abc", ->
it "sends /index.html", ->
request = req "https://domain.abc"
assert.same request\statusCode!, 200
assert.same request\statusMessage!, "OK"
assert.same request\body!\match("<body>%s+(.-)%s+</body>"), "hello world!"
describe "http://domain.abc", ->
it "redirects to https", ->
request = req "http://domain.abc"
assert.same request\statusCode!, 301
assert.same request\statusMessage!, "Moved Permanently"
assert.same request\header!.Location, "https://domain.abc/"