From 172ebbc2cbcf3803eac8759c4caaca2bc66e4ca5 Mon Sep 17 00:00:00 2001 From: surrealwolf Date: Fri, 26 Jun 2026 06:03:02 +0000 Subject: [PATCH 1/5] Add golangci-lint and expand controller test coverage Introduce .golangci.yml and a lint CI workflow. Extend unit tests with fake-client reconciler coverage for managed resources, finalizers, and validation failures. CI verifies generated code, runs vet, lint, and tests. --- .github/workflows/lint.yml | 23 ++ .github/workflows/test.yml | 14 +- .gitignore | 2 +- .golangci.yml | 40 ++++ Makefile | 13 +- README.md | 12 +- cmd/main.go | 2 +- internal/controller/constants.go | 14 +- internal/controller/envoy_gateway.go | 14 +- .../controller/windroseserver_controller.go | 4 +- .../windroseserver_controller_test.go | 198 ++++++++++++++++++ 11 files changed, 309 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 .golangci.yml create mode 100644 internal/controller/windroseserver_controller_test.go diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..2cbcb41 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,23 @@ +name: Lint + +on: + push: + pull_request: + +jobs: + lint: + name: golangci-lint + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: golangci-lint + uses: golangci/golangci-lint-action@v8 + with: + version: v2.4.0 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b42bbc8..5fd74c7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,10 +6,10 @@ on: jobs: test: - name: Run on Ubuntu + name: go test runs-on: ubuntu-latest steps: - - name: Clone the code + - name: Checkout uses: actions/checkout@v4 - name: Setup Go @@ -17,8 +17,14 @@ jobs: with: go-version-file: go.mod - - name: Running Tests + - name: Verify generated code run: | go mod tidy make generate manifests - make test + git diff --exit-code + + - name: go vet + run: go vet ./... + + - name: go test + run: make test diff --git a/.gitignore b/.gitignore index 3ae6db8..5d34efa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ +.cover.out bin/ -cover.out *.exe *.exe~ *.dll diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..781f38f --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,40 @@ +version: "2" +run: + allow-parallel-runners: true + timeout: 5m +linters: + default: none + enable: + - copyloopvar + - errcheck + - goconst + - govet + - ineffassign + - misspell + - revive + - staticcheck + - unconvert + - unused + settings: + revive: + rules: + - name: comment-spacings + - name: import-shadowing + exclusions: + generated: lax + rules: + - linters: + - revive + path: api/v1alpha1/zz_generated.deepcopy.go + paths: + - third_party$ + - bin$ +formatters: + enable: + - gofmt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - bin$ diff --git a/Makefile b/Makefile index 2f97384..14cc4ae 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,18 @@ build: generate .PHONY: test test: generate - go test ./... -coverprofile cover.out + go test ./... -race -coverprofile cover.out + +.PHONY: lint +lint: + golangci-lint run ./... + +.PHONY: lint-fix +lint-fix: + golangci-lint run --fix ./... + +.PHONY: ci +ci: generate manifests vet lint test .PHONY: run run: manifests generate diff --git a/README.md b/README.md index c33bd63..6e6ffa3 100644 --- a/README.md +++ b/README.md @@ -214,16 +214,20 @@ docker run --user ue_user --name WindroseServer \ ## Development -Requires Go 1.25+. +Requires Go 1.25+ and [golangci-lint](https://golangci-lint.run/) for local linting. ```shell make generate manifests # CRD, RBAC, deepcopy -make test -make build # bin/manager -make run # local controller +make test # unit tests with race detector +make lint # golangci-lint +make ci # generate, vet, lint, and test +make build # bin/manager +make run # local controller make docker-build IMG=harbor.dataknife.net/library/windrose-operator:latest ``` +CI runs lint and tests on every push and pull request. + ## Related projects - [DataKnifeAI/windrose-server-k8s](https://github.com/DataKnifeAI/windrose-server-k8s) — Wine-based image and Kustomize manifests diff --git a/cmd/main.go b/cmd/main.go index 3b21f38..d173d35 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -16,9 +16,9 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" - egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" windrosev1alpha1 "github.com/DataKnifeAI/windrose-operator/api/v1alpha1" "github.com/DataKnifeAI/windrose-operator/internal/controller" + egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" ) var ( diff --git a/internal/controller/constants.go b/internal/controller/constants.go index 9892ba7..d8042f7 100644 --- a/internal/controller/constants.go +++ b/internal/controller/constants.go @@ -3,13 +3,13 @@ package controller const ( finalizerName = "windrose.dataknife.ai/finalizer" - defaultServerImage = "windroseserver/windroseserver:latest" - defaultGatewayClassName = "envoy" - defaultDirectConnectionPort int32 = 7777 - defaultMaxPlayers int32 = 4 - defaultStorageSize = "35Gi" - defaultDirectConnectionProxyAddress = "0.0.0.0" - defaultP2PProxyAddress = "127.0.0.1" + defaultServerImage = "windroseserver/windroseserver:latest" + defaultGatewayClassName = "envoy" + defaultDirectConnectionPort int32 = 7777 + defaultMaxPlayers int32 = 4 + defaultStorageSize = "35Gi" + defaultDirectConnectionProxyAddress = "0.0.0.0" + defaultP2PProxyAddress = "127.0.0.1" containerUser = int64(1000) diff --git a/internal/controller/envoy_gateway.go b/internal/controller/envoy_gateway.go index a8943bf..ef2a1fc 100644 --- a/internal/controller/envoy_gateway.go +++ b/internal/controller/envoy_gateway.go @@ -4,14 +4,14 @@ import ( "context" "fmt" - egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" windrosev1alpha1 "github.com/DataKnifeAI/windrose-operator/api/v1alpha1" + egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/ptr" - gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" - gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" logf "sigs.k8s.io/controller-runtime/pkg/log" + gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" + gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" ) func (r *WindroseServerReconciler) reconcileEnvoyGateway( @@ -118,7 +118,7 @@ func (r *WindroseServerReconciler) reconcileGateway( Listeners: []gatewayv1.Listener{ { Name: gatewayv1.SectionName(gatewayListenerGameTCP), - Port: gatewayv1.PortNumber(port), + Port: port, Protocol: gatewayv1.TCPProtocolType, AllowedRoutes: &gatewayv1.AllowedRoutes{ Namespaces: &gatewayv1.RouteNamespaces{ @@ -128,7 +128,7 @@ func (r *WindroseServerReconciler) reconcileGateway( }, { Name: gatewayv1.SectionName(gatewayListenerGameUDP), - Port: gatewayv1.PortNumber(port), + Port: port, Protocol: gatewayv1.UDPProtocolType, AllowedRoutes: &gatewayv1.AllowedRoutes{ Namespaces: &gatewayv1.RouteNamespaces{ @@ -181,7 +181,7 @@ func (r *WindroseServerReconciler) reconcileTCPRoute( { BackendObjectReference: gatewayv1.BackendObjectReference{ Name: gatewayv1.ObjectName(names.envoyService), - Port: ptr.To(gatewayv1.PortNumber(port)), + Port: ptr.To(port), }, }, }, @@ -231,7 +231,7 @@ func (r *WindroseServerReconciler) reconcileUDPRoute( { BackendObjectReference: gatewayv1.BackendObjectReference{ Name: gatewayv1.ObjectName(names.envoyService), - Port: ptr.To(gatewayv1.PortNumber(port)), + Port: ptr.To(port), }, }, }, diff --git a/internal/controller/windroseserver_controller.go b/internal/controller/windroseserver_controller.go index acdb33e..a6d4f36 100644 --- a/internal/controller/windroseserver_controller.go +++ b/internal/controller/windroseserver_controller.go @@ -19,8 +19,8 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" - egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" windrosev1alpha1 "github.com/DataKnifeAI/windrose-operator/api/v1alpha1" + egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" ) // WindroseServerReconciler reconciles a WindroseServer object. @@ -225,7 +225,7 @@ func (r *WindroseServerReconciler) reconcileDeployment( deployment.Spec.Selector = &metav1.LabelSelector{ MatchLabels: serverLabels(server.Name), } - deployment.Spec.Template.ObjectMeta.Labels = serverLabels(server.Name) + deployment.Spec.Template.Labels = serverLabels(server.Name) podSpec := corev1.PodSpec{ SecurityContext: &corev1.PodSecurityContext{ diff --git a/internal/controller/windroseserver_controller_test.go b/internal/controller/windroseserver_controller_test.go new file mode 100644 index 0000000..f24e079 --- /dev/null +++ b/internal/controller/windroseserver_controller_test.go @@ -0,0 +1,198 @@ +package controller + +import ( + "context" + "testing" + + windrosev1alpha1 "github.com/DataKnifeAI/windrose-operator/api/v1alpha1" + egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/types" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + clientgoscheme "k8s.io/client-go/kubernetes/scheme" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/client/fake" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" + gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" +) + +func testScheme(t *testing.T) *runtime.Scheme { + t.Helper() + scheme := runtime.NewScheme() + utilruntime.Must(clientgoscheme.AddToScheme(scheme)) + utilruntime.Must(windrosev1alpha1.AddToScheme(scheme)) + utilruntime.Must(gatewayv1.Install(scheme)) + utilruntime.Must(gatewayv1alpha2.Install(scheme)) + utilruntime.Must(egv1a1.AddToScheme(scheme)) + return scheme +} + +func testWindroseServer() *windrosev1alpha1.WindroseServer { + return &windrosev1alpha1.WindroseServer{ + ObjectMeta: metav1.ObjectMeta{ + Name: "windrose-server", + Namespace: "game-servers", + }, + Spec: windrosev1alpha1.WindroseServerSpec{ + Gateway: windrosev1alpha1.GatewayConfig{ + Address: "192.168.14.186", + }, + MaxPlayerCount: 4, + }, + } +} + +func objectExists(t *testing.T, c client.Client, namespace, name string, obj client.Object) { + t.Helper() + if err := c.Get(context.Background(), types.NamespacedName{ + Name: name, Namespace: namespace, + }, obj); err != nil { + t.Fatalf("Get(%s) error = %v", name, err) + } +} + +func TestReconcileAddsFinalizer(t *testing.T) { + scheme := testScheme(t) + server := testWindroseServer() + + reconciler := &WindroseServerReconciler{ + Client: fake.NewClientBuilder(). + WithScheme(scheme). + WithObjects(server). + WithStatusSubresource(server). + Build(), + Scheme: scheme, + } + + req := reconcile.Request{NamespacedName: types.NamespacedName{ + Name: server.Name, Namespace: server.Namespace, + }} + + if _, err := reconciler.Reconcile(context.Background(), req); err != nil { + t.Fatalf("Reconcile() error = %v", err) + } + + updated := &windrosev1alpha1.WindroseServer{} + if err := reconciler.Get(context.Background(), req.NamespacedName, updated); err != nil { + t.Fatalf("Get() error = %v", err) + } + if len(updated.Finalizers) != 1 || updated.Finalizers[0] != finalizerName { + t.Fatalf("finalizers = %v, want [%s]", updated.Finalizers, finalizerName) + } +} + +func TestReconcileCreatesManagedResources(t *testing.T) { + scheme := testScheme(t) + server := testWindroseServer() + server.Finalizers = []string{finalizerName} + + reconciler := &WindroseServerReconciler{ + Client: fake.NewClientBuilder(). + WithScheme(scheme). + WithObjects(server). + WithStatusSubresource(server). + Build(), + Scheme: scheme, + } + + req := reconcile.Request{NamespacedName: types.NamespacedName{ + Name: server.Name, Namespace: server.Namespace, + }} + + if _, err := reconciler.Reconcile(context.Background(), req); err != nil { + t.Fatalf("Reconcile() error = %v", err) + } + + names := deriveNames(server) + ns := server.Namespace + + objectExists(t, reconciler.Client, ns, names.deploymentName, &appsv1.Deployment{}) + objectExists(t, reconciler.Client, ns, names.pvcName, &corev1.PersistentVolumeClaim{}) + objectExists(t, reconciler.Client, ns, names.configMapName, &corev1.ConfigMap{}) + objectExists(t, reconciler.Client, ns, names.serviceName, &corev1.Service{}) + objectExists(t, reconciler.Client, ns, names.envoyService, &corev1.Service{}) + objectExists(t, reconciler.Client, ns, names.gatewayName, &gatewayv1.Gateway{}) + objectExists(t, reconciler.Client, ns, names.envoyProxyName, &egv1a1.EnvoyProxy{}) + objectExists(t, reconciler.Client, ns, names.tcpRouteName, &gatewayv1alpha2.TCPRoute{}) + objectExists(t, reconciler.Client, ns, names.udpRouteName, &gatewayv1alpha2.UDPRoute{}) + + deployment := &appsv1.Deployment{} + objectExists(t, reconciler.Client, ns, names.deploymentName, deployment) + + container := deployment.Spec.Template.Spec.Containers[0] + if container.Image != defaultServerImage { + t.Fatalf("image = %q, want %q", container.Image, defaultServerImage) + } + if got := container.Resources.Requests.Memory().String(); got != "12Gi" { + t.Fatalf("memory request = %s, want 12Gi for 4 players", got) + } + + gateway := &gatewayv1.Gateway{} + objectExists(t, reconciler.Client, ns, names.gatewayName, gateway) + if got := gateway.Spec.Addresses[0].Value; got != server.Spec.Gateway.Address { + t.Fatalf("gateway address = %q, want %q", got, server.Spec.Gateway.Address) + } + + updated := &windrosev1alpha1.WindroseServer{} + if err := reconciler.Get(context.Background(), req.NamespacedName, updated); err != nil { + t.Fatalf("Get status: %v", err) + } + if updated.Status.ConnectionAddress != server.Spec.Gateway.Address { + t.Fatalf("connectionAddress = %q, want %q", updated.Status.ConnectionAddress, server.Spec.Gateway.Address) + } + if updated.Status.ConnectionPort != defaultDirectConnectionPort { + t.Fatalf("connectionPort = %d, want %d", updated.Status.ConnectionPort, defaultDirectConnectionPort) + } +} + +func TestReconcileFailsWithoutGatewayAddress(t *testing.T) { + scheme := testScheme(t) + server := testWindroseServer() + server.Finalizers = []string{finalizerName} + server.Spec.Gateway.Address = "" + + reconciler := &WindroseServerReconciler{ + Client: fake.NewClientBuilder(). + WithScheme(scheme). + WithObjects(server). + WithStatusSubresource(server). + Build(), + Scheme: scheme, + } + + req := reconcile.Request{NamespacedName: types.NamespacedName{ + Name: server.Name, Namespace: server.Namespace, + }} + + if _, err := reconciler.Reconcile(context.Background(), req); err == nil { + t.Fatal("Reconcile() expected error for missing gateway address") + } + + updated := &windrosev1alpha1.WindroseServer{} + if err := reconciler.Get(context.Background(), req.NamespacedName, updated); err != nil { + t.Fatalf("Get() error = %v", err) + } + if updated.Status.Phase != windrosev1alpha1.PhaseFailed { + t.Fatalf("phase = %q, want %q", updated.Status.Phase, windrosev1alpha1.PhaseFailed) + } +} + +func TestConnectionAddressFromGateway(t *testing.T) { + server := testWindroseServer() + if got := connectionAddressFromGateway(server, nil); got != "192.168.14.186" { + t.Fatalf("fallback address = %q", got) + } + + gateway := &gatewayv1.Gateway{ + Status: gatewayv1.GatewayStatus{ + Addresses: []gatewayv1.GatewayStatusAddress{{Value: "10.0.0.1"}}, + }, + } + if got := connectionAddressFromGateway(server, gateway); got != "10.0.0.1" { + t.Fatalf("status address = %q, want 10.0.0.1", got) + } +} From 4dbf769a819d837917d3c0e6b9caa013f69db93b Mon Sep 17 00:00:00 2001 From: surrealwolf Date: Fri, 26 Jun 2026 06:04:37 +0000 Subject: [PATCH 2/5] Add GitLab mirror CI and Harbor image publish pipeline Create GitLab CI to run make ci, build the operator image with BuildKit, and push to harbor.dataknife.net/library/windrose-operator. Add a GitHub Actions mirror workflow and docs for GITLAB_TOKEN and Harbor variables. --- .github/workflows/mirror-gitlab.yml | 62 ++++++++++++++++++++ .gitignore | 2 +- .gitlab-ci.yml | 88 +++++++++++++++++++++++++++++ docs/GITLAB_MIRROR.md | 69 ++++++++++++++++++++++ 4 files changed, 220 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/mirror-gitlab.yml create mode 100644 .gitlab-ci.yml create mode 100644 docs/GITLAB_MIRROR.md diff --git a/.github/workflows/mirror-gitlab.yml b/.github/workflows/mirror-gitlab.yml new file mode 100644 index 0000000..7caa1b2 --- /dev/null +++ b/.github/workflows/mirror-gitlab.yml @@ -0,0 +1,62 @@ +# Mirror to GitLab after CI; GitLab CI publishes the operator image to Harbor. +# Configure HARBOR_* variables on the GitLab project. GitHub: GITLAB_TOKEN for push only. +name: Mirror to GitLab + +on: + push: + branches: + - main + pull_request: + branches: + - main + workflow_dispatch: + +permissions: + contents: read + +env: + GITLAB_MIRROR_PATH: dk-raas/dkai/game-servers/windrose-operator + +jobs: + verify: + name: Verify + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: golangci-lint + uses: golangci/golangci-lint-action@v8 + with: + version: v2.4.0 + + - name: make ci + run: make ci + + mirror: + name: Push to GitLab + runs-on: ubuntu-latest + needs: [verify] + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Push to GitLab + env: + GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} + run: | + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + git remote remove gitlab 2>/dev/null || true + git remote add gitlab "https://gitlab.com/${{ env.GITLAB_MIRROR_PATH }}.git" + git config credential.helper '!f() { echo "username=oauth2"; echo "password=${GITLAB_TOKEN}"; }; f' + git fetch gitlab main 2>/dev/null || true + git push gitlab HEAD:main --force diff --git a/.gitignore b/.gitignore index 5d34efa..3ae6db8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -.cover.out bin/ +cover.out *.exe *.exe~ *.dll diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..147c4f7 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,88 @@ +# GitLab CI: test/build the operator, publish image to Harbor +# +# Workflow: main or tag → build → publish windrose-operator to Harbor +# +# Required CI/CD variables (Settings → CI/CD → Variables): +# HARBOR_REGISTRY - Harbor registry URL (e.g. harbor.dataknife.net) +# HARBOR_PROJECT - Harbor project name (default: library) +# HARBOR_USER - Harbor username (masked) +# HARBOR_PASSWORD - Harbor password/token (masked, protected) + +stages: + - build + - docker + +variables: + IMAGE_NAME: windrose-operator + HARBOR_PROJECT: library + +.build_template: &build_template + image: golang:1.25-alpine + before_script: + - cd "$CI_PROJECT_DIR" + - apk add --no-cache git make + - go version + - go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.17.2 + - go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.4.0 + - export PATH="$(go env GOPATH)/bin:$PATH" + +build: + stage: build + <<: *build_template + script: + - go mod download + - make ci + - make build + artifacts: + paths: + - bin/manager + expire_in: 1 week + rules: + - if: $CI_COMMIT_BRANCH == "main" + - if: $CI_COMMIT_TAG + +.docker_build_template: &docker_build_template + stage: docker + image: + name: moby/buildkit:rootless + entrypoint: [""] + needs: [build] + rules: + - if: $CI_COMMIT_BRANCH == "main" + - if: $CI_COMMIT_TAG + tags: + - kubernetes + +publish-windrose-operator: + <<: *docker_build_template + script: + - | + if [ -z "$HARBOR_REGISTRY" ] || [ -z "$HARBOR_PROJECT" ]; then + echo "❌ Error: HARBOR_REGISTRY or HARBOR_PROJECT not set" + echo "HARBOR_REGISTRY: ${HARBOR_REGISTRY:-NOT SET}" + echo "HARBOR_PROJECT: ${HARBOR_PROJECT:-NOT SET}" + exit 1 + fi + + export DOCKER_CONFIG=$(mktemp -d) + if [ -n "${HARBOR_USER:-}" ] && [ -n "${HARBOR_PASSWORD:-}" ]; then + AUTH=$(printf '%s' "$HARBOR_USER:$HARBOR_PASSWORD" | base64 | tr -d '\n') + echo '{"auths":{"'"$HARBOR_REGISTRY"'":{"auth":"'"$AUTH"'"}}}' > "$DOCKER_CONFIG/config.json" + fi + + echo "Building windrose-operator image..." + echo "Registry: $HARBOR_REGISTRY/$HARBOR_PROJECT/$IMAGE_NAME" + + IMAGE_TAG="${CI_COMMIT_SHORT_SHA:-$CI_PIPELINE_ID}" + OUTPUT_FLAGS="--output type=image,name=$HARBOR_REGISTRY/$HARBOR_PROJECT/$IMAGE_NAME:latest,push=true" + OUTPUT_FLAGS="$OUTPUT_FLAGS --output type=image,name=$HARBOR_REGISTRY/$HARBOR_PROJECT/$IMAGE_NAME:$IMAGE_TAG,push=true" + + if [ -n "$CI_COMMIT_TAG" ]; then + OUTPUT_FLAGS="$OUTPUT_FLAGS --output type=image,name=$HARBOR_REGISTRY/$HARBOR_PROJECT/$IMAGE_NAME:$CI_COMMIT_TAG,push=true" + fi + + buildctl-daemonless.sh build \ + --frontend dockerfile.v0 \ + --local context=. \ + --local dockerfile=. \ + $OUTPUT_FLAGS diff --git a/docs/GITLAB_MIRROR.md b/docs/GITLAB_MIRROR.md new file mode 100644 index 0000000..835b0b1 --- /dev/null +++ b/docs/GITLAB_MIRROR.md @@ -0,0 +1,69 @@ +# GitLab mirror and Harbor publish + +The operator image is built and pushed to Harbor from GitLab CI on the mirror at +`gitlab.com/dk-raas/dkai/game-servers/windrose-operator`. + +GitHub Actions on `main` runs verification, then mirrors the repository to GitLab. +GitLab CI runs `make ci`, builds the Docker image, and publishes to +`harbor.dataknife.net/library/windrose-operator`. + +## Authenticate GitLab CLI (`glab`) + +1. Create a [GitLab personal access token](https://docs.gitlab.com/user/profile/personal_access_tokens/) + or [group/project access token](https://docs.gitlab.com/user/project/settings/project_access_tokens/) + with at least **write_repository**. + +2. Log in: + + ```bash + glab auth login --hostname gitlab.com + ``` + + Or for non-interactive use: + + ```bash + export GITLAB_TOKEN="glpat-..." # do not commit this value + ``` + +3. Verify: + + ```bash + glab auth status + ``` + +## Create the mirror project (once) + +Already created for this repo: + +```bash +glab repo create "dk-raas/dkai/game-servers/windrose-operator" \ + --private \ + --description "Mirror of DataKnifeAI/windrose-operator — CI builds operator image to Harbor" +``` + +## GitHub repository secret + +Add a `GITLAB_TOKEN` secret on the GitHub repository with push access to the +mirror project. The **Mirror to GitLab** workflow uses it only to push `main`. + +## GitLab CI variables (Harbor) + +On the GitLab project (or parent group), set **masked** variables: + +| Variable | Example | +|----------|---------| +| `HARBOR_REGISTRY` | `harbor.dataknife.net` | +| `HARBOR_PROJECT` | `library` | +| `HARBOR_USER` | Harbor robot or user | +| `HARBOR_PASSWORD` | Harbor token (masked, protected) | + +Pushes produce tags `:latest`, `:`, and `:` when applicable. + +## Manual mirror push + +If GitHub Actions is not yet configured: + +```bash +git remote add gitlab https://gitlab.com/dk-raas/dkai/game-servers/windrose-operator.git +git push gitlab main --force +``` From 7d5952d608507364f8a45683f55ca834bc47f5af Mon Sep 17 00:00:00 2001 From: surrealwolf Date: Fri, 26 Jun 2026 06:04:46 +0000 Subject: [PATCH 3/5] Link GitLab mirror docs from README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6e6ffa3..7b9b224 100644 --- a/README.md +++ b/README.md @@ -231,6 +231,7 @@ CI runs lint and tests on every push and pull request. ## Related projects - [DataKnifeAI/windrose-server-k8s](https://github.com/DataKnifeAI/windrose-server-k8s) — Wine-based image and Kustomize manifests +- [GitLab mirror](docs/GITLAB_MIRROR.md) — CI builds `harbor.dataknife.net/library/windrose-operator` - [Windrose Dedicated Server Guide](https://playwindrose.com/dedicated-server-guide) - [windroseserver/windroseserver on Docker Hub](https://hub.docker.com/r/windroseserver/windroseserver) From ec652fda249d38c63973040c2153b88473422d32 Mon Sep 17 00:00:00 2001 From: surrealwolf Date: Fri, 26 Jun 2026 19:47:02 +0000 Subject: [PATCH 4/5] Fix GitLab CI for group Harbor vars and document org secrets Use inherited HARBOR_USERNAME from dk-raas/dkai, avoid empty DOCKER_CONFIG, and skip -race on Alpine. Document verified org GITLAB_TOKEN and group CI vars. --- .gitlab-ci.yml | 20 +++++----- docs/GITLAB_MIRROR.md | 87 +++++++++++++++++++++++++------------------ 2 files changed, 61 insertions(+), 46 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 147c4f7..0684194 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,11 +2,8 @@ # # Workflow: main or tag → build → publish windrose-operator to Harbor # -# Required CI/CD variables (Settings → CI/CD → Variables): -# HARBOR_REGISTRY - Harbor registry URL (e.g. harbor.dataknife.net) -# HARBOR_PROJECT - Harbor project name (default: library) -# HARBOR_USER - Harbor username (masked) -# HARBOR_PASSWORD - Harbor password/token (masked, protected) +# Harbor variables are inherited from the dk-raas/dkai GitLab group: +# HARBOR_REGISTRY, HARBOR_PROJECT, HARBOR_USERNAME, HARBOR_PASSWORD, DOCKER_AUTH_CONFIG stages: - build @@ -31,7 +28,9 @@ build: <<: *build_template script: - go mod download - - make ci + # Alpine has no CGO by default; skip -race (GitHub Actions runs race tests on ubuntu) + - make generate manifests vet lint + - go test ./... -coverprofile cover.out - make build artifacts: paths: @@ -64,10 +63,11 @@ publish-windrose-operator: exit 1 fi - export DOCKER_CONFIG=$(mktemp -d) - if [ -n "${HARBOR_USER:-}" ] && [ -n "${HARBOR_PASSWORD:-}" ]; then - AUTH=$(printf '%s' "$HARBOR_USER:$HARBOR_PASSWORD" | base64 | tr -d '\n') - echo '{"auths":{"'"$HARBOR_REGISTRY"'":{"auth":"'"$AUTH"'"}}}' > "$DOCKER_CONFIG/config.json" + HARBOR_AUTH_USER="${HARBOR_USERNAME:-${HARBOR_USER:-}}" + if [ -n "$HARBOR_AUTH_USER" ] && [ -n "${HARBOR_PASSWORD:-}" ]; then + AUTH=$(printf '%s' "$HARBOR_AUTH_USER:$HARBOR_PASSWORD" | base64 | tr -d '\n') + mkdir -p ~/.docker + echo "{\"auths\":{\"$HARBOR_REGISTRY\":{\"auth\":\"$AUTH\"}}}" > ~/.docker/config.json fi echo "Building windrose-operator image..." diff --git a/docs/GITLAB_MIRROR.md b/docs/GITLAB_MIRROR.md index 835b0b1..bd3406f 100644 --- a/docs/GITLAB_MIRROR.md +++ b/docs/GITLAB_MIRROR.md @@ -4,66 +4,81 @@ The operator image is built and pushed to Harbor from GitLab CI on the mirror at `gitlab.com/dk-raas/dkai/game-servers/windrose-operator`. GitHub Actions on `main` runs verification, then mirrors the repository to GitLab. -GitLab CI runs `make ci`, builds the Docker image, and publishes to +GitLab CI runs tests, builds the Docker image, and publishes to `harbor.dataknife.net/library/windrose-operator`. -## Authenticate GitLab CLI (`glab`) +## Credentials (already configured at org/group level) + +No per-repo secrets or CI variables are required for normal operation. + +### GitHub — org secret `GITLAB_TOKEN` -1. Create a [GitLab personal access token](https://docs.gitlab.com/user/profile/personal_access_tokens/) - or [group/project access token](https://docs.gitlab.com/user/project/settings/project_access_tokens/) - with at least **write_repository**. +The DataKnifeAI organization provides `GITLAB_TOKEN` to repositories that mirror +to GitLab. Verify access for this repo: -2. Log in: +```bash +gh api repos/DataKnifeAI/windrose-operator/actions/organization-secrets +``` - ```bash - glab auth login --hostname gitlab.com - ``` +Expected: `GITLAB_TOKEN` in the `secrets` list. - Or for non-interactive use: +The **Mirror to GitLab** workflow reads `${{ secrets.GITLAB_TOKEN }}` on pushes +to `main`. Sibling repos (for example `windrose-server-k8s`) use the same +org secret successfully. - ```bash - export GITLAB_TOKEN="glpat-..." # do not commit this value - ``` +### GitLab — group variables on `dk-raas/dkai` -3. Verify: +Harbor and registry credentials are inherited from the parent group. Verify: - ```bash - glab auth status - ``` +```bash +glab variable list --group dk-raas/dkai +``` -## Create the mirror project (once) +Expected variables include `HARBOR_REGISTRY`, `HARBOR_PROJECT`, `HARBOR_USERNAME`, +`HARBOR_PASSWORD`, and `DOCKER_AUTH_CONFIG`. The `game-servers` subgroup and +`windrose-operator` project do not need their own copies. -Already created for this repo: +Non-secret values (safe to print): ```bash -glab repo create "dk-raas/dkai/game-servers/windrose-operator" \ - --private \ - --description "Mirror of DataKnifeAI/windrose-operator — CI builds operator image to Harbor" +glab variable get HARBOR_REGISTRY --group dk-raas/dkai +glab variable get HARBOR_PROJECT --group dk-raas/dkai +``` + +## Authenticate GitLab CLI (`glab`) + +For manual pushes or project management: + +```bash +glab auth login --hostname gitlab.com +glab auth status ``` -## GitHub repository secret +## Mirror project -Add a `GITLAB_TOKEN` secret on the GitHub repository with push access to the -mirror project. The **Mirror to GitLab** workflow uses it only to push `main`. +https://gitlab.com/dk-raas/dkai/game-servers/windrose-operator -## GitLab CI variables (Harbor) +Created once with: -On the GitLab project (or parent group), set **masked** variables: +```bash +glab repo create windrose-operator \ + --group dk-raas/dkai/game-servers \ + --private \ + --description "Mirror of DataKnifeAI/windrose-operator — CI builds operator image to Harbor" +``` -| Variable | Example | -|----------|---------| -| `HARBOR_REGISTRY` | `harbor.dataknife.net` | -| `HARBOR_PROJECT` | `library` | -| `HARBOR_USER` | Harbor robot or user | -| `HARBOR_PASSWORD` | Harbor token (masked, protected) | +## Image tags -Pushes produce tags `:latest`, `:`, and `:` when applicable. +Pushes produce `:latest`, `:`, and `:` when applicable. ## Manual mirror push -If GitHub Actions is not yet configured: +If GitHub Actions has not run yet: ```bash git remote add gitlab https://gitlab.com/dk-raas/dkai/game-servers/windrose-operator.git -git push gitlab main --force +git push gitlab main ``` + +Note: `main` on GitLab may be branch-protected; prefer merging to GitHub `main` +and letting the mirror workflow sync. From 7b48d66dc6af233b645ec2424cd4487db8ff569e Mon Sep 17 00:00:00 2001 From: surrealwolf Date: Fri, 26 Jun 2026 19:47:09 +0000 Subject: [PATCH 5/5] Note org GITLAB_TOKEN in mirror workflow comment --- .github/workflows/mirror-gitlab.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/mirror-gitlab.yml b/.github/workflows/mirror-gitlab.yml index 7caa1b2..6b8df62 100644 --- a/.github/workflows/mirror-gitlab.yml +++ b/.github/workflows/mirror-gitlab.yml @@ -1,5 +1,5 @@ # Mirror to GitLab after CI; GitLab CI publishes the operator image to Harbor. -# Configure HARBOR_* variables on the GitLab project. GitHub: GITLAB_TOKEN for push only. +# Uses org secret GITLAB_TOKEN; Harbor vars inherited from dk-raas/dkai GitLab group. name: Mirror to GitLab on: