--- apiVersion: apps/v1 kind: DaemonSet metadata: name: forgejo-worker-full namespace: forgejo-workers spec: selector: matchLabels: app: forgejo-worker-full template: metadata: labels: app: forgejo-worker-full spec: nodeSelector: kubernetes.io/arch: arm64 hostNetwork: true hostPID: true containers: - name: worker image: node:20-alpine command: ["/bin/sh", "-c"] args: - | echo "🚀 Starting simple Node.js Forgejo worker on $(hostname)" echo "✅ Node.js version: $(node --version)" echo "✅ npm version: $(npm --version)" # Install required packages echo "📦 Installing required packages..." apk add --no-cache wget git curl bash python3 py3-pip unzip jq tar gzip make gcc musl-dev go gcompat # Install AWS CLI echo "☁️ Installing AWS CLI..." pip3 install awscli --break-system-packages || { echo "pip install failed, trying direct download..." curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip" unzip awscliv2.zip ./aws/install rm -rf aws awscliv2.zip } # Install Hugo Extended with glibc compatibility echo "📚 Installing Hugo Extended..." HUGO_VERSION="0.148.0" wget -O hugo.tar.gz "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-arm64.tar.gz" tar -xzf hugo.tar.gz hugo mv hugo /usr/local/bin/hugo chmod +x /usr/local/bin/hugo rm -f hugo.tar.gz # Set up Go environment echo "🐹 Setting up Go environment..." export GOPATH=/go export PATH=$GOPATH/bin:/usr/local/go/bin:$PATH mkdir -p $GOPATH/{bin,src,pkg} # Install other common CI tools echo "🔧 Installing additional tools..." if ! command -v yarn >/dev/null 2>&1; then npm install -g yarn || echo "yarn install failed" else echo "✅ yarn already available: $(yarn --version)" fi # Download and install Forgejo Runner echo "⬇️ Downloading Forgejo Runner..." if wget -O /usr/local/bin/forgejo-runner https://code.forgejo.org/forgejo/runner/releases/download/v6.3.1/forgejo-runner-6.3.1-linux-arm64; then echo "✅ Downloaded Forgejo runner v6.3.1" else echo "❌ Failed to download runner" exit 1 fi chmod +x /usr/local/bin/forgejo-runner echo "✅ Git version: $(git --version)" echo "✅ AWS CLI version: $(aws --version || echo 'AWS CLI installation failed')" echo "✅ Go version: $(go version || echo 'Go installation failed')" echo "✅ Hugo version: $(hugo version || echo 'Hugo installation failed')" echo "✅ Python version: $(python3 --version)" echo "✅ Yarn version: $(yarn --version || echo 'Yarn not available')" echo "✅ jq version: $(jq --version || echo 'jq not available')" echo "✅ Forgejo runner version: $(forgejo-runner --version || echo 'Version check failed')" # Configure git for HTTPS echo "🔧 Configuring git..." git config --global url."https://git.deco.sh/".insteadOf "git@git.deco.sh:" git config --global url."https://git.deco.sh/".insteadOf "ssh://git@git.deco.sh/" git config --global url."https://".insteadOf "git://" git config --global advice.detachedHead false git config --global safe.directory '*' git config --global user.name "Forgejo Worker" git config --global user.email "worker@$(hostname)" # CRITICAL: Set up directory structure with NFS mounts echo "📁 Setting up directory structure..." mkdir -p /data # Remove existing directories if they exist if [ -d "/data/workspace" ] && [ ! -L "/data/workspace" ]; then echo "🗑️ Removing existing workspace directory..." rm -rf /data/workspace fi if [ -d "/data/cache" ] && [ ! -L "/data/cache" ]; then echo "🗑️ Removing existing cache directory..." rm -rf /data/cache fi # Create symlinks to NFS mounts ln -sfn /workspace /data/workspace ln -sfn /cache /data/cache # Verify mounts and symlinks echo "📊 Storage configuration:" df -h | grep -E "(Volume5|Filesystem)" echo "" echo "📂 Directory structure:" ls -la /data/ echo "" echo "🔗 Verifying symlinks:" ls -la /data/workspace ls -la /data/cache # Test write access echo "✍️ Testing write access..." echo "Test write at $(date)" > /data/workspace/test-$(hostname).txt echo "Test write at $(date)" > /data/cache/test-$(hostname).txt # Register worker if not already registered cd /data if [ ! -f /data/.runner ]; then echo "📝 Registering new worker: k8s-full-$(hostname)" forgejo-runner register \ --no-interactive \ --instance "${FORGEJO_INSTANCE_URL}" \ --token "${FORGEJO_TOKEN}" \ --name "k8s-full-$(hostname)" \ --labels "self-hosted,linux,arm64,nodejs,aws-cli,golang,hugo" else echo "✅ Worker already registered" fi # Verify registration if [ ! -f /data/.runner ]; then echo "❌ ERROR: Registration failed" exit 1 fi # Start the worker echo "🏃 Starting Forgejo runner daemon..." exec forgejo-runner daemon --config /etc/forgejo-runner/config.yaml env: - name: FORGEJO_INSTANCE_URL value: "https://git.deco.sh" - name: FORGEJO_TOKEN valueFrom: secretKeyRef: name: forgejo-worker-token key: token volumeMounts: - name: config mountPath: /etc/forgejo-runner - name: data mountPath: /data - name: workspace mountPath: /workspace - name: cache mountPath: /cache - name: go-workspace mountPath: /go resources: requests: memory: "512Mi" cpu: "250m" limits: memory: "4Gi" cpu: "2000m" securityContext: privileged: true volumes: - name: config configMap: name: forgejo-worker-config - name: data hostPath: path: /var/lib/forgejo-worker-full type: DirectoryOrCreate - name: workspace nfs: server: 192.168.12.16 path: /Volume5/forgejo-builds - name: cache nfs: server: 192.168.12.16 path: /Volume5/forgejo-cache - name: go-workspace hostPath: path: /var/lib/go-workspace type: DirectoryOrCreate tolerations: - key: node-role.kubernetes.io/master effect: NoSchedule operator: Exists - key: node-role.kubernetes.io/control-plane effect: NoSchedule operator: Exists