Repository: mbrubeck/agate (language: rust)

Issue:
Add ghcr.io Docker container generation to workflow actions
There's an open PR for improving the docker image size, which would be great to get merged.

But also it's difficult to deploy to any non-local server or kubernetes without a prebuilt image.

[This page from github support](https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#upgrading-a-workflow-that-accesses-a-registry-using-a-personal-access-token) has pretty much a ready-to-go example for adding docker image generation to workflows. Until then I'll be having to copy images manually over ssh to my server, which is not ideal.


Discussion / hints:
As noted in https://github.com/mbrubeck/agate/pull/144#issuecomment-1110073345 I am still waiting for modifications to be made to that pull request. To clarify that I think that pull request is not complete I have marked it as a draft.

As noted in https://github.com/mbrubeck/agate/issues/145#issuecomment-1033561978 I am not knowledgeable in Docker. If you want the thing you mentioned, feel free to open a pull request.
Thanks for the info.
For what it's worth, I've used [@timwalls' Dockerfile](https://github.com/timwalls/agate/blob/master/Dockerfile) in the past and it's been great, but his repo is now several years behind this one. I am happy to provide a PR that merges his version's more canonical approach to copying source, with the same directory and calling conventions as this repo's one, so as to reduce the likelihood of a breaking change. I will look at what is needed to get github actions to compile the image too.

Fix patch:
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index b3219d8..aee6af6 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -71,3 +71,42 @@ jobs:
         files: 'agate.*.gz'
         repo-token: ${{ secrets.GITHUB_TOKEN }}
         release-tag: ${{ github.ref_name }}
+
+  build_docker:
+    runs-on: ubuntu-latest
+    permissions:
+      contents: read
+      packages: write
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v4
+        with:
+          fetch-depth: 0
+      - name: Log into GHCR
+        uses: docker/login-action@v3
+        with:
+          registry: ghcr.io
+          username: ${{ github.actor }}
+          password: ${{ secrets.GITHUB_TOKEN }}
+      - name: Extract metadata for Docker
+        id: meta
+        uses: docker/metadata-action@v5
+        with:
+          images: ghcr.io/${{ github.repository }}
+          # Because this workflow only runs on commits tagged `v*` (i n semver format) this section ensures that
+          # a docker build tagged `v1.2.3+podman.build` is tagged with `1`, `1.2`, `1.2.3` and `1.2.3+podman.build`
+          # as well as being tagged with `latest`. For each of these, a subsequent build that has the same tag will
+          # replace it. This means that pulling `ghcr.io/mbrubeck/agate:1` will always get the most recent image
+          # released with a v1 tag, container, `ghcr.io/mbrubeck/agate:1.2` will get the latest v1.2 tag, and so on.
+          tags: |
+            type=semver,pattern={{version}}
+            type=semver,pattern={{major}}.{{minor}}.{{patch}}
+            type=semver,pattern={{major}}.{{minor}}
+            type=semver,pattern={{major}}
+      - name: Build and push Docker image
+        id: push
+        uses: docker/build-push-action@v6
+        with:
+          push: true
+          tags: ${{ steps.meta.outputs.tags }}
+          labels: ${{ steps.meta.outputs.labels }}
diff --git a/README.md b/README.md
index fbd952c..99ed237 100644
--- a/README.md
+++ b/README.md
@@ -38,6 +38,23 @@ Install the package [`agate-bin`](https://aur.archlinux.org/packages/agate-bin/)
 
 If you have the Rust toolchain installed, run `cargo install agate` to install agate from crates.io.
 
+### Docker
+
+Recent builds have also been released as OCI/Docker images on Github's Container Registry (ghcr.io). Most people will need to mount two volumes, one for your content, one for your certificates (this can be empty, they will be automatically generated if needed):
+
+```sh
+$ docker run \
+  -p 1965:1965 \
+  -v your/path/to/gmi:/gmi \
+  -v your/path/to/certs:/certs \
+  ghcr.io/mbrubeck/agate:latest \
+  --hostname example.org
+```
+
+This container will run without a mounted certificates directory, but new certificates will be lost when it shuts down and re-generated every time it boots, showing your site's visitors a certificate warning each time your server restarts.
+
+Each release is tagged with `major`, `major.minor`, `major.minor.patch`, as well as the full version string and "latest". This means `docker pull ghcr.io/mbrubeck/agate:3` will always retrieve the latest `v3.*` image, `…:3.3` the latest `v3.3.*` image, and `…:latest` the most recent release of any version.
+
 ### Source
 
 Download the source code and run `cargo build --release` inside the source repository, then find the binary at `target/release/agate`.
diff --git a/tools/docker/README.md b/tools/docker/README.md
deleted file mode 100644
index 8d64ec7..0000000
--- a/tools/docker/README.md
+++ /dev/null
@@ -1,49 +0,0 @@
-# Install agate in a docker container
-(these instructions assume you use linux and have some experience with both docker and the command line)
-## obtain the source code
-
-There are currently no container images online so you have to build the image yourself before you can use it.
-There are two options available for this: downloading a release or cloning the repository with `git`.
-I will explain both methods but if you're unsure which method to use, I would recommend the release for new comers because it's probably more tested so you'll encounter less problems.
-
-### downloading the release tarball
-
-Download the tarball. Go to [https://github.com/mbrubeck/agate/releases/latest](https://github.com/mbrubeck/agate/releases/latest), and copy the url of the source code tarball.
-
-```
-wget URL
-```
-
-Then unpack the tarball and remove it afterwards:
-```
-tar -xzf tarball.tar.gz
-rm tarball.tar.gz
-```
-
-### clone the repository with git
-
-I assume you have git already installed. If not, please search on how to do it in the internet.
-
-```
-git clone https://github.com/mbrubeck/agate
-cd agate
-```
-
-## build the image
-
-Now build the docker image:
-
-```
-docker build -t agate .
-```
-This process will take a few minutes because all the rust modules have to be compiled from source.
-
-## start the docker container
-
-```
-docker run -t -d --name agate -p 1965:1965 -v path/to/gmi:/gmi:ro -v path/to/certs:/certs:rw agate:latest --hostname localhost
-```
-
-You have to replace `/var/www/gmi/` with the folder where you'd like to have gemtext files and `/var/www/gmi/.certificates/` with the folder where you'd like to have your certificates stored. You also have to have to replace `example.org` with your domain name and if plan to speak in a different language than english in your gemini space than you should replace `en-US` with your countries language code (for example de-DE or fr-CA).
-
-## That's it! Now have agate running in a docker container!


Test patch: