From ab20e4ad364b0796cdf91bd216a5e9ed30f890c8 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Tue, 10 Jun 2025 13:01:46 -0700 Subject: [PATCH 01/26] WIP: start and stop docker container with bash script --- Makefile | 11 ++++++++--- conf/nginx.conf | 23 ++++++++++++----------- test.sh | 17 +++++++++++++++++ 3 files changed, 37 insertions(+), 14 deletions(-) create mode 100755 test.sh diff --git a/Makefile b/Makefile index 0450f57..0c8fdf3 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,14 @@ +image = miti.sh + run: docker run --rm -it --init -v $(PWD):/opt/app -p 8080:8080 \ - sitegen-openresty + --add-host=miti.sh=127.0.0.1 $(image) build: - docker run --rm -w /opt/app -v $(PWD):/opt/app sitegen-openresty sitegen + docker run --rm -w /opt/app -v $(PWD):/opt/app $(image) sitegen lint: - docker run --rm -w /opt/app -v $(PWD):/opt/app sitegen-openresty moonc -l . + docker run --rm -w /opt/app -v $(PWD):/opt/app $(image) moonc -l . + +test: + ./test.sh diff --git a/conf/nginx.conf b/conf/nginx.conf index 68e7585..53fdced 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -7,15 +7,16 @@ events { http { server { - listen 80; - listen 443 ssl; + # listen 80; + listen 8080; + # listen 443 ssl; include mime.types; charset utf-8; default_type text/html; - ssl_certificate /var/www/certs/miti.sh/fullchain.pem; - ssl_certificate_key /var/www/certs/miti.sh/privkey.pem; + # ssl_certificate /var/www/certs/miti.sh/fullchain.pem; + # ssl_certificate_key /var/www/certs/miti.sh/privkey.pem; location ^~ /.well-known/acme-challenge { alias /var/www/dehydrated; @@ -40,7 +41,7 @@ http { } server { - listen 443 ssl; + # listen 443 ssl; server_name git.miti.sh; location ^~ /.well-known/acme-challenge { @@ -60,7 +61,7 @@ http { } server { - listen 443 ssl; + # listen 443 ssl; server_name apps.miti.sh; root /var/www/sites/apps.miti.sh; @@ -75,15 +76,15 @@ http { } server { - listen 443 ssl; + # listen 443 ssl; server_name webdevcat.me; include mime.types; charset utf-8; default_type text/html; - ssl_certificate /var/www/certs/webdevcat.me/fullchain.pem; - ssl_certificate_key /var/www/certs/webdevcat.me/privkey.pem; + # ssl_certificate /var/www/certs/webdevcat.me/fullchain.pem; + # ssl_certificate_key /var/www/certs/webdevcat.me/privkey.pem; location ^~ /.well-known/acme-challenge { alias /var/www/dehydrated; @@ -102,7 +103,7 @@ http { } } server { - listen 443 ssl; + # listen 443 ssl; server_name git.webdevcat.me; location ^~ /.well-known/acme-challenge { @@ -110,7 +111,7 @@ http { } } server { - listen 443 ssl; + # listen 443 ssl; server_name apps.webdevcat.me; location ^~ /.well-known/acme-challenge { diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..e935234 --- /dev/null +++ b/test.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +# echo "hello" +# curl http://webdevcat.me:8080 +image=miti.sh + +echo "starting container..." +container_id=$(docker run --rm -d -v $(pwd):/opt/app -p 8080:8080 \ + --add-host=miti.sh=127.0.0.1 \ + --add-host=webdevcat.me=127.0.0.1 \ + $image) + +echo "container $container_id started" +echo "stopping container $container_id" +stop_cmd_result=$(docker stop $container_id) +echo "container $stop_cmd_result stopped" +# curl http://miti.sh:8080 -- 2.39.5 From 11c56aff4db38c2a9cd3b1abb90b76bc1506e005 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Tue, 10 Jun 2025 14:38:33 -0700 Subject: [PATCH 02/26] Fix nginx.conf redirects; add a rudimentary test --- conf/nginx.conf | 68 ++----------------------------------------------- test.sh | 36 +++++++++++++++++++++----- 2 files changed, 32 insertions(+), 72 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 53fdced..a9b9d4b 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -15,13 +15,6 @@ http { charset utf-8; default_type text/html; - # ssl_certificate /var/www/certs/miti.sh/fullchain.pem; - # ssl_certificate_key /var/www/certs/miti.sh/privkey.pem; - - location ^~ /.well-known/acme-challenge { - alias /var/www/dehydrated; - } - try_files $uri $uri/ $uri.html =404; # return `/posts/index.html` from `/posts` @@ -41,41 +34,7 @@ http { } server { - # listen 443 ssl; - server_name git.miti.sh; - - location ^~ /.well-known/acme-challenge { - alias /var/www/dehydrated; - } - - location / { - client_max_body_size 1024M; - proxy_pass http://localhost:3000; - proxy_set_header Connection $http_connection; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - } - } - - server { - # listen 443 ssl; - server_name apps.miti.sh; - - root /var/www/sites/apps.miti.sh; - - include mime.types; - charset utf-8; - default_type text/html; - - location ^~ /.well-known/acme-challenge { - alias /var/www/dehydrated; - } - } - - server { + listen 8080; # listen 443 ssl; server_name webdevcat.me; @@ -83,15 +42,8 @@ http { charset utf-8; default_type text/html; - # ssl_certificate /var/www/certs/webdevcat.me/fullchain.pem; - # ssl_certificate_key /var/www/certs/webdevcat.me/privkey.pem; - - location ^~ /.well-known/acme-challenge { - alias /var/www/dehydrated; - } - location / { - return 301 https://miti.sh$request_uri; + return 301 http://miti.sh:8080$request_uri; } location ~ ^/git/(.*)$ { @@ -102,20 +54,4 @@ http { return 301 https://apps.miti.sh/$1; } } - server { - # listen 443 ssl; - server_name git.webdevcat.me; - - location ^~ /.well-known/acme-challenge { - alias /var/www/dehydrated; - } - } - server { - # listen 443 ssl; - server_name apps.webdevcat.me; - - location ^~ /.well-known/acme-challenge { - alias /var/www/dehydrated; - } - } } diff --git a/test.sh b/test.sh index e935234..35c62a2 100755 --- a/test.sh +++ b/test.sh @@ -4,14 +4,38 @@ # curl http://webdevcat.me:8080 image=miti.sh -echo "starting container..." +echo "Starting test container..." container_id=$(docker run --rm -d -v $(pwd):/opt/app -p 8080:8080 \ --add-host=miti.sh=127.0.0.1 \ --add-host=webdevcat.me=127.0.0.1 \ $image) -echo "container $container_id started" -echo "stopping container $container_id" -stop_cmd_result=$(docker stop $container_id) -echo "container $stop_cmd_result stopped" -# curl http://miti.sh:8080 +echo "Test container started" + +# docker exec -t $container_id curl http://miti.sh:8080 +# docker exec -t $container_id curl -v http://webdevcat.me:8080 + +echo "redirects webdevcat.me to miti.sh" + +response=$(docker exec -t $container_id curl -so /dev/null \ + -w "%{http_code} %{redirect_url}" http://webdevcat.me:8080) + +expected="301 http://miti.sh:8080/" + +if [[ $response != $expected ]]; then + echo "TEST FAILED" + printf "expected: $expected\ngot: $response\n" +else + echo "TEST PASSED" +fi + +echo "Stopping test container" +docker exec $container_id openresty -p /opt/app -s stop + +is_running=$(docker inspect -f '{{.State.Running}}' $container_id) + +if [[ $is_running == "true" ]]; then + echo "Warning: Docker reports test container is still running" +else + echo "Test container stopped" +fi -- 2.39.5 From 9f019dbac524a196c9bb4bb2cf8fce90ee56a34d Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Tue, 10 Jun 2025 18:11:22 -0700 Subject: [PATCH 03/26] Use Busted and LuaJIT-cURL for tests --- Dockerfile | 3 ++- Makefile | 9 +++++++++ README.md | 4 ++++ spec/routes_spec.moon | 31 +++++++++++++++++++++++++++++++ test.sh | 22 ++++++++++++---------- 5 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 spec/routes_spec.moon diff --git a/Dockerfile b/Dockerfile index 2976516..76b894b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM openresty/openresty:1.27.1.2-0-bookworm-buildpack +FROM openresty/openresty:bookworm-buildpack WORKDIR /opt/app @@ -12,6 +12,7 @@ RUN apt-get update && apt-get install -y \ RUN luarocks install sitegen RUN luarocks install busted +RUN luarocks install luajit-curl RUN luarocks install inotify INOTIFY_INCDIR=/usr/include/x86_64-linux-gnu/ CMD ["sh", "-c", "openresty -p `pwd` -g 'daemon off;'"] diff --git a/Makefile b/Makefile index 0c8fdf3..af9e230 100644 --- a/Makefile +++ b/Makefile @@ -12,3 +12,12 @@ lint: test: ./test.sh + +test-server: + docker run --rm -t -v $(PWD):/opt/app -p 8080:8080 \ + --add-host=miti.sh=127.0.0.1 \ + --add-host=webdevcat.me=127.0.0.1 \ + $(image) + +busted: + docker run --rm -t -w /opt/app -v $(PWD):/opt/app $(image) busted diff --git a/README.md b/README.md index 8341fc9..4132087 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,10 @@ example: $ pygmentize -S default -f html +### run tests + + $ make test + ## gotchas ### What is error `cosmo failed: [string "..."]:62: cannot resume dead coroutine`? diff --git a/spec/routes_spec.moon b/spec/routes_spec.moon new file mode 100644 index 0000000..fd5d1d5 --- /dev/null +++ b/spec/routes_spec.moon @@ -0,0 +1,31 @@ +http = require "luajit-curl-helper.http" + +describe "routes", -> + it "loads miti.sh", -> + request = http.init "http://miti.sh:8080" + st = request\perform! + + error request\lastError! if not st + + status_code = request\statusCode! + status_message = request\statusMessage! + + assert.same status_code, 200 + assert.same status_message, "OK" + + it "redirects webdevcat.me to miti.sh", -> + request = http.init "http://webdevcat.me:8080" + st = request\perform! + + error request\lastError! if not st + + status_code = request\statusCode! + status_message = request\statusMessage! + header = request\header! + + assert.same status_code, 301 + assert.same status_message, "Moved Permanently" + assert.same header.Location, "http://miti.sh:8080/" + + -- body = request\body! + -- print "body", body diff --git a/test.sh b/test.sh index 35c62a2..bb171dc 100755 --- a/test.sh +++ b/test.sh @@ -15,19 +15,21 @@ echo "Test container started" # docker exec -t $container_id curl http://miti.sh:8080 # docker exec -t $container_id curl -v http://webdevcat.me:8080 -echo "redirects webdevcat.me to miti.sh" +docker exec -t $container_id busted -response=$(docker exec -t $container_id curl -so /dev/null \ - -w "%{http_code} %{redirect_url}" http://webdevcat.me:8080) +# echo "redirects webdevcat.me to miti.sh" -expected="301 http://miti.sh:8080/" +# response=$(docker exec -t $container_id curl -so /dev/null \ +# -w "%{http_code} %{redirect_url}" http://webdevcat.me:8080) -if [[ $response != $expected ]]; then - echo "TEST FAILED" - printf "expected: $expected\ngot: $response\n" -else - echo "TEST PASSED" -fi +# expected="301 http://miti.sh:8080/" + +# if [[ $response != $expected ]]; then +# echo "TEST FAILED" +# printf "expected: $expected\ngot: $response\n" +# else +# echo "TEST PASSED" +# fi echo "Stopping test container" docker exec $container_id openresty -p /opt/app -s stop -- 2.39.5 From 831a86c738f582611d7bb5d1e56d70307a28963d Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Wed, 11 Jun 2025 09:44:38 -0700 Subject: [PATCH 04/26] Don't publish any ports from the test container This allows us to make test requests to port 80, like in production --- conf/nginx.conf | 6 ++--- spec/routes_spec.moon | 61 ++++++++++++++++++++++++++++--------------- test.sh | 5 +--- 3 files changed, 43 insertions(+), 29 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index a9b9d4b..1d06c71 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -7,8 +7,7 @@ events { http { server { - # listen 80; - listen 8080; + listen 80; # listen 443 ssl; include mime.types; @@ -34,7 +33,6 @@ http { } server { - listen 8080; # listen 443 ssl; server_name webdevcat.me; @@ -43,7 +41,7 @@ http { default_type text/html; location / { - return 301 http://miti.sh:8080$request_uri; + return 301 http://miti.sh$request_uri; } location ~ ^/git/(.*)$ { diff --git a/spec/routes_spec.moon b/spec/routes_spec.moon index fd5d1d5..58aa1e1 100644 --- a/spec/routes_spec.moon +++ b/spec/routes_spec.moon @@ -1,31 +1,50 @@ http = require "luajit-curl-helper.http" -describe "routes", -> - it "loads miti.sh", -> - request = http.init "http://miti.sh:8080" - st = request\perform! +index_title = "miti.sh · Catalin Constantin Mititiuc" - error request\lastError! if not st +req = (url) -> + request = http.init url + st = request\perform! + error request\lastError! if not st + request - status_code = request\statusCode! - status_message = request\statusMessage! +describe "http://webdevcat.me", -> + it "permanently redirects to http://miti.sh", -> + request = req "http://webdevcat.me" + assert.same request\statusCode!, 301 + assert.same request\statusMessage!, "Moved Permanently" + assert.same request\header!.Location, "http://miti.sh/" - assert.same status_code, 200 - assert.same status_message, "OK" +describe "http://webdevcat.me/git", -> + it "permanently redirects to http://git.miti.sh", -> + request = req "http://webdevcat.me/git" + assert.same request\header!.Location, "http://git.miti.sh/" - it "redirects webdevcat.me to miti.sh", -> - request = http.init "http://webdevcat.me:8080" - st = request\perform! +describe "http://webdevcat.me/git/", -> + it "permanently redirects to http://git.miti.sh", -> + request = req "http://webdevcat.me/git" + assert.same request\header!.Location, "http://git.miti.sh/" - error request\lastError! if not st +describe "http://webdevcat.me/git/pandoc/", -> + pending "permanently redirects to http://git.miti.sh/ccm/pandoc" - status_code = request\statusCode! - status_message = request\statusMessage! - header = request\header! +describe "http://miti.sh", -> + it "sends /index.html", -> + request = req "http://miti.sh" + assert.same request\statusCode!, 200 + assert.same request\statusMessage!, "OK" + assert.same request\body!\match("(.*)"), index_title - assert.same status_code, 301 - assert.same status_message, "Moved Permanently" - assert.same header.Location, "http://miti.sh:8080/" +describe "http://miti.sh/index", -> + it "sends /index.html", -> + request = req "http://miti.sh/index" + assert.same request\statusCode!, 200 + assert.same request\statusMessage!, "OK" + assert.same request\body!\match("(.*)"), index_title - -- body = request\body! - -- print "body", body +describe "http://miti.sh/index.html", -> + it "sends /index.html", -> + request = req "http://miti.sh/index.html" + assert.same request\statusCode!, 200 + assert.same request\statusMessage!, "OK" + assert.same request\body!\match("(.*)"), index_title diff --git a/test.sh b/test.sh index bb171dc..ecb6bb5 100755 --- a/test.sh +++ b/test.sh @@ -5,16 +5,13 @@ image=miti.sh echo "Starting test container..." -container_id=$(docker run --rm -d -v $(pwd):/opt/app -p 8080:8080 \ +container_id=$(docker run --rm -d -v $(pwd):/opt/app \ --add-host=miti.sh=127.0.0.1 \ --add-host=webdevcat.me=127.0.0.1 \ $image) echo "Test container started" -# docker exec -t $container_id curl http://miti.sh:8080 -# docker exec -t $container_id curl -v http://webdevcat.me:8080 - docker exec -t $container_id busted # echo "redirects webdevcat.me to miti.sh" -- 2.39.5 From 7b8413ae57260d28ba54a14006073511da5ea225 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Wed, 11 Jun 2025 09:52:06 -0700 Subject: [PATCH 05/26] Add tests for posts route --- conf/nginx.conf | 2 +- spec/routes_spec.moon | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 1d06c71..c7ddbcc 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -23,7 +23,7 @@ http { # redirect requests ending in a forward slash location ~ ^/(.+)/$ { - return 302 /$1; + return 301 /$1; } location /css { diff --git a/spec/routes_spec.moon b/spec/routes_spec.moon index 58aa1e1..9c9e21f 100644 --- a/spec/routes_spec.moon +++ b/spec/routes_spec.moon @@ -48,3 +48,17 @@ describe "http://miti.sh/index.html", -> assert.same request\statusCode!, 200 assert.same request\statusMessage!, "OK" assert.same request\body!\match("(.*)"), index_title + +describe "http://miti.sh/posts/", -> + it "permanently redirects to http://miti.sh/posts", -> + request = req "http://miti.sh/posts/" + assert.same request\statusCode!, 301 + assert.same request\statusMessage!, "Moved Permanently" + assert.same request\header!.Location, "http://miti.sh/posts" + +describe "http://miti.sh/posts", -> + it "sends /posts/index.html", -> + request = req "http://miti.sh/posts" + assert.same request\statusCode!, 200 + assert.same request\statusMessage!, "OK" + assert.same request\body!\match("(.*)"), "miti.sh · Posts" -- 2.39.5 From 54052e3890139db4715bce0b5ec066d21b4be568 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Wed, 11 Jun 2025 12:39:07 -0700 Subject: [PATCH 06/26] Add capture '/git' (without a trailing slash) to rules --- conf/nginx.conf | 6 +++--- spec/routes_spec.moon | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index c7ddbcc..c3fd55f 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -44,12 +44,12 @@ http { return 301 http://miti.sh$request_uri; } - location ~ ^/git/(.*)$ { - return 301 https://git.miti.sh/ccm/$1; + location ~ ^/git/?(.*)$ { + return 301 http://git.miti.sh/ccm/$1; } location ~ ^/apps/(.*)$ { - return 301 https://apps.miti.sh/$1; + return 301 http://apps.miti.sh/$1; } } } diff --git a/spec/routes_spec.moon b/spec/routes_spec.moon index 9c9e21f..6e3bf0f 100644 --- a/spec/routes_spec.moon +++ b/spec/routes_spec.moon @@ -16,17 +16,24 @@ describe "http://webdevcat.me", -> assert.same request\header!.Location, "http://miti.sh/" describe "http://webdevcat.me/git", -> - it "permanently redirects to http://git.miti.sh", -> + it "permanently redirects to http://git.miti.sh/ccm/", -> request = req "http://webdevcat.me/git" - assert.same request\header!.Location, "http://git.miti.sh/" + assert.same request\header!.Location, "http://git.miti.sh/ccm/" describe "http://webdevcat.me/git/", -> it "permanently redirects to http://git.miti.sh", -> request = req "http://webdevcat.me/git" - assert.same request\header!.Location, "http://git.miti.sh/" + assert.same request\header!.Location, "http://git.miti.sh/ccm/" -describe "http://webdevcat.me/git/pandoc/", -> - pending "permanently redirects to http://git.miti.sh/ccm/pandoc" +describe "http://webdevcat.me/git/pandoc", -> + it "permanently redirects to http://git.miti.sh/ccm/pandoc", -> + request = req "http://webdevcat.me/git/pandoc" + assert.same request\header!.Location, "http://git.miti.sh/ccm/pandoc" + +describe "http://webdevcat.me/apps/btroops", -> + it "permanently redirects to http://apps.miti.sh/btroops", -> + request = req "http://webdevcat.me/apps/btroops" + assert.same request\header!.Location, "http://apps.miti.sh/btroops" describe "http://miti.sh", -> it "sends /index.html", -> -- 2.39.5 From dc8fb2f1f2453aebc893991ef0f29c3c54767061 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Wed, 11 Jun 2025 13:15:50 -0700 Subject: [PATCH 07/26] Fix test env having access to internet; add apps.miti.sh server to conf --- conf/nginx.conf | 5 +++++ spec/routes_spec.moon | 12 ++++++++++++ test.sh | 6 +++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index c3fd55f..96f53c4 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -32,6 +32,11 @@ http { } } + server { + server_name apps.miti.sh; + root /var/www/sites/apps.miti.sh; + } + server { # listen 443 ssl; server_name webdevcat.me; diff --git a/spec/routes_spec.moon b/spec/routes_spec.moon index 6e3bf0f..97c9152 100644 --- a/spec/routes_spec.moon +++ b/spec/routes_spec.moon @@ -8,6 +8,12 @@ req = (url) -> error request\lastError! if not st request +describe "test environment", -> + it "can't connect to the internet", -> + request = http.init "http://example.org" + assert.not_true request\perform! + assert.same request\lastError!, "Couldn't resolve host name" + describe "http://webdevcat.me", -> it "permanently redirects to http://miti.sh", -> request = req "http://webdevcat.me" @@ -69,3 +75,9 @@ describe "http://miti.sh/posts", -> assert.same request\statusCode!, 200 assert.same request\statusMessage!, "OK" assert.same request\body!\match("(.*)"), "miti.sh · Posts" + +describe "http://apps.miti.sh", -> + it "doesn't find it", -> + request = req "http://apps.miti.sh" + assert.same request\statusCode!, 404 + assert.same request\statusMessage!, "Not Found" diff --git a/test.sh b/test.sh index ecb6bb5..138c805 100755 --- a/test.sh +++ b/test.sh @@ -5,8 +5,12 @@ image=miti.sh echo "Starting test container..." -container_id=$(docker run --rm -d -v $(pwd):/opt/app \ + +# Make sure to create 'no-internet' network, if it doesn't already exist: +# $ docker network create --internal no-internet +container_id=$(docker run --rm -d -v $(pwd):/opt/app --network no-internet \ --add-host=miti.sh=127.0.0.1 \ + --add-host=apps.miti.sh=127.0.0.1 \ --add-host=webdevcat.me=127.0.0.1 \ $image) -- 2.39.5 From c2dcb5708aa783a8804d2f6bb50d166338224364 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Wed, 11 Jun 2025 13:21:00 -0700 Subject: [PATCH 08/26] Add prod conf to source control --- conf/nginx.prod.conf | 120 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 conf/nginx.prod.conf diff --git a/conf/nginx.prod.conf b/conf/nginx.prod.conf new file mode 100644 index 0000000..68e7585 --- /dev/null +++ b/conf/nginx.prod.conf @@ -0,0 +1,120 @@ +worker_processes 1; +error_log logs/error.log; + +events { + worker_connections 1024; +} + +http { + server { + listen 80; + listen 443 ssl; + + include mime.types; + charset utf-8; + default_type text/html; + + ssl_certificate /var/www/certs/miti.sh/fullchain.pem; + ssl_certificate_key /var/www/certs/miti.sh/privkey.pem; + + location ^~ /.well-known/acme-challenge { + alias /var/www/dehydrated; + } + + try_files $uri $uri/ $uri.html =404; + + # return `/posts/index.html` from `/posts` + location = /posts { + rewrite ^ /posts/ break; + } + + # redirect requests ending in a forward slash + location ~ ^/(.+)/$ { + return 302 /$1; + } + + location /css { + expires 1h; + alias css; + } + } + + server { + listen 443 ssl; + server_name git.miti.sh; + + location ^~ /.well-known/acme-challenge { + alias /var/www/dehydrated; + } + + location / { + client_max_body_size 1024M; + proxy_pass http://localhost:3000; + proxy_set_header Connection $http_connection; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + } + + server { + listen 443 ssl; + server_name apps.miti.sh; + + root /var/www/sites/apps.miti.sh; + + include mime.types; + charset utf-8; + default_type text/html; + + location ^~ /.well-known/acme-challenge { + alias /var/www/dehydrated; + } + } + + server { + listen 443 ssl; + server_name webdevcat.me; + + include mime.types; + charset utf-8; + default_type text/html; + + ssl_certificate /var/www/certs/webdevcat.me/fullchain.pem; + ssl_certificate_key /var/www/certs/webdevcat.me/privkey.pem; + + location ^~ /.well-known/acme-challenge { + alias /var/www/dehydrated; + } + + location / { + return 301 https://miti.sh$request_uri; + } + + location ~ ^/git/(.*)$ { + return 301 https://git.miti.sh/ccm/$1; + } + + location ~ ^/apps/(.*)$ { + return 301 https://apps.miti.sh/$1; + } + } + server { + listen 443 ssl; + server_name git.webdevcat.me; + + location ^~ /.well-known/acme-challenge { + alias /var/www/dehydrated; + } + } + server { + listen 443 ssl; + server_name apps.webdevcat.me; + + location ^~ /.well-known/acme-challenge { + alias /var/www/dehydrated; + } + } +} -- 2.39.5 From 1e33d2770a37749fd5658a58e79a1dcd7d0d9ec1 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Wed, 11 Jun 2025 14:23:11 -0700 Subject: [PATCH 09/26] Add subdomains git and apps --- conf/nginx.conf | 25 +++++++++++++++++++++++++ spec/routes_spec.moon | 41 ++++++++++++++++++++++++++++++++++++++--- test.sh | 5 +++++ 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 96f53c4..c94c2a9 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -32,6 +32,21 @@ http { } } + server { + server_name git.miti.sh; + + location / { + client_max_body_size 1024M; + proxy_pass http://localhost:3000; + proxy_set_header Connection $http_connection; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + } + server { server_name apps.miti.sh; root /var/www/sites/apps.miti.sh; @@ -57,4 +72,14 @@ http { return 301 http://apps.miti.sh/$1; } } + + server { + server_name git.webdevcat.me; + return 301 http://git.miti.sh$request_uri; + } + + server { + server_name apps.webdevcat.me; + return 301 http://apps.miti.sh$request_uri; + } } diff --git a/spec/routes_spec.moon b/spec/routes_spec.moon index 97c9152..2f87fac 100644 --- a/spec/routes_spec.moon +++ b/spec/routes_spec.moon @@ -10,9 +10,7 @@ req = (url) -> describe "test environment", -> it "can't connect to the internet", -> - request = http.init "http://example.org" - assert.not_true request\perform! - assert.same request\lastError!, "Couldn't resolve host name" + assert.has_error (-> req "http://example.org"), "Couldn't resolve host name" describe "http://webdevcat.me", -> it "permanently redirects to http://miti.sh", -> @@ -24,21 +22,50 @@ describe "http://webdevcat.me", -> describe "http://webdevcat.me/git", -> it "permanently redirects to http://git.miti.sh/ccm/", -> request = req "http://webdevcat.me/git" + assert.same request\statusCode!, 301 + assert.same request\statusMessage!, "Moved Permanently" assert.same request\header!.Location, "http://git.miti.sh/ccm/" describe "http://webdevcat.me/git/", -> it "permanently redirects to http://git.miti.sh", -> request = req "http://webdevcat.me/git" + assert.same request\statusCode!, 301 + assert.same request\statusMessage!, "Moved Permanently" assert.same request\header!.Location, "http://git.miti.sh/ccm/" describe "http://webdevcat.me/git/pandoc", -> it "permanently redirects to http://git.miti.sh/ccm/pandoc", -> request = req "http://webdevcat.me/git/pandoc" + assert.same request\statusCode!, 301 + assert.same request\statusMessage!, "Moved Permanently" assert.same request\header!.Location, "http://git.miti.sh/ccm/pandoc" +describe "http://git.webdevcat.me", -> + it "permanently redirects to http://git.miti.sh/", -> + request = req "http://git.webdevcat.me" + assert.same request\statusCode!, 301 + assert.same request\statusMessage!, "Moved Permanently" + assert.same request\header!.Location, "http://git.miti.sh/" + describe "http://webdevcat.me/apps/btroops", -> it "permanently redirects to http://apps.miti.sh/btroops", -> request = req "http://webdevcat.me/apps/btroops" + assert.same request\statusCode!, 301 + assert.same request\statusMessage!, "Moved Permanently" + assert.same request\header!.Location, "http://apps.miti.sh/btroops" + +describe "http://apps.webdevcat.me", -> + it "permanently redirects to http://apps.miti.sh/", -> + request = req "http://apps.webdevcat.me" + assert.same request\statusCode!, 301 + assert.same request\statusMessage!, "Moved Permanently" + assert.same request\header!.Location, "http://apps.miti.sh/" + +describe "http://apps.webdevcat.me/btroops", -> + it "permanently redirects to http://apps.miti.sh/btroops", -> + request = req "http://apps.webdevcat.me/btroops" + assert.same request\statusCode!, 301 + assert.same request\statusMessage!, "Moved Permanently" assert.same request\header!.Location, "http://apps.miti.sh/btroops" describe "http://miti.sh", -> @@ -76,6 +103,14 @@ describe "http://miti.sh/posts", -> assert.same request\statusMessage!, "OK" assert.same request\body!\match("(.*)"), "miti.sh · Posts" +describe "http://git.miti.sh", -> + it "doesn't find it?", -> + request = req "http://git.miti.sh" + require("moon").p request\body! + require("moon").p request\header! + -- assert.same request\statusCode!, 404 + -- assert.same request\statusMessage!, "Not Found" + describe "http://apps.miti.sh", -> it "doesn't find it", -> request = req "http://apps.miti.sh" diff --git a/test.sh b/test.sh index 138c805..b1cc03a 100755 --- a/test.sh +++ b/test.sh @@ -11,11 +11,16 @@ echo "Starting test container..." container_id=$(docker run --rm -d -v $(pwd):/opt/app --network no-internet \ --add-host=miti.sh=127.0.0.1 \ --add-host=apps.miti.sh=127.0.0.1 \ + --add-host=git.miti.sh=127.0.0.1 \ --add-host=webdevcat.me=127.0.0.1 \ + --add-host=apps.webdevcat.me=127.0.0.1 \ + --add-host=git.webdevcat.me=127.0.0.1 \ $image) echo "Test container started" +# docker exec -t $container_id cat /etc/hosts +# docker exec -t $container_id cat /opt/app/logs/error.log docker exec -t $container_id busted # echo "redirects webdevcat.me to miti.sh" -- 2.39.5 From 74632be2e1255f610c06f10a3c414aff26c62433 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Thu, 12 Jun 2025 15:27:23 -0700 Subject: [PATCH 10/26] Add test for nginx reverse proxy rule --- Dockerfile | 9 +++++++-- app.ini | 8 ++++---- conf/nginx.conf | 2 +- spec/routes_spec.moon | 12 +++++++----- test.sh | 29 +++++++---------------------- unixstreamsrvr.lua | 12 ++++++++++++ 6 files changed, 38 insertions(+), 34 deletions(-) create mode 100644 unixstreamsrvr.lua diff --git a/Dockerfile b/Dockerfile index 76b894b..68233ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,8 +11,13 @@ RUN apt-get update && apt-get install -y \ wget -q -O $pkgname $pkgurl && dpkg -i $pkgname && rm $pkgname RUN luarocks install sitegen -RUN luarocks install busted -RUN luarocks install luajit-curl + +# needed for sitegen watcher RUN luarocks install inotify INOTIFY_INCDIR=/usr/include/x86_64-linux-gnu/ +# needed for testing +RUN luarocks install busted +RUN luarocks install luajit-curl +RUN luarocks install luasocket # needed for testing nginx reverse proxy + CMD ["sh", "-c", "openresty -p `pwd` -g 'daemon off;'"] diff --git a/app.ini b/app.ini index a8fb316..c06ea4d 100644 --- a/app.ini +++ b/app.ini @@ -21,12 +21,12 @@ ROOT = /var/lib/gitea/data/gitea-repositories [server] ; SSH_DOMAIN = localhost -SSH_DOMAIN = git.miti.sh +; SSH_DOMAIN = git.miti.sh ; DOMAIN = localhost -DOMAIN = git.miti.sh -HTTP_PORT = 3000 +; DOMAIN = git.miti.sh +; HTTP_PORT = 3000 ; ROOT_URL = http://localhost:3000/ -ROOT_URL = https://git.miti.sh +ROOT_URL = https://git.miti.sh:3000 APP_DATA_PATH = /var/lib/gitea/data DISABLE_SSH = false SSH_PORT = 22 diff --git a/conf/nginx.conf b/conf/nginx.conf index c94c2a9..43d27a9 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -37,7 +37,7 @@ http { location / { client_max_body_size 1024M; - proxy_pass http://localhost:3000; + proxy_pass http://unix:/run/gitea/gitea.socket; proxy_set_header Connection $http_connection; proxy_set_header Upgrade $http_upgrade; proxy_set_header Host $host; diff --git a/spec/routes_spec.moon b/spec/routes_spec.moon index 2f87fac..54faf94 100644 --- a/spec/routes_spec.moon +++ b/spec/routes_spec.moon @@ -104,12 +104,14 @@ describe "http://miti.sh/posts", -> assert.same request\body!\match("(.*)"), "miti.sh · Posts" describe "http://git.miti.sh", -> - it "doesn't find it?", -> + it "reverse proxies request to unix socket", -> + os.execute "mkdir /run/gitea" + p = io.popen "luajit unixstreamsrvr.lua" + os.execute("sleep 1") + os.execute("chown -R nobody /run/gitea") + request = req "http://git.miti.sh" - require("moon").p request\body! - require("moon").p request\header! - -- assert.same request\statusCode!, 404 - -- assert.same request\statusMessage!, "Not Found" + assert.is_not_nil p\read"*a"\match "Host: git.miti.sh" describe "http://apps.miti.sh", -> it "doesn't find it", -> diff --git a/test.sh b/test.sh index b1cc03a..aad5089 100755 --- a/test.sh +++ b/test.sh @@ -1,20 +1,19 @@ #!/usr/bin/env bash -# echo "hello" -# curl http://webdevcat.me:8080 image=miti.sh +loopback=127.0.0.1 echo "Starting test container..." # Make sure to create 'no-internet' network, if it doesn't already exist: # $ docker network create --internal no-internet container_id=$(docker run --rm -d -v $(pwd):/opt/app --network no-internet \ - --add-host=miti.sh=127.0.0.1 \ - --add-host=apps.miti.sh=127.0.0.1 \ - --add-host=git.miti.sh=127.0.0.1 \ - --add-host=webdevcat.me=127.0.0.1 \ - --add-host=apps.webdevcat.me=127.0.0.1 \ - --add-host=git.webdevcat.me=127.0.0.1 \ + --add-host=miti.sh=$loopback \ + --add-host=git.miti.sh=$loopback \ + --add-host=apps.miti.sh=$loopback \ + --add-host=webdevcat.me=$loopback \ + --add-host=git.webdevcat.me=$loopback \ + --add-host=apps.webdevcat.me=$loopback \ $image) echo "Test container started" @@ -23,20 +22,6 @@ echo "Test container started" # docker exec -t $container_id cat /opt/app/logs/error.log docker exec -t $container_id busted -# echo "redirects webdevcat.me to miti.sh" - -# response=$(docker exec -t $container_id curl -so /dev/null \ -# -w "%{http_code} %{redirect_url}" http://webdevcat.me:8080) - -# expected="301 http://miti.sh:8080/" - -# if [[ $response != $expected ]]; then -# echo "TEST FAILED" -# printf "expected: $expected\ngot: $response\n" -# else -# echo "TEST PASSED" -# fi - echo "Stopping test container" docker exec $container_id openresty -p /opt/app -s stop diff --git a/unixstreamsrvr.lua b/unixstreamsrvr.lua new file mode 100644 index 0000000..407d17d --- /dev/null +++ b/unixstreamsrvr.lua @@ -0,0 +1,12 @@ + socket = require"socket" + socket.unix = require"socket.unix" + u = assert(socket.unix.stream()) + assert(u:bind("/run/gitea/gitea.socket")) + assert(u:listen()) + c = assert(u:accept()) + + m = assert(c:receive()) + repeat + print(m) + m = assert(c:receive()) + until m == "" -- 2.39.5 From 63f50820bd2c04a02884dbe47eb3d221c76f0303 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Thu, 12 Jun 2025 17:10:07 -0700 Subject: [PATCH 11/26] Move socket test server file into spec dir --- spec/routes_spec.moon | 18 ++++++++++++------ unixstreamsrvr.lua => spec/unixstreamsrvr.lua | 0 2 files changed, 12 insertions(+), 6 deletions(-) rename unixstreamsrvr.lua => spec/unixstreamsrvr.lua (100%) diff --git a/spec/routes_spec.moon b/spec/routes_spec.moon index 54faf94..adafba1 100644 --- a/spec/routes_spec.moon +++ b/spec/routes_spec.moon @@ -104,14 +104,20 @@ describe "http://miti.sh/posts", -> assert.same request\body!\match("(.*)"), "miti.sh · Posts" describe "http://git.miti.sh", -> - it "reverse proxies request to unix socket", -> - os.execute "mkdir /run/gitea" - p = io.popen "luajit unixstreamsrvr.lua" - os.execute("sleep 1") - os.execute("chown -R nobody /run/gitea") + it "reverse proxies request to gitea through a unix socket", -> + Path = require "sitegen.path" + filename = "unixstreamsrvr.lua" + socket_dir = "/run/gitea" + info = debug.getinfo 1 + basepath = Path.basepath info.short_src + + os.execute "mkdir " .. socket_dir + p = io.popen "luajit %s"\format Path.join basepath, filename + os.execute "sleep 0" + os.execute "chown -R nobody " .. socket_dir request = req "http://git.miti.sh" - assert.is_not_nil p\read"*a"\match "Host: git.miti.sh" + assert.truthy p\read"*a"\match "Host: git.miti.sh" describe "http://apps.miti.sh", -> it "doesn't find it", -> diff --git a/unixstreamsrvr.lua b/spec/unixstreamsrvr.lua similarity index 100% rename from unixstreamsrvr.lua rename to spec/unixstreamsrvr.lua -- 2.39.5 From 6462ac9968616c95fd32bf576a60e6e60d3a3ec5 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Fri, 13 Jun 2025 13:36:36 -0700 Subject: [PATCH 12/26] Assert the socket exists in reverse proxy test --- spec/routes_spec.moon | 18 +++++++++++------- spec/unixstreamsrvr.lua | 12 ------------ spec/unixstreamsrvr.moon | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 19 deletions(-) delete mode 100644 spec/unixstreamsrvr.lua create mode 100644 spec/unixstreamsrvr.moon diff --git a/spec/routes_spec.moon b/spec/routes_spec.moon index adafba1..14b7798 100644 --- a/spec/routes_spec.moon +++ b/spec/routes_spec.moon @@ -106,18 +106,22 @@ describe "http://miti.sh/posts", -> describe "http://git.miti.sh", -> it "reverse proxies request to gitea through a unix socket", -> Path = require "sitegen.path" - filename = "unixstreamsrvr.lua" + socket_fname = "unixstreamsrvr.moon" socket_dir = "/run/gitea" - info = debug.getinfo 1 - basepath = Path.basepath info.short_src + socket_owner = "nobody" + basepath = Path.basepath debug.getinfo(1).short_src os.execute "mkdir " .. socket_dir - p = io.popen "luajit %s"\format Path.join basepath, filename - os.execute "sleep 0" - os.execute "chown -R nobody " .. socket_dir + p = io.popen "moon %s"\format Path.join(basepath, socket_fname) + os.execute "sleep 0.1" + os.execute "chown -R " .. socket_owner .. " " .. socket_dir + result = Path.read_exec "find", socket_dir, "-type", "s", "-ls" + assert.truthy result\match "nobody%s+root.+" .. Path.join(socket_dir, "gitea.socket") request = req "http://git.miti.sh" - assert.truthy p\read"*a"\match "Host: git.miti.sh" + pout = p\read"*a" + p\close! + assert.truthy pout\match "Host: git.miti.sh" describe "http://apps.miti.sh", -> it "doesn't find it", -> diff --git a/spec/unixstreamsrvr.lua b/spec/unixstreamsrvr.lua deleted file mode 100644 index 407d17d..0000000 --- a/spec/unixstreamsrvr.lua +++ /dev/null @@ -1,12 +0,0 @@ - socket = require"socket" - socket.unix = require"socket.unix" - u = assert(socket.unix.stream()) - assert(u:bind("/run/gitea/gitea.socket")) - assert(u:listen()) - c = assert(u:accept()) - - m = assert(c:receive()) - repeat - print(m) - m = assert(c:receive()) - until m == "" diff --git a/spec/unixstreamsrvr.moon b/spec/unixstreamsrvr.moon new file mode 100644 index 0000000..517fb89 --- /dev/null +++ b/spec/unixstreamsrvr.moon @@ -0,0 +1,19 @@ +-- modified from +-- https://github.com/lunarmodules/luasocket/blob/4844a48fbf76b0400fd7b7e4d15d244484019df1/test/unixstreamsrvr.lua +socket = require "socket" +socket.unix = require "socket.unix" +u = assert socket.unix.stream! +assert u\bind "/run/gitea/gitea.socket" +assert u\listen! +assert u\settimeout 1 +c = assert u\accept! +m = assert c\receive! +-- print "RECEIVED" +-- print m +while m != "" + print m + m = assert c\receive! +-- repeat +-- print m + -- m = assert c\receive! +-- until m == "" -- 2.39.5 From f364eb68876d29c534f5e83fd69b0e15018591a4 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Fri, 13 Jun 2025 14:05:03 -0700 Subject: [PATCH 13/26] Use Path.exec instead of os.execute where we can --- spec/routes_spec.moon | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/spec/routes_spec.moon b/spec/routes_spec.moon index 14b7798..93a4d6e 100644 --- a/spec/routes_spec.moon +++ b/spec/routes_spec.moon @@ -104,24 +104,26 @@ describe "http://miti.sh/posts", -> assert.same request\body!\match("(.*)"), "miti.sh · Posts" describe "http://git.miti.sh", -> - it "reverse proxies request to gitea through a unix socket", -> + it "reverse-proxies request to a gitea unix socket", -> Path = require "sitegen.path" socket_fname = "unixstreamsrvr.moon" socket_dir = "/run/gitea" socket_owner = "nobody" basepath = Path.basepath debug.getinfo(1).short_src - os.execute "mkdir " .. socket_dir - p = io.popen "moon %s"\format Path.join(basepath, socket_fname) - os.execute "sleep 0.1" - os.execute "chown -R " .. socket_owner .. " " .. socket_dir + Path.mkdir socket_dir + server = io.popen "moon %s"\format Path.join(basepath, socket_fname) + Path.exec "sleep", "0.1" + Path.exec "chown", "-R", socket_owner, socket_dir result = Path.read_exec "find", socket_dir, "-type", "s", "-ls" assert.truthy result\match "nobody%s+root.+" .. Path.join(socket_dir, "gitea.socket") - request = req "http://git.miti.sh" - pout = p\read"*a" - p\close! - assert.truthy pout\match "Host: git.miti.sh" + req "http://git.miti.sh" + + reqheader = with server\read "*a" + server\close! + + assert.truthy reqheader\match "Host: git.miti.sh" describe "http://apps.miti.sh", -> it "doesn't find it", -> -- 2.39.5 From 5265281babb2217d7aac31698b0235102d3f1f5d Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Fri, 13 Jun 2025 14:24:53 -0700 Subject: [PATCH 14/26] Clean up spec/unixstreamsrvr.moon --- spec/unixstreamsrvr.moon | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/spec/unixstreamsrvr.moon b/spec/unixstreamsrvr.moon index 517fb89..133b581 100644 --- a/spec/unixstreamsrvr.moon +++ b/spec/unixstreamsrvr.moon @@ -7,13 +7,8 @@ assert u\bind "/run/gitea/gitea.socket" assert u\listen! assert u\settimeout 1 c = assert u\accept! + m = assert c\receive! --- print "RECEIVED" --- print m while m != "" print m m = assert c\receive! --- repeat --- print m - -- m = assert c\receive! --- until m == "" -- 2.39.5 From 29a979fc66848e76237cc68e54f0c2f605a6fd42 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Fri, 13 Jun 2025 14:26:29 -0700 Subject: [PATCH 15/26] Clean up test.sh --- test.sh | 9 --------- 1 file changed, 9 deletions(-) diff --git a/test.sh b/test.sh index aad5089..8904929 100755 --- a/test.sh +++ b/test.sh @@ -3,8 +3,6 @@ image=miti.sh loopback=127.0.0.1 -echo "Starting test container..." - # Make sure to create 'no-internet' network, if it doesn't already exist: # $ docker network create --internal no-internet container_id=$(docker run --rm -d -v $(pwd):/opt/app --network no-internet \ @@ -16,19 +14,12 @@ container_id=$(docker run --rm -d -v $(pwd):/opt/app --network no-internet \ --add-host=apps.webdevcat.me=$loopback \ $image) -echo "Test container started" - -# docker exec -t $container_id cat /etc/hosts -# docker exec -t $container_id cat /opt/app/logs/error.log docker exec -t $container_id busted -echo "Stopping test container" docker exec $container_id openresty -p /opt/app -s stop is_running=$(docker inspect -f '{{.State.Running}}' $container_id) if [[ $is_running == "true" ]]; then echo "Warning: Docker reports test container is still running" -else - echo "Test container stopped" fi -- 2.39.5 From d66dde558759ad4ef4259fded577f555c45597a8 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Fri, 13 Jun 2025 14:30:49 -0700 Subject: [PATCH 16/26] Clean up Makefile --- Makefile | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/Makefile b/Makefile index af9e230..ac7471c 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,7 @@ image = miti.sh run: - docker run --rm -it --init -v $(PWD):/opt/app -p 8080:8080 \ - --add-host=miti.sh=127.0.0.1 $(image) + docker run --rm -it --init -v $(PWD):/opt/app -p 8080:80 $(image) build: docker run --rm -w /opt/app -v $(PWD):/opt/app $(image) sitegen @@ -12,12 +11,3 @@ lint: test: ./test.sh - -test-server: - docker run --rm -t -v $(PWD):/opt/app -p 8080:8080 \ - --add-host=miti.sh=127.0.0.1 \ - --add-host=webdevcat.me=127.0.0.1 \ - $(image) - -busted: - docker run --rm -t -w /opt/app -v $(PWD):/opt/app $(image) busted -- 2.39.5 From 63719f8fda1b829413fc6d95cbbe4f52676b424a Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Fri, 13 Jun 2025 14:31:54 -0700 Subject: [PATCH 17/26] Rename spec file --- spec/{routes_spec.moon => nginx_spec.moon} | 1 - 1 file changed, 1 deletion(-) rename spec/{routes_spec.moon => nginx_spec.moon} (99%) diff --git a/spec/routes_spec.moon b/spec/nginx_spec.moon similarity index 99% rename from spec/routes_spec.moon rename to spec/nginx_spec.moon index 93a4d6e..3787e3b 100644 --- a/spec/routes_spec.moon +++ b/spec/nginx_spec.moon @@ -1,5 +1,4 @@ http = require "luajit-curl-helper.http" - index_title = "miti.sh · Catalin Constantin Mititiuc" req = (url) -> -- 2.39.5 From 027b8616d34cdfa83347b18242e34465af99421d Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Fri, 13 Jun 2025 16:49:40 -0700 Subject: [PATCH 18/26] Refactor while loop to not repeat instruction --- spec/unixstreamsrvr.moon | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/unixstreamsrvr.moon b/spec/unixstreamsrvr.moon index 133b581..b0ffd8a 100644 --- a/spec/unixstreamsrvr.moon +++ b/spec/unixstreamsrvr.moon @@ -8,7 +8,7 @@ assert u\listen! assert u\settimeout 1 c = assert u\accept! -m = assert c\receive! -while m != "" - print m +while true m = assert c\receive! + break if m == "" + print m -- 2.39.5 From a14be2cbde15fb6c27bd7ec161d28a5762828a57 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Fri, 13 Jun 2025 22:03:11 -0700 Subject: [PATCH 19/26] Add some self-signed TSL certs to test https --- Dockerfile | 14 ++++++++++++++ Makefile | 6 ++++++ conf/nginx.conf | 18 +++++++++++++++++- spec/nginx_spec.moon | 33 ++++++++++++++++++++------------- 4 files changed, 57 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 68233ab..d213f0e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,4 +20,18 @@ RUN luarocks install busted RUN luarocks install luajit-curl RUN luarocks install luasocket # needed for testing nginx reverse proxy +RUN mkdir -p /var/www/certs/miti.sh \ + && openssl req -x509 -newkey rsa:4096 -nodes \ + -keyout /var/www/certs/miti.sh/privkey.pem \ + -out /var/www/certs/miti.sh/fullchain.pem \ + -sha256 -days 365 -subj '/CN=miti.sh' \ + -addext "subjectAltName=DNS:miti.sh,DNS:git.miti.sh,DNS:apps.miti.sh" + +RUN mkdir -p /var/www/certs/webdevcat.me \ + && openssl req -x509 -newkey rsa:4096 -nodes \ + -keyout /var/www/certs/webdevcat.me/privkey.pem \ + -out /var/www/certs/webdevcat.me/fullchain.pem \ + -sha256 -days 365 -subj '/CN=webdevcat.me' \ + -addext "subjectAltName=DNS:webdevcat.me,DNS:git.webdevcat.me,DNS:apps.webdevcat.me" + CMD ["sh", "-c", "openresty -p `pwd` -g 'daemon off;'"] diff --git a/Makefile b/Makefile index ac7471c..3d3b558 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,12 @@ run: build: docker run --rm -w /opt/app -v $(PWD):/opt/app $(image) sitegen +image-rm: + docker image rm $(image):latest + +image-build: + docker build -t $(image) . + lint: docker run --rm -w /opt/app -v $(PWD):/opt/app $(image) moonc -l . diff --git a/conf/nginx.conf b/conf/nginx.conf index 43d27a9..076e9e1 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -8,12 +8,23 @@ events { http { server { listen 80; - # listen 443 ssl; + return 301 https://$host$request_uri; + } + + server { + listen 443 ssl; include mime.types; charset utf-8; default_type text/html; + ssl_certificate /var/www/certs/miti.sh/fullchain.pem; + ssl_certificate_key /var/www/certs/miti.sh/privkey.pem; + + location ^~ /.well-known/acme-challenge { + alias /var/www/dehydrated; + } + try_files $uri $uri/ $uri.html =404; # return `/posts/index.html` from `/posts` @@ -33,8 +44,13 @@ http { } server { + listen 443 ssl; server_name git.miti.sh; + location ^~ /.well-known/acme-challenge { + alias /var/www/dehydrated; + } + location / { client_max_body_size 1024M; proxy_pass http://unix:/run/gitea/gitea.socket; diff --git a/spec/nginx_spec.moon b/spec/nginx_spec.moon index 3787e3b..8dc754c 100644 --- a/spec/nginx_spec.moon +++ b/spec/nginx_spec.moon @@ -11,6 +11,13 @@ describe "test environment", -> it "can't connect to the internet", -> assert.has_error (-> req "http://example.org"), "Couldn't resolve host name" +describe "http://miti.sh", -> + it "redirects to https", -> + request = req "http://miti.sh" + assert.same request\statusCode!, 301 + assert.same request\statusMessage!, "Moved Permanently" + assert.same request\header!.Location, "https://miti.sh/" + describe "http://webdevcat.me", -> it "permanently redirects to http://miti.sh", -> request = req "http://webdevcat.me" @@ -67,42 +74,42 @@ describe "http://apps.webdevcat.me/btroops", -> assert.same request\statusMessage!, "Moved Permanently" assert.same request\header!.Location, "http://apps.miti.sh/btroops" -describe "http://miti.sh", -> +describe "https://miti.sh", -> it "sends /index.html", -> - request = req "http://miti.sh" + request = req "https://miti.sh" assert.same request\statusCode!, 200 assert.same request\statusMessage!, "OK" assert.same request\body!\match("(.*)"), index_title -describe "http://miti.sh/index", -> +describe "https://miti.sh/index", -> it "sends /index.html", -> - request = req "http://miti.sh/index" + request = req "https://miti.sh/index" assert.same request\statusCode!, 200 assert.same request\statusMessage!, "OK" assert.same request\body!\match("(.*)"), index_title -describe "http://miti.sh/index.html", -> +describe "https://miti.sh/index.html", -> it "sends /index.html", -> - request = req "http://miti.sh/index.html" + request = req "https://miti.sh/index.html" assert.same request\statusCode!, 200 assert.same request\statusMessage!, "OK" assert.same request\body!\match("(.*)"), index_title -describe "http://miti.sh/posts/", -> +describe "https://miti.sh/posts/", -> it "permanently redirects to http://miti.sh/posts", -> - request = req "http://miti.sh/posts/" + request = req "https://miti.sh/posts/" assert.same request\statusCode!, 301 assert.same request\statusMessage!, "Moved Permanently" - assert.same request\header!.Location, "http://miti.sh/posts" + assert.same request\header!.Location, "https://miti.sh/posts" -describe "http://miti.sh/posts", -> +describe "https://miti.sh/posts", -> it "sends /posts/index.html", -> - request = req "http://miti.sh/posts" + request = req "https://miti.sh/posts" assert.same request\statusCode!, 200 assert.same request\statusMessage!, "OK" assert.same request\body!\match("(.*)"), "miti.sh · Posts" -describe "http://git.miti.sh", -> +describe "https://git.miti.sh", -> it "reverse-proxies request to a gitea unix socket", -> Path = require "sitegen.path" socket_fname = "unixstreamsrvr.moon" @@ -117,7 +124,7 @@ describe "http://git.miti.sh", -> result = Path.read_exec "find", socket_dir, "-type", "s", "-ls" assert.truthy result\match "nobody%s+root.+" .. Path.join(socket_dir, "gitea.socket") - req "http://git.miti.sh" + req "https://git.miti.sh" reqheader = with server\read "*a" server\close! -- 2.39.5 From 02d17d1b115dc0db8e957b221399575d445c2056 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Sat, 14 Jun 2025 11:04:33 -0700 Subject: [PATCH 20/26] Run socket server as user nobody in reverse-proxy spec --- spec/nginx_spec.moon | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/nginx_spec.moon b/spec/nginx_spec.moon index 8dc754c..2d79503 100644 --- a/spec/nginx_spec.moon +++ b/spec/nginx_spec.moon @@ -117,12 +117,12 @@ describe "https://git.miti.sh", -> socket_owner = "nobody" basepath = Path.basepath debug.getinfo(1).short_src - Path.mkdir socket_dir - server = io.popen "moon %s"\format Path.join(basepath, socket_fname) + Path.exec "install", "-o", socket_owner, "-d", socket_dir + cmd = "su -s /bin/bash -c 'moon %s' %s" + server = io.popen cmd\format Path.join(basepath, socket_fname), socket_owner Path.exec "sleep", "0.1" - Path.exec "chown", "-R", socket_owner, socket_dir result = Path.read_exec "find", socket_dir, "-type", "s", "-ls" - assert.truthy result\match "nobody%s+root.+" .. Path.join(socket_dir, "gitea.socket") + assert.truthy result\match "nobody%s+nogroup.+" .. Path.join(socket_dir, "gitea.socket") req "https://git.miti.sh" -- 2.39.5 From e8714ba8d4dfdd64d4f9b8ac4f4130bbab021a6c Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Sat, 14 Jun 2025 13:32:08 -0700 Subject: [PATCH 21/26] Serve apps.miti.sh with https --- conf/nginx.conf | 14 ++++++++++++-- spec/nginx_spec.moon | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 076e9e1..cb7e34c 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -64,8 +64,18 @@ http { } server { - server_name apps.miti.sh; - root /var/www/sites/apps.miti.sh; + listen 443 ssl; + server_name apps.miti.sh; + + root /var/www/sites/apps.miti.sh; + + include mime.types; + charset utf-8; + default_type text/html; + + location ^~ /.well-known/acme-challenge { + alias /var/www/dehydrated; + } } server { diff --git a/spec/nginx_spec.moon b/spec/nginx_spec.moon index 2d79503..c0c481c 100644 --- a/spec/nginx_spec.moon +++ b/spec/nginx_spec.moon @@ -131,8 +131,8 @@ describe "https://git.miti.sh", -> assert.truthy reqheader\match "Host: git.miti.sh" -describe "http://apps.miti.sh", -> +describe "https://apps.miti.sh", -> it "doesn't find it", -> - request = req "http://apps.miti.sh" + request = req "https://apps.miti.sh" assert.same request\statusCode!, 404 assert.same request\statusMessage!, "Not Found" -- 2.39.5 From 943ca92c3220ddde6229ab45113c1e3a348c06b9 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Sat, 14 Jun 2025 13:49:28 -0700 Subject: [PATCH 22/26] Serve webdevcat.me and subdomains with https --- conf/nginx.conf | 33 ++++++++++++++++++----- spec/nginx_spec.moon | 64 ++++++++++++++++++++++---------------------- 2 files changed, 59 insertions(+), 38 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index cb7e34c..69329bb 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -79,33 +79,54 @@ http { } server { - # listen 443 ssl; + listen 443 ssl; server_name webdevcat.me; include mime.types; charset utf-8; default_type text/html; + ssl_certificate /var/www/certs/webdevcat.me/fullchain.pem; + ssl_certificate_key /var/www/certs/webdevcat.me/privkey.pem; + location / { - return 301 http://miti.sh$request_uri; + return 301 https://miti.sh$request_uri; } location ~ ^/git/?(.*)$ { - return 301 http://git.miti.sh/ccm/$1; + return 301 https://git.miti.sh/ccm/$1; } location ~ ^/apps/(.*)$ { - return 301 http://apps.miti.sh/$1; + return 301 https://apps.miti.sh/$1; } } server { + listen 443 ssl; server_name git.webdevcat.me; - return 301 http://git.miti.sh$request_uri; + + ssl_certificate /var/www/certs/webdevcat.me/fullchain.pem; + ssl_certificate_key /var/www/certs/webdevcat.me/privkey.pem; + + location ^~ /.well-known/acme-challenge { + alias /var/www/dehydrated; + } + + return 301 https://git.miti.sh$request_uri; } server { + listen 443 ssl; server_name apps.webdevcat.me; - return 301 http://apps.miti.sh$request_uri; + + ssl_certificate /var/www/certs/webdevcat.me/fullchain.pem; + ssl_certificate_key /var/www/certs/webdevcat.me/privkey.pem; + + location ^~ /.well-known/acme-challenge { + alias /var/www/dehydrated; + } + + return 301 https://apps.miti.sh$request_uri; } } diff --git a/spec/nginx_spec.moon b/spec/nginx_spec.moon index c0c481c..dfd8403 100644 --- a/spec/nginx_spec.moon +++ b/spec/nginx_spec.moon @@ -18,61 +18,61 @@ describe "http://miti.sh", -> assert.same request\statusMessage!, "Moved Permanently" assert.same request\header!.Location, "https://miti.sh/" -describe "http://webdevcat.me", -> - it "permanently redirects to http://miti.sh", -> - request = req "http://webdevcat.me" +describe "https://webdevcat.me", -> + it "permanently redirects to https://miti.sh", -> + request = req "https://webdevcat.me" assert.same request\statusCode!, 301 assert.same request\statusMessage!, "Moved Permanently" - assert.same request\header!.Location, "http://miti.sh/" + assert.same request\header!.Location, "https://miti.sh/" -describe "http://webdevcat.me/git", -> - it "permanently redirects to http://git.miti.sh/ccm/", -> - request = req "http://webdevcat.me/git" +describe "https://webdevcat.me/git", -> + it "permanently redirects to https://git.miti.sh/ccm/", -> + request = req "https://webdevcat.me/git" assert.same request\statusCode!, 301 assert.same request\statusMessage!, "Moved Permanently" - assert.same request\header!.Location, "http://git.miti.sh/ccm/" + assert.same request\header!.Location, "https://git.miti.sh/ccm/" -describe "http://webdevcat.me/git/", -> - it "permanently redirects to http://git.miti.sh", -> - request = req "http://webdevcat.me/git" +describe "https://webdevcat.me/git/", -> + it "permanently redirects to https://git.miti.sh", -> + request = req "https://webdevcat.me/git" assert.same request\statusCode!, 301 assert.same request\statusMessage!, "Moved Permanently" - assert.same request\header!.Location, "http://git.miti.sh/ccm/" + assert.same request\header!.Location, "https://git.miti.sh/ccm/" -describe "http://webdevcat.me/git/pandoc", -> - it "permanently redirects to http://git.miti.sh/ccm/pandoc", -> - request = req "http://webdevcat.me/git/pandoc" +describe "https://webdevcat.me/git/pandoc", -> + it "permanently redirects to https://git.miti.sh/ccm/pandoc", -> + request = req "https://webdevcat.me/git/pandoc" assert.same request\statusCode!, 301 assert.same request\statusMessage!, "Moved Permanently" - assert.same request\header!.Location, "http://git.miti.sh/ccm/pandoc" + assert.same request\header!.Location, "https://git.miti.sh/ccm/pandoc" -describe "http://git.webdevcat.me", -> - it "permanently redirects to http://git.miti.sh/", -> - request = req "http://git.webdevcat.me" +describe "https://git.webdevcat.me", -> + it "permanently redirects to https://git.miti.sh/", -> + request = req "https://git.webdevcat.me" assert.same request\statusCode!, 301 assert.same request\statusMessage!, "Moved Permanently" - assert.same request\header!.Location, "http://git.miti.sh/" + assert.same request\header!.Location, "https://git.miti.sh/" -describe "http://webdevcat.me/apps/btroops", -> - it "permanently redirects to http://apps.miti.sh/btroops", -> - request = req "http://webdevcat.me/apps/btroops" +describe "https://webdevcat.me/apps/btroops", -> + it "permanently redirects to https://apps.miti.sh/btroops", -> + request = req "https://webdevcat.me/apps/btroops" assert.same request\statusCode!, 301 assert.same request\statusMessage!, "Moved Permanently" - assert.same request\header!.Location, "http://apps.miti.sh/btroops" + assert.same request\header!.Location, "https://apps.miti.sh/btroops" -describe "http://apps.webdevcat.me", -> - it "permanently redirects to http://apps.miti.sh/", -> - request = req "http://apps.webdevcat.me" +describe "https://apps.webdevcat.me", -> + it "permanently redirects to https://apps.miti.sh/", -> + request = req "https://apps.webdevcat.me" assert.same request\statusCode!, 301 assert.same request\statusMessage!, "Moved Permanently" - assert.same request\header!.Location, "http://apps.miti.sh/" + assert.same request\header!.Location, "https://apps.miti.sh/" -describe "http://apps.webdevcat.me/btroops", -> - it "permanently redirects to http://apps.miti.sh/btroops", -> - request = req "http://apps.webdevcat.me/btroops" +describe "https://apps.webdevcat.me/btroops", -> + it "permanently redirects to https://apps.miti.sh/btroops", -> + request = req "https://apps.webdevcat.me/btroops" assert.same request\statusCode!, 301 assert.same request\statusMessage!, "Moved Permanently" - assert.same request\header!.Location, "http://apps.miti.sh/btroops" + assert.same request\header!.Location, "https://apps.miti.sh/btroops" describe "https://miti.sh", -> it "sends /index.html", -> -- 2.39.5 From c0162f210e565953d59ebe79a1728ffdde9932ef Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Sat, 14 Jun 2025 14:02:11 -0700 Subject: [PATCH 23/26] Update gitea config file app.ini --- app.ini | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app.ini b/app.ini index c06ea4d..ba2d8d8 100644 --- a/app.ini +++ b/app.ini @@ -21,12 +21,13 @@ ROOT = /var/lib/gitea/data/gitea-repositories [server] ; SSH_DOMAIN = localhost -; SSH_DOMAIN = git.miti.sh ; DOMAIN = localhost -; DOMAIN = git.miti.sh +DOMAIN = git.miti.sh ; HTTP_PORT = 3000 -; ROOT_URL = http://localhost:3000/ -ROOT_URL = https://git.miti.sh:3000 +PROTOCOL = unix +ROOT_URL = https://git.miti.sh/ +HTTP_ADDR = /run/gitea/gitea.socket +LOCAL_ROOT_URL = APP_DATA_PATH = /var/lib/gitea/data DISABLE_SSH = false SSH_PORT = 22 -- 2.39.5 From 5d65aad8b5dc597147d67f58cee7f70c8abb3fd4 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Sat, 14 Jun 2025 14:09:42 -0700 Subject: [PATCH 24/26] Update prod nginx.conf --- conf/nginx.prod.conf | 120 ------------------------------------------- 1 file changed, 120 deletions(-) delete mode 100644 conf/nginx.prod.conf diff --git a/conf/nginx.prod.conf b/conf/nginx.prod.conf deleted file mode 100644 index 68e7585..0000000 --- a/conf/nginx.prod.conf +++ /dev/null @@ -1,120 +0,0 @@ -worker_processes 1; -error_log logs/error.log; - -events { - worker_connections 1024; -} - -http { - server { - listen 80; - listen 443 ssl; - - include mime.types; - charset utf-8; - default_type text/html; - - ssl_certificate /var/www/certs/miti.sh/fullchain.pem; - ssl_certificate_key /var/www/certs/miti.sh/privkey.pem; - - location ^~ /.well-known/acme-challenge { - alias /var/www/dehydrated; - } - - try_files $uri $uri/ $uri.html =404; - - # return `/posts/index.html` from `/posts` - location = /posts { - rewrite ^ /posts/ break; - } - - # redirect requests ending in a forward slash - location ~ ^/(.+)/$ { - return 302 /$1; - } - - location /css { - expires 1h; - alias css; - } - } - - server { - listen 443 ssl; - server_name git.miti.sh; - - location ^~ /.well-known/acme-challenge { - alias /var/www/dehydrated; - } - - location / { - client_max_body_size 1024M; - proxy_pass http://localhost:3000; - proxy_set_header Connection $http_connection; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - } - } - - server { - listen 443 ssl; - server_name apps.miti.sh; - - root /var/www/sites/apps.miti.sh; - - include mime.types; - charset utf-8; - default_type text/html; - - location ^~ /.well-known/acme-challenge { - alias /var/www/dehydrated; - } - } - - server { - listen 443 ssl; - server_name webdevcat.me; - - include mime.types; - charset utf-8; - default_type text/html; - - ssl_certificate /var/www/certs/webdevcat.me/fullchain.pem; - ssl_certificate_key /var/www/certs/webdevcat.me/privkey.pem; - - location ^~ /.well-known/acme-challenge { - alias /var/www/dehydrated; - } - - location / { - return 301 https://miti.sh$request_uri; - } - - location ~ ^/git/(.*)$ { - return 301 https://git.miti.sh/ccm/$1; - } - - location ~ ^/apps/(.*)$ { - return 301 https://apps.miti.sh/$1; - } - } - server { - listen 443 ssl; - server_name git.webdevcat.me; - - location ^~ /.well-known/acme-challenge { - alias /var/www/dehydrated; - } - } - server { - listen 443 ssl; - server_name apps.webdevcat.me; - - location ^~ /.well-known/acme-challenge { - alias /var/www/dehydrated; - } - } -} -- 2.39.5 From 576090d065bad4bcbc13f169896d62bb87af8424 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Sat, 14 Jun 2025 14:15:49 -0700 Subject: [PATCH 25/26] Add missing acme-challenge block to webdevcat.me server in nginx.conf --- conf/nginx.conf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/conf/nginx.conf b/conf/nginx.conf index 69329bb..e74cc14 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -89,6 +89,10 @@ http { ssl_certificate /var/www/certs/webdevcat.me/fullchain.pem; ssl_certificate_key /var/www/certs/webdevcat.me/privkey.pem; + location ^~ /.well-known/acme-challenge { + alias /var/www/dehydrated; + } + location / { return 301 https://miti.sh$request_uri; } -- 2.39.5 From a0f18520cb38e9f1dcd0bce61abf5271ba8acbe5 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Sat, 14 Jun 2025 14:26:42 -0700 Subject: [PATCH 26/26] Update README.md --- README.md | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 4132087..1cd7362 100644 --- a/README.md +++ b/README.md @@ -15,15 +15,19 @@ ### build docker image - $ docker build -t sitegen-openresty . + $ make image-build + +### rebuild an existing docker image + + $ make image-rm image-build ### generate a new site file - $ docker run --rm -w /opt -v $PWD:/opt sitegen-openresty sitegen new + $ docker run --rm -w /opt/app -v $PWD:/opt/app miti.sh sitegen new ### add an index page - $ docker run --rm -w /opt -v $PWD:/opt sitegen-openresty sitegen page /opt/ index + $ docker run --rm -w /opt/app -v $PWD:/opt/app miti.sh sitegen page /opt/app index ### add to `site.moon` @@ -50,17 +54,9 @@ ### build site - $ docker run --rm -w /opt/app -v $PWD:/opt/app sitegen-openresty sitegen - -or - $ make build -### start server - - $ docker run --rm -it --init -v $PWD:/opt/app -p 8080:8080 sitegen-openresty - -or +### start dev server $ make @@ -70,6 +66,10 @@ Visit `localhost:8080` in web browser $ docker exec -it container_name sitegen watch +### run tests + + $ make test + ### lint moonscript $ make lint @@ -82,10 +82,6 @@ example: $ pygmentize -S default -f html -### run tests - - $ make test - ## gotchas ### What is error `cosmo failed: [string "..."]:62: cannot resume dead coroutine`? @@ -104,8 +100,7 @@ to return `nil`, you will see this cryptic error: Delete your `.sitegen_cache` file. -## todo +## thinking about * draft documents * treesitter highlighting for moonscript -* penlight library -- 2.39.5