Changes
8 changed files (+173/-69)
-
-
@@ -27,3 +27,24 @@ This project use [dprint](https://dprint.dev/).You have to install [`nixfmt`](https://github.com/NixOS/nixfmt) and Go toolchain as well. Nix user can run `nix fmt` without installing or configuring anything. ## Build an OCI Image You can build an [OCI](https://opencontainers.org/) image easily with [podman](https://podman.io/). legit works perfectly fine in an unprivilege (rootless) container. On the project root directory run the following command: ```sh podman build . -t pocka/legit ``` That would create and register `pocka/legit` image on your local registry. To test the image works, run the following command: ```sh podman run --volume ./demo:/var/www/legit --publish 5555:5555 pocka/legit:latest ``` If you don't have podman on your NixOS system and quickly test these steps, use `nix develop .#podman` devShell. It has podman and configures minimum podman environment.
-
-
Dockerfile (new)
-
@@ -0,0 +1,57 @@# Copyright 2026 Shota FUJI <pockawoooh@gmail.com> # SPDX-License-Identifier: MIT FROM golang:1.26-alpine3.24 AS build WORKDIR /app # Download external modules for caching. COPY go.mod go.sum ./ RUN go mod download # Copy source files needed for building the binary. COPY *.go ./ COPY config/*.go ./config/ COPY renderer ./renderer COPY git ./git COPY routes ./routes COPY embed ./embed RUN go build -o /bin/legit # Scratch image does not have mkdir. RUN mkdir -p /var/www/legit # --- FROM scratch WORKDIR /etc/legit COPY --from=build /bin/legit /bin/legit # Mount "config.yaml" file at "/etc/legit/config.yaml". # You can optionally mount "static" and "templates" directories under "/etc/legit/" # then tell legit to read them. # # dirs: # templates: /etc/legit/templates # static: /etc/legit/static COPY config/base.yaml /etc/legit/config.yaml VOLUME ["/etc/legit"] # "/var/www/legit" holds git repositories to host. You have to mount at this # otherwise legit hosts empty top page, which is useless. COPY --from=build /var/www/legit /var/www/legit VOLUME ["/var/www/legit"] # legit serves HTTP content on this TCP port. Bind it to host's :80 or whatever # you want. EXPOSE 5555 # File paths and listen address depend on how the container was built. # Users are not supposed to change these options. CMD [ \ "/bin/legit", \ "-config", "/etc/legit/config.yaml", \ "-server.host", "0.0.0.0", \ "-server.port", "5555", \ "-repo.scanPath", "/var/www/legit" \ ]
-
-
-
@@ -54,6 +54,29 @@ final: prev:Runtime error will happen if Go toolchain in your nixpkgs is older than v1.24.1. ### OCI (Docker, Podman) Build the image on the project root. The image exposes TCP port 5555 for HTTP server. Generated image expectes two volume mounts: - `/var/www/legit` ... a directory containing git repositories to host. - `/etc/legit/config.yaml` ... config file for UI and metadata customization. Example commands using podman: ```sh podman build . -t pocka/legit podman run -v ./demo:/var/www/legit -v ./config.yaml:/etc/legit/config.yaml --publish 5555:5555 pocka/legit:latest ``` OCI image entrypoint overwrites these config options, so values inside your `config.yaml` will be ignored: - `server.host` - `server.port` - `repo.scanPath` ## Configuration legit reads YAML config file. Create YAML file somewhere (e.g. `$XDG_CONFIG_HOME/legit/config.yaml`) and pass the path to legit via `--config` flag.
-
-
config/base.yaml (new)
-
@@ -0,0 +1,23 @@# Copyright 2026 Shota FUJI <pockawoooh@gmail.com> # SPDX-License-Identifier: MIT # # Minimal config as a customization base. # # This config assumes you supply "-server.host", "-server.port" and # "-repo.scanPath" CLI options. # # Docker image uses this file as a fallback config. meta: # For top page heading and website's "<title>". title: "legit" # For top page description and "<meta name="description">" description: "" # Enables syntax highlighting on blob page. syntaxHighlight: true ui: footer: poweredBy: true
-
-
contrib/Dockerfile (deleted)
-
@@ -1,22 +0,0 @@FROM golang:1.22-alpine AS builder WORKDIR /app COPY . . RUN go mod download RUN go mod verify RUN go build -o legit FROM scratch AS build-release-stage WORKDIR /app COPY static ./static COPY templates ./templates COPY config.yaml ./ COPY --from=builder /app/legit ./ EXPOSE 5555 CMD ["./legit"]
-
-
contrib/docker-compose.yml (deleted)
-
@@ -1,14 +0,0 @@services: legit: container_name: legit build: context: ../ dockerfile: contrib/Dockerfile restart: unless-stopped ports: - "5555:5555" volumes: - /var/www/git:/var/www/git - ../config.yaml:/app/config.yaml - ../static:/app/static - ../templates:/app/templates
-
-
contrib/legit.service (deleted)
-
@@ -1,17 +0,0 @@[Unit] Description=legit Server After=network-online.target Requires=network-online.target [Service] User=git Group=git ExecStart=/usr/bin/legit -config /etc/legit/config.yaml ProtectSystem=strict ProtectHome=strict NoNewPrivileges=true PrivateTmp=true PrivateDevices=true [Install] WantedBy=multi-user.target
-
-
-
@@ -75,22 +75,6 @@repos ]; }; docker = pkgs.dockerTools.buildLayeredImage { name = "sini:5000/legit"; tag = "latest"; contents = [ files legit pkgs.git ]; config = { Entrypoint = [ "${legit}/bin/legit" ]; ExposedPorts = { "5555/tcp" = { }; }; }; }; } );
-
@@ -137,6 +121,55 @@gopls ]; }; # For those who don't have podman on system. podman = let conf = pkgs.stdenv.mkDerivation { name = "podman-config-files"; # No source. unpackPhase = "true"; postInstall = '' mkdir $out cat > $out/registries.conf <<EOF unqualified-search-registries = ["docker.io"] EOF # This is meant to be copied under ~/.config/containers/ cat > $out/policy.json <<EOF { "default": [{ "type": "insecureAcceptAnything" }] } EOF cat > $out/containers.conf <<EOF [engine] cgroup_manager="cgroupfs" events_logger="file" EOF ''; }; in pkgs.mkShell { packages = with pkgs; [ podman conf ]; shellHook = '' if [[ ! -f ~/.config/containers/policy.json && ! -f /etc/containers/policy.json ]]; then echo "Create policy.json file for podman." echo "https://podman.io/docs/installation#policyjson" echo "If you are okay with insecureAcceptAnything for all, run:" echo "install -Dm555 ${conf}/policy.json ~/.config/containers/policy.json" fi ''; CONTAINERS_REGISTRIES_CONF = "${conf}/registries.conf"; CONTAINERS_CONF = "${conf}/containers.conf"; }; } ); };
-