Add Dockerfile, Makefile, specs, SSL certs
This commit is contained in:
parent
b5757a6c91
commit
6de5e6b847
14
Dockerfile
Normal file
14
Dockerfile
Normal 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
19
Makefile
Normal 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
|
@ -11,10 +11,17 @@
|
||||
# See https://github.com/openresty/docker-openresty/blob/master/README.md#nginx-config-files
|
||||
#
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
return 301 https://$host$request_uri;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
listen 443 ssl;
|
||||
server_name domain.abc;
|
||||
|
||||
ssl_certificate /etc/ssl/certs/domain.abc.pem;
|
||||
ssl_certificate_key /etc/ssl/private/domain.abc.pem;
|
||||
|
||||
#charset koi8-r;
|
||||
#access_log /var/log/nginx/host.access.log main;
|
||||
|
26
spec/nginx_spec.moon
Normal file
26
spec/nginx_spec.moon
Normal 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/"
|
Loading…
x
Reference in New Issue
Block a user