Update post

This commit is contained in:
Catalin Constantin Mititiuc 2025-06-26 18:14:32 -07:00
parent 3cb0b83e8a
commit be52884226

View File

@ -8,22 +8,32 @@ $index
We'll need nginx and luarocks. Buildpack has luarocks installed. We'll need nginx and luarocks. Buildpack has luarocks installed.
docker pull openresty/openresty:bookworm-buildpack ```console
$ docker pull openresty/openresty:bookworm-buildpack
```
Start a server on `localhost`:
```console
$ docker run --rm -it -p 80:80 openresty/openresty:bookworm-buildpack $ docker run --rm -it -p 80:80 openresty/openresty:bookworm-buildpack
```
Visit `localhost` in browser. Should see OpenResty splash page. Visit `localhost` in browser. Should see OpenResty splash page.
![OpenResty default nginx index page](/images/openresty-default-index-page.png) ![OpenResty default nginx index page](/images/openresty-default-index-page.png)
https://openresty.org/en/getting-started.html#prepare-directory-layout [Prepare directory layout](ehttps://openresty.org/en/getting-started.html#prepare-directory-layout)
```console
$ mkdir -p logs/ conf/conf.d/ html/ $ mkdir -p logs/ conf/conf.d/ html/
```
https://github.com/openresty/docker-openresty?tab=readme-ov-file#nginx-config-files [Copy config file](https://github.com/openresty/docker-openresty?tab=readme-ov-file#nginx-config-files)
```console
$ docker run --rm -it -w /opt -v $PWD:/opt openresty/openresty:bookworm-buildpack \ $ docker run --rm -it -w /opt -v $PWD:/opt openresty/openresty:bookworm-buildpack \
cp /etc/nginx/conf.d/default.conf /opt/conf.d/ cp /etc/nginx/conf.d/default.conf /opt/conf.d/
```
edit default.conf edit default.conf
change `root /usr/local/openresty/nginx/html;` to: change `root /usr/local/openresty/nginx/html;` to:
@ -149,7 +159,9 @@ container does not have access to the internet, otherwise we might
unintentionally get a response from a domain's server on the internet rather unintentionally get a response from a domain's server on the internet rather
than from our test server. than from our test server.
```console
$ docker network create --internal no-internet $ docker network create --internal no-internet
```
Now we can start the test server with our host: Now we can start the test server with our host:
@ -287,8 +299,7 @@ server {
Rebuild the image: Rebuild the image:
```console ```console
$ make image-rm $ make image-rm image-build
$ make image-build
``` ```
Run tests: Run tests:
@ -323,7 +334,7 @@ $ make test
3 successes / 0 failures / 0 errors / 0 pending : 0.017065 seconds 3 successes / 0 failures / 0 errors / 0 pending : 0.017065 seconds
``` ```
## Reverse proxy a subdomain to a Gitea unix socket ## Reverse proxy a subdomain to a unix socket
Add to `default.conf`: Add to `default.conf`:
@ -351,13 +362,13 @@ Add subdomain to certs in Dockerfile:
-addext "subjectAltName=DNS:domain.abc,DNS:git.domain.abc" -addext "subjectAltName=DNS:domain.abc,DNS:git.domain.abc"
``` ```
Add a test socket server: Add a test socket server (copied and modified from [here](https://github.com/lunarmodules/luasocket/blob/4844a48fbf76b0400fd7b7e4d15d244484019df1/test/unixstreamsrvr.lua)):
::: filename-for-code-block
`spec/unixstreamsrvr.moon` `spec/unixstreamsrvr.moon`
:::
```moonscript ```moonscript
-- modified from
-- https://github.com/lunarmodules/luasocket/blob/4844a48fbf76b0400fd7b7e4d15d244484019df1/test/unixstreamsrvr.lua
socket = require "socket" socket = require "socket"
socket.unix = require "socket.unix" socket.unix = require "socket.unix"
u = assert socket.unix.stream! u = assert socket.unix.stream!
@ -384,7 +395,7 @@ describe "https://git.domain.abc", ->
os.execute "install -o #{socket.owner} -d #{socket.dir}" os.execute "install -o #{socket.owner} -d #{socket.dir}"
cmd = "su -s /bin/bash -c 'moon %s' %s" cmd = "su -s /bin/bash -c 'moon %s' %s"
server = io.popen cmd\format "#{basepath}/#{socket.fname}", socket.owner server = io.popen cmd\format "#{basepath}/#{socket.fname}", socket.owner
os.execute "sleep #{seconds}" os.execute "sleep #{seconds}" -- wait for server to start
f = io.popen "find #{socket.dir} -type s -ls", "r" f = io.popen "find #{socket.dir} -type s -ls", "r"
result = with f\read "*a" result = with f\read "*a"
f\close! f\close!
@ -423,4 +434,28 @@ $ make test
## Bonus!: Issues We Ran Into Just Trying To Make This Post ## Bonus!: Issues We Ran Into Just Trying To Make This Post
1. `$host$request_uri` 1. `$host$request_uri`
`renderers/markdown.moon`
```moonscript
dollar_temp = "0000sitegen_markdown00dollar0000"
```
So, when two cosmo selectors had no space between them, it was ambiguous
to which selector the numbers belonged.
```
0000sitegen_markdown00dollar0000.10000sitegen_markdown00dollar0000.2
```
Solution was to change the first `0` to a letter `z`:
```
z000sitegen_markdown00dollar0000.1z000sitegen_markdown00dollar0000.2
```
Because `dollar_temp` is a private attribute, I had to copy every function
from the sitegen markdown renderer. Which makes my renderer a copy with
some additions.
2. `$$ct` 2. `$$ct`