diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8d671ca --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +# The Go build needs only the Go sources and the module files. +java/ +.git +.claude +deploy/ +bin/ diff --git a/.github/workflows/chart.yml b/.github/workflows/chart.yml new file mode 100644 index 0000000..74cd2b6 --- /dev/null +++ b/.github/workflows/chart.yml @@ -0,0 +1,46 @@ +name: chart + +# Helm chart checks: lint, render and validate the rendered manifests against the Kubernetes schemas. +# None of them needs a cluster. + +on: + pull_request: + paths: + - "deploy/helm/**" + - ".github/workflows/chart.yml" + push: + branches: [main] + paths: + - "deploy/helm/**" + - ".github/workflows/chart.yml" + +permissions: + contents: read + +env: + KUBECONFORM_VERSION: "0.6.7" + +jobs: + helm: + name: Helm chart + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v7 + with: + persist-credentials: false + + - name: Set up Helm + uses: azure/setup-helm@v5 + + - name: Lint the chart + run: helm lint deploy/helm/grus -f deploy/helm/grus/ci/lint-values.yaml + + - name: Install kubeconform + run: | + curl -fsSL "https://github.com/yannh/kubeconform/releases/download/v${KUBECONFORM_VERSION}/kubeconform-linux-amd64.tar.gz" \ + | tar -xz -C "$RUNNER_TEMP" kubeconform + echo "$RUNNER_TEMP" >> "$GITHUB_PATH" + + - name: Validate the rendered manifests + run: helm template grus deploy/helm/grus -f deploy/helm/grus/ci/lint-values.yaml | kubeconform -strict -ignore-missing-schemas -summary diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..c37530c --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,47 @@ +name: go + +# Controller and agent checks: formatting, vet, tests and builds of the Go module. The guard at the end +# keeps the agent free of the Kubernetes client, which only the controller may depend on. + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +jobs: + go: + name: Go + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v7 + with: + persist-credentials: false + + - name: Set up Go + uses: actions/setup-go@v7 + with: + go-version-file: go.mod + cache: true + + - name: Check formatting + run: test -z "$(gofmt -l .)" + + - name: Vet + run: go vet ./... + + - name: Test + run: go test ./... + + - name: Build the commands + run: go build ./cmd/... + + - name: Keep the Kubernetes client out of the agent + run: | + if go list -deps ./cmd/grus-agent | grep -q '^k8s.io/'; then + echo "::error::cmd/grus-agent must not depend on k8s.io/*" + exit 1 + fi diff --git a/.github/workflows/java.yml b/.github/workflows/java.yml new file mode 100644 index 0000000..9dc5612 --- /dev/null +++ b/.github/workflows/java.yml @@ -0,0 +1,42 @@ +name: java + +# Gradle build of the Java modules (SDK, Velocity plugin, Minestom demo) under java/. + +on: + pull_request: + paths: + - "java/**" + - ".github/workflows/java.yml" + push: + branches: [main] + paths: + - "java/**" + - ".github/workflows/java.yml" + +permissions: + contents: read + +jobs: + gradle: + name: Gradle + runs-on: ubuntu-latest + defaults: + run: + working-directory: java + steps: + - name: Checkout + uses: actions/checkout@v7 + with: + persist-credentials: false + + - name: Set up JDK 25 + uses: actions/setup-java@v6 + with: + distribution: temurin + java-version: "25.0.3" + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v6 + + - name: Build + run: ./gradlew build --max-workers=2 diff --git a/.github/workflows/pr-lint.yml b/.github/workflows/pr-lint.yml new file mode 100644 index 0000000..5019514 --- /dev/null +++ b/.github/workflows/pr-lint.yml @@ -0,0 +1,17 @@ +name: pr-lint + +# Conventional Commits on the pull request title, which is the squash commit that lands on main, and +# on every commit of the branch. release-please reads the commit types for the version and the +# changelog. The commit rules are in commitlint.config.mjs, which the reusable workflow reads. + +on: + pull_request: + types: [opened, edited, synchronize, reopened] + +permissions: + contents: read + pull-requests: read + +jobs: + pr-lint: + uses: OneLiteFeatherNET/workflows/.github/workflows/pr-lint.yml@v2.9.1 diff --git a/.github/workflows/prototype-images.yml b/.github/workflows/prototype-images.yml new file mode 100644 index 0000000..680688b --- /dev/null +++ b/.github/workflows/prototype-images.yml @@ -0,0 +1,106 @@ +name: prototype-images + +# Manual prototype images for the feather-core deployment. Tags are prototype-; releases are +# not involved, so this does not wait for release-please. The controller image is built from the root +# Dockerfile, the Velocity and Minestom images from the Docker contexts that Gradle writes. + +on: + workflow_dispatch: + +permissions: + contents: read + +jobs: + meta: + name: Tag + runs-on: ubuntu-latest + outputs: + tag: ${{ steps.tag.outputs.tag }} + steps: + - name: Derive the prototype tag + id: tag + run: echo "tag=prototype-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT" + + grus: + name: Controller image + needs: meta + permissions: + contents: read + id-token: write # keyless cosign signing + uses: OneLiteFeatherNET/workflows/.github/workflows/docker-publish.yml@v2.9.1 + with: + image-name: "onelitefeather/grus" + version: ${{ needs.meta.outputs.tag }} + context: "." + dockerfile: "Dockerfile" + secrets: inherit + + java-context: + name: Java Docker contexts + runs-on: ubuntu-latest + defaults: + run: + working-directory: java + steps: + - name: Checkout + uses: actions/checkout@v7 + with: + persist-credentials: false + + - name: Set up JDK 25 + uses: actions/setup-java@v6 + with: + distribution: temurin + java-version: "25.0.3" + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v6 + + - name: Write the Docker contexts + run: ./gradlew :grus-velocity:dockerContext :grus-demo-minestom:dockerContext --max-workers=2 + + - name: Upload the Velocity context + uses: actions/upload-artifact@v7 + with: + name: velocity-context + path: java/grus-velocity/build/docker-context + include-hidden-files: false + if-no-files-found: error + + - name: Upload the Minestom demo context + uses: actions/upload-artifact@v7 + with: + name: demo-minestom-context + path: java/grus-demo-minestom/build/docker-context + include-hidden-files: false + if-no-files-found: error + + velocity: + name: Velocity image + needs: [meta, java-context] + permissions: + contents: read + id-token: write # keyless cosign signing + uses: OneLiteFeatherNET/workflows/.github/workflows/docker-publish.yml@v2.9.1 + with: + image-name: "onelitefeather/grus-velocity" + version: ${{ needs.meta.outputs.tag }} + context: "docker-context" + dockerfile: "docker-context/Dockerfile" + artifact-name: "velocity-context" + secrets: inherit + + demo-minestom: + name: Minestom demo image + needs: [meta, java-context] + permissions: + contents: read + id-token: write # keyless cosign signing + uses: OneLiteFeatherNET/workflows/.github/workflows/docker-publish.yml@v2.9.1 + with: + image-name: "onelitefeather/grus-demo-minestom" + version: ${{ needs.meta.outputs.tag }} + context: "docker-context" + dockerfile: "docker-context/Dockerfile" + artifact-name: "demo-minestom-context" + secrets: inherit diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 0000000..4131918 --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,21 @@ +name: release-please + +# One release for the whole repository. release-please keeps the release pull request up to date on +# main; when it is merged, the release is created and tagged. Tags created with GITHUB_TOKEN start no +# workflow, so nothing here listens for a tag push. +# +# Prototype: this workflow does not publish images or SBOMs yet. Docker publishing on release comes +# later, once the controller leaves the prototype stage; until then the prototype-images workflow +# builds the images on demand. + +on: + push: + branches: [main] + +permissions: + contents: write + pull-requests: write + +jobs: + release-please: + uses: OneLiteFeatherNET/workflows/.github/workflows/release-please.yml@v2.9.1 diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..e18ee07 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "0.0.0" +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fd2e134 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +# syntax=docker/dockerfile:1 + +# Controller image: one static binary (cmd/grus) on distroless, running as the nonroot user. + +FROM golang:1.26.11-alpine AS build +WORKDIR /src +COPY go.mod go.sum* ./ +RUN go mod download +COPY . . +RUN CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o /out/grus ./cmd/grus + +FROM gcr.io/distroless/static-debian12:nonroot +COPY --from=build /out/grus /grus +USER 65532:65532 +ENTRYPOINT ["/grus"] +CMD ["controller"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..7c47493 --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +# Grus + +Grus is OneLiteFeather's minimal control plane for Minecraft server pools. It starts, watches and stops +server instances on Kubernetes, hands out their templates and status over a small HTTP API and an event +stream, and is meant to replace CloudNet for the network. + +## Status + +Prototype. The controller, the Kubernetes driver, the Velocity plugin and a Minestom demo server are being +built toward one demo deployment. Nothing here is released or production ready, and the API may change. + +## Layout + +- `cmd/grus`: the controller binary (`grus controller`). +- `cmd/grus-agent`: the node-side agent. It must not depend on `k8s.io/*`. +- `internal/`: domain model, controller, drivers, store and templates. +- `api/`: the HTTP API contract (OpenAPI). +- `java/`: Gradle build of the Java modules (SDK, Velocity plugin, Minestom demo). +- `deploy/helm/grus`: the Helm chart. + +## Development + +Go tests and checks: + +```sh +go test ./... +``` + +Java build (Java 25): + +```sh +cd java && ./gradlew build +``` + +Prototype images are built by hand from the `prototype-images` workflow (`workflow_dispatch`). They are +tagged `prototype-` and pushed to the OneLiteFeather registry. Release images are not published +yet. + +## License + +Apache License 2.0. See [LICENSE](LICENSE). diff --git a/commitlint.config.mjs b/commitlint.config.mjs new file mode 100644 index 0000000..ee49e24 --- /dev/null +++ b/commitlint.config.mjs @@ -0,0 +1,22 @@ +// Conventional Commits enforcement (commits + PR title). +// https://www.conventionalcommits.org +// release-please (release-please-config.json) parses commit types to decide version bumps and +// changelog sections, so this isn't just style - a non-conventional commit silently fails to +// bump the version or gets dropped from the changelog. +// The pr-lint workflow reads this file for the commit-lint job. +export default { + extends: ['@commitlint/config-conventional'], + // Merge commits inside a pull request never reach main (squash merge), and their bodies list + // conflicts and long lines, so they are not linted. defaultIgnores stays on. + defaultIgnores: true, + ignores: [(message) => /^Merge /.test(message)], + rules: { + 'header-max-length': [2, 'always', 100], + 'scope-case': [2, 'always', 'lower-case'], + 'type-enum': [ + 2, + 'always', + ['build', 'chore', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'style', 'test'], + ], + }, +}; diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..fd0f471 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,32 @@ +{ + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", + "release-type": "simple", + "include-component-in-tag": false, + "include-v-in-tag": true, + "pull-request-header": "", + "changelog-sections": [ + { "type": "feat", "section": "Features" }, + { "type": "fix", "section": "Bug Fixes" }, + { "type": "perf", "section": "Performance Improvements" }, + { "type": "revert", "section": "Reverts" }, + { "type": "docs", "section": "Documentation" }, + { "type": "refactor", "section": "Refactoring", "hidden": true }, + { "type": "build", "section": "Build System", "hidden": true }, + { "type": "ci", "section": "Continuous Integration", "hidden": true }, + { "type": "chore", "section": "Miscellaneous", "hidden": true }, + { "type": "style", "section": "Styles", "hidden": true }, + { "type": "test", "section": "Tests", "hidden": true } + ], + "packages": { + ".": { + "package-name": "grus", + "changelog-path": "CHANGELOG.md", + "extra-files": [ + { + "type": "generic", + "path": "deploy/helm/grus/Chart.yaml" + } + ] + } + } +} diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..2d276c2 --- /dev/null +++ b/renovate.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": ["github>OneLiteFeatherNET/renovate:default(OneLiteFeatherNET/infrastructure-core-team)"] +}