From 68c939762e536d6f27c6df5d2cba00944c5a22df Mon Sep 17 00:00:00 2001 From: JP Hastings-Spital Date: Tue, 30 Apr 2024 19:59:10 +0100 Subject: [PATCH] Gemini: server (fly.io, non-functional) This puts the framework for building a statically compiled agate into a scratch Docker image which can be run from fly.io (as well as the fly.toml that sets it up correctly). This doesn't seem to work on fly.io itself at the moment, so more tinkering soon, but it works locally. --- .dockerignore | 2 ++ .github/workflows/publish.yml | 6 ++++++ Dockerfile | 11 +++++++++++ Taskfile.yml | 13 ++++++++++--- fly.toml | 31 +++++++++++++++++++++++++++++++ 5 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 fly.toml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..626389ed --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +* +!/public/ diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 487012ed..11c602be 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -29,6 +29,7 @@ jobs: HUGO_VERSION: 0.125.4 PAGEFIND_VERSION: 1.1.0 TASK_VERSION: 3.36.0 + RESTIC_VERSION: 0.16.4 steps: - name: Install Hugo CLI run: | @@ -44,6 +45,11 @@ jobs: wget -q -O ${{ runner.temp }}/task.tar.gz https://github.com/go-task/task/releases/download/v${TASK_VERSION}/task_linux_amd64.tar.gz \ && tar -xpf ${{ runner.temp }}/task.tar.gz task \ && mv task /usr/local/bin/task + - name: Install Restic CLI + run: | + wget -q -O ${{ runner.temp }}/restic.bz2 https://github.com/restic/restic/releases/download/v${RESTIC_VERSION}/restic_${RESTIC_VERSION}_linux_amd64.bz2 \ + && bunzip2 ${{ runner.temp }}/restic.bz2 \ + && mv restic /usr/local/bin/restic - name: Checkout uses: actions/checkout@v3 with: diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..5bb2e116 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM ghcr.io/rust-cross/rust-musl-cross:x86_64-unknown-linux-musl as agate + +RUN cargo install agate + +FROM scratch +COPY --from=agate /root/.cargo/bin/agate /bin/agate +COPY ./public/ /var/agate/content/ + +EXPOSE 1965 + +ENTRYPOINT ["/bin/agate", "--content", "/var/agate/content/", "--addr", "0.0.0.0:1965", "--only-tls13", "--central-conf", "--lang", "en-GB", "--certs", "/var/agate/certificates/", "--hostname", "byjp.cc"] diff --git a/Taskfile.yml b/Taskfile.yml index 5ade922a..17e5fe9a 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -4,6 +4,7 @@ version: '3' vars: domain: www.byjp.me + gmi_domain: byjp.cc puma_dev_tld: .test env: @@ -54,14 +55,20 @@ tasks: - find -E ./public -regex '.*\.(html|js|css|css\.map|webmanifest|xml|xsl|ico|opml)' -type f -delete # Remove specific unneeded files - rm -rf ./public/favicon*.png ./public/_redirects ./public/{apple,android,mstile}*.png ./public/safari-pinned-tab.svg ./public/robots.txt - # Remove specific unneeded direcctories + # Remove specific unneeded directories - rm -rf ./public/.well-known/ ./public/fonts/ ./public/standalone/project-prime/ # Remove empty directories - find ./public -type d -empty -delete gemini-dev: desc: Builds the site & starts a gemini server (on the default port) for it. - deps: [ build ] cmds: - - agate --content public --lang en-GB --hostname "{{ .domain }}{{ .puma_dev_tld }}" --central-conf + - agate --content public --addr 0.0.0.0:1965 --ed25519 --only-tls13 --lang en-GB --hostname "{{ .gmi_domain }}{{ .puma_dev_tld }}" --central-conf + gemini-deploy: + desc: Builds, reduces, and deploys the gemini version of the site with fly. + deps: + - build + - gemini-reduce + cmds: + - fly deploy diff --git a/fly.toml b/fly.toml new file mode 100644 index 00000000..da47fcc2 --- /dev/null +++ b/fly.toml @@ -0,0 +1,31 @@ +# fly.toml app configuration file generated for byjp-cc on 2024-04-30T15:16:09+01:00 +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# + +app = 'byjp-cc' +primary_region = 'lhr' + +[build] + +[[files]] + guest_path = "/var/agate/certificates/byjp.cc/cert.der" + secret_name = "AGATE_CERT" + +[[files]] + guest_path = "/var/agate/certificates/byjp.cc/key.der" + secret_name = "AGATE_KEY" + +[[services]] + internal_port = 1965 + auto_stop_machines = true + auto_start_machines = true + min_machines_running = 0 + + [[services.ports]] + port = 1965 + +[[vm]] + memory = '1gb' + cpu_kind = 'shared' + cpus = 1