feat: add kiln feature

This commit is contained in:
valvin 2022-09-18 14:54:50 +02:00
parent 3211cce159
commit 72643fcc9b
9 changed files with 88 additions and 12 deletions

View File

@ -1,20 +1,24 @@
FROM debian:stretch-slim
FROM alpine:3.16 as build
ENV AGATE_VER 3.2.3
ENV AGATE_VER 3.2.4
RUN apk --no-cache add cargo
RUN cargo install agate --version ${AGATE_VER}
FROM alpine:3.16
ENV GEMINI_DOMAIN example.com
ENV GEMINI_GIT_REPO https://gitlab.com/valvin/gemini-agate-image
ENV GEMINI_GIT_PATH /app/data
ENV GEMINI_CONTENT_FOLDER content
ENV GEMINI_CERT_PATH /certs
ENV GEMINI_LANG fr-FR
ENV GEMINI_PORT 1965
ENV GEMINI_KILN_BUILD false
ENV GEMINI_KILN_SRC .
RUN apt update && apt install -y openssl git wget \
&& apt clean && rm -rf /var/lib/apt/lists/*
RUN apk --no-cache add openssl libgcc git kiln
RUN mkdir /app
RUN wget https://github.com/mbrubeck/agate/releases/download/v${AGATE_VER}/agate.x86_64-unknown-linux-gnu.gz -O /app/agate.gz \
&& cd /app && gunzip agate.gz && chmod +x agate
COPY --from=build /root/.cargo/bin/agate /app/agate
COPY entrypoint.sh /app/entrypoint.sh
EXPOSE 1965/tcp

View File

@ -9,6 +9,8 @@ This images takes these environment variables:
| `GEMINI_DOMAIN` | domain name of the capsule | example.com |
| `GEMINI_GIT_REPO` | url of the git repository containing content | `https://gitlab.com/valvin/gemini-agate-image` |
| `GEMINI_CONTENT_FOLDER` | folder inside the git repository which contains the content. it means you have `content` folder in your repo with default | `content`|
| `GEMINI_KILN_BUILD` | if set to `true` `kiln build` will be execute after an update of the repository | `false` |
| `GEMINI_KILN_SRC` | used when kiln build is enabled. path inside de git repository where kiln `config.toml` is located | `.` |
| `GEMINI_GIT_PATH` | path in which git repository will be cloned | `/app/data` |
| `GEMINI_CERT_PATH` | path which contains certificates. this path has to be a volume if not new certs will be generated | `/certs` |
| `GEMINI_LANG` | langage of the content | `fr-FR` |
@ -25,9 +27,24 @@ initialization process is:
docker command example:
* static files:
```
docker run --rm -it -e GEMINI_DOMAIN=mydomain.tld \
-e GEMINI_GIT_REPO=https://gitlab.com/valvin/gemini-agate-image \
-v $(pwd)/certs:/certs -p 1965:1965
-e GEMINI_CONTENT_FOLDER=content/static \
-v $(pwd)/certs:/certs -p 1965:1965 \
registry.gitlab.com/valvin/gemini-agate-image:latest
```
* kiln capsule:
```
docker run --rm -it -e GEMINI_DOMAIN=mydomain.tld \
-e GEMINI_GIT_REPO=https://gitlab.com/valvin/gemini-agate-image \
-e GEMINI_CONTENT_FOLDER=content/kiln/public \
-e GEMINI_KILN_BUILD=true \
-e GEMINI_KILN_SRC=content/kiln \
-v $(pwd)/certs:/certs -p 1965:1965 \
registry.gitlab.com/valvin/gemini-agate-image:latest
```

19
content/kiln/config.toml Normal file
View File

@ -0,0 +1,19 @@
title = "Example website"
[permalinks]
"/" = "/{{ .Date.Format `2006/01/02` }}/{{ path.Base .Path }}/"
[[tasks]]
name = "Gemini"
url = "gemini://example.com"
input = [".gmi"]
output = ".gmi"
template = ".gmi"
static_dir = "static"
output_dir = "public"
[[tasks.feeds]]
input_dir = "."
title = "Example feed"
template = "atom.xml"
output = "atom.xml"

View File

@ -0,0 +1,3 @@
---
title: Hello, world!
---

View File

@ -0,0 +1,13 @@
{{ `<?xml version="1.0" encoding="utf-8"?>` | safeHTML }}
<feed xmlns="http://www.w3.org/2005/Atom">
<id>{{ .URL }}</id>
<title>{{ .Title }}</title>
<updated>{{ site.Generated.Format "2006-01-02T15:04:05Z07:00" }}</updated>
<link href="{{ .URL | safeURL }}" rel="alternate"/>
{{ range .Pages }}<entry>
<id>{{ .URL }}</id>
<title>{{ .Title }}</title>
<updated>{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}</updated>
</entry>
{{ end -}}
</feed>

View File

@ -0,0 +1,6 @@
# {{ .Title }}
{{ if .Content }}
{{ .Content }}{{ end }}
{{ range .Pages }}=> {{ .Path }} {{ if not .Date.IsZero -}}
{{ .Date.Format "2006-01-02" }} {{end}}{{ .Title }}
{{ end -}}

View File

@ -0,0 +1,5 @@
# {{ .Title }}
{{- if not .Date.IsZero }}
Posted on {{ .Date.Format "2006-01-02" }}{{ end }}
{{ .Content }}

View File

@ -1,4 +1,5 @@
#!/bin/sh
set -e
create_new_cert(){
if [ ! -d "${GEMINI_CERT_PATH}" ]; then
mkdir ${GEMINI_CERT_PATH}
@ -9,6 +10,7 @@ create_new_cert(){
clone_repository(){
git clone ${GEMINI_GIT_REPO} ${GEMINI_GIT_PATH}
prepare_content
}
update_repository(){
@ -18,15 +20,22 @@ update_repository(){
else
cd ${GEMINI_GIT_PATH}
git pull
prepare_content
fi
}
prepare_content(){
if [ "${GEMINI_KILN_BUILD}" == "true" ]; then
echo "Building content with kiln..."
kiln build
fi
}
run_agate(){
/app/agate --content ${GEMINI_GIT_PATH}/${GEMINI_CONTENT_FOLDER} \
--key ${GEMINI_CERT_PATH}/key.rsa \
--cert ${GEMINI_CERT_PATH}/cert.pem \
--addr [::]:1965 \
--addr 0.0.0.0:1965 \
--certs ${GEMINI_CERT_PATH} \
--addr [::]:${GEMINI_PORT} \
--addr 0.0.0.0:${GEMINI_PORT} \
--hostname ${GEMINI_DOMAIN} \
--lang ${GEMINI_LANG}
}