🏡 index : ~doyle/pisshoff.git

author Jordan Doyle <jordan@doyle.la> 2023-08-14 21:37:31.0 +00:00:00
committer Jordan Doyle <jordan@doyle.la> 2023-08-14 21:38:48.0 +00:00:00
commit
62439b2ad955840f5899ec8e609caf6d73861d5b [patch]
tree
694ed6e04f3cbdced6fee14ff56cb684ad67aa32
parent
250f055fd61a54b4446e00e50cd63aa02541c0ed
download
62439b2ad955840f5899ec8e609caf6d73861d5b.tar.gz

Add installation instructions for Docker & NixOS



Diff

 .dockerignore                        |  2 ++-
 .github/workflows/docker-publish.yml | 45 +++++++++++++++++++++++++++++++++++-
 Dockerfile                           | 21 +++++++++++++++++-
 README.md                            | 47 +++++++++++++++++++++++++++++++++++++-
 4 files changed, 115 insertions(+)

diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..a099dca
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,2 @@
target
Dockerfile
diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml
new file mode 100644
index 0000000..8694f26
--- /dev/null
+++ b/.github/workflows/docker-publish.yml
@@ -0,0 +1,45 @@
name: Docker

on:
  schedule:
    - cron: '45 20 * * *'
  push:
    branches: [ master ]

env:
  # Use docker.io for Docker Hub if empty
  REGISTRY: ghcr.io
  # github.repository as <account>/<repo>
  IMAGE_NAME: ${{ github.repository }}

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
      - name: Setup Docker buildx
        uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
      - name: Log into registry ${{ env.REGISTRY }}
        if: github.event_name != 'pull_request'
        uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Extract Docker metadata
        id: meta
        uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
        with:
          images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
      - name: Build and push Docker image
        id: build-and-push
        uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
        with:
          context: .
          push: ${{ github.event_name != 'pull_request' }}
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..b0de74e
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,21 @@
FROM rust:1.71-slim AS builder

RUN apt-get update && apt-get install -y libsodium-dev pkg-config

COPY . /sources
WORKDIR /sources
RUN cargo build --release
RUN chown nobody:nogroup /sources/target/release/pisshoff-server

FROM debian:bullseye-slim

RUN apt-get update && apt-get install -y libsodium23 && rm -rf /var/lib/apt/lists/*

COPY --from=builder /sources/target/release/pisshoff-server /pisshoff-server
COPY --from=builder /sources/pisshoff-server/config.toml /config.toml

RUN touch audit.jsonl && chown nobody audit.jsonl

USER nobody
EXPOSE 2233
ENTRYPOINT ["/pisshoff-server", "-c", "/config.toml"]
diff --git a/README.md b/README.md
index ff67af2..b07c547 100644
--- a/README.md
+++ b/README.md
@@ -185,8 +185,55 @@ $ cat audit.log | tail -n 2 | jq

## Running the server

### From source

An [example configuration][] is provided within the repository, running the server is as simple
as building the binary using [`cargo build --release`][] and calling `./pisshoff-server -c config.toml`.

[example configuration]: https://github.com/w4/pisshoff/blob/master/pisshoff-server/config.toml
[`cargo build --release`]: https://www.rust-lang.org/

### NixOS

Running pisshoff on NixOS is extremely simple, simply import the module into your flake.nix and use the provided service:

```nix
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";

    pisshoff = {
      url = "github:w4/pisshoff";
      inputs.nixpkgs = "nixpkgs";
    };
  };

  outputs = { nixpkgs, ... }: {
    nixosConfigurations.mySystem = nixpkgs.lib.nixosSystem {
      modules = [
        pisshoff.nixosModules.default
        {
          services.pisshoff = {
            enable = true;
            settings = {
              listen-address = "127.0.0.1:2233";
              access-probability = "0.2";
              audit-output-file = "/var/log/pisshoff/audit.jsonl";
            };
          };
        }
        ...
      ];
    };
  };
}
```

### Docker

Running pisshoff in Docker is also simple:

```bash
$ docker run -d --name pisshoff ghcr.io/w4/pisshoff:master
$ docker exec -it pisshoff tail -f audit.jsonl
```