diff --git a/Dockerfile b/Dockerfile index 6b8b4c8..d9df6fd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/README.md b/README.md index 3f3c563..f6601e9 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/content/kiln/config.toml b/content/kiln/config.toml new file mode 100644 index 0000000..3dc2bdc --- /dev/null +++ b/content/kiln/config.toml @@ -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" diff --git a/content/kiln/content/_index.gmi b/content/kiln/content/_index.gmi new file mode 100644 index 0000000..a43abfc --- /dev/null +++ b/content/kiln/content/_index.gmi @@ -0,0 +1,3 @@ +--- +title: Hello, world! +--- diff --git a/content/kiln/templates/_default/atom.xml b/content/kiln/templates/_default/atom.xml new file mode 100644 index 0000000..d702ccd --- /dev/null +++ b/content/kiln/templates/_default/atom.xml @@ -0,0 +1,13 @@ +{{ `` | safeHTML }} + +{{ .URL }} +{{ .Title }} +{{ site.Generated.Format "2006-01-02T15:04:05Z07:00" }} + +{{ range .Pages }} + {{ .URL }} + {{ .Title }} + {{ .Date.Format "2006-01-02T15:04:05Z07:00" }} + +{{ end -}} + diff --git a/content/kiln/templates/_default/index.gmi b/content/kiln/templates/_default/index.gmi new file mode 100644 index 0000000..a8fe4d8 --- /dev/null +++ b/content/kiln/templates/_default/index.gmi @@ -0,0 +1,6 @@ +# {{ .Title }} +{{ if .Content }} +{{ .Content }}{{ end }} +{{ range .Pages }}=> {{ .Path }} {{ if not .Date.IsZero -}} +{{ .Date.Format "2006-01-02" }} {{end}}{{ .Title }} +{{ end -}} diff --git a/content/kiln/templates/_default/page.gmi b/content/kiln/templates/_default/page.gmi new file mode 100644 index 0000000..c9de13a --- /dev/null +++ b/content/kiln/templates/_default/page.gmi @@ -0,0 +1,5 @@ +# {{ .Title }} +{{- if not .Date.IsZero }} +Posted on {{ .Date.Format "2006-01-02" }}{{ end }} + +{{ .Content }} diff --git a/content/index.gmi b/content/static/index.gmi similarity index 100% rename from content/index.gmi rename to content/static/index.gmi diff --git a/entrypoint.sh b/entrypoint.sh index 38f4969..9974f67 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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} }