Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

4.7 KB
Raw Blame
# Cloud Run service — world.three.ws (Hyperfy multiplayer world)
#
# One-time: create the admin-code secret and let the service account read it.
# Without ADMIN_CODE, Hyperfy gives EVERY visitor admin/build rights — anyone
# can delete the ground or fill the world with broken GLBs.
#   printf '%s' "<code>" | gcloud secrets create hyperfy-admin-code --data-file=-
#   gcloud secrets add-iam-policy-binding hyperfy-admin-code \
#     --member=serviceAccount:hyperfy-world-sa@aerial-vehicle-466722-p5.iam.gserviceaccount.com \
#     --role=roles/secretmanager.secretAccessor
#
# Apply with:
#   gcloud run services replace deploy/world/cloudrun.yaml --region=us-central1
#
# In-world, an admin claims build rights with the chat command: /admin <code>
#
# After deploy, map the custom domain:
#   gcloud run domain-mappings create --service=hyperfy-world \
#     --domain=world.three.ws --region=us-central1
# Then add a CNAME at your registrar:
#   world  CNAME  ghs.googlehosted.com.

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: hyperfy-world
  labels:
    cloud.googleapis.com/location: us-central1
  annotations:
    run.googleapis.com/launch-stage: BETA
spec:
  template:
    metadata:
      annotations:
        # Keep exactly one instance alive at all times so the world never cold-starts
        # and in-memory state (physics sim, connected players) is never wiped.
        autoscaling.knative.dev/minScale: "1"
        autoscaling.knative.dev/maxScale: "1"
        # Always-on CPU: a multiplayer game server has a continuous tick loop;
        # throttling CPU when no requests are in flight would stall the sim.
        run.googleapis.com/cpu-throttling: "false"
        # Gen2 execution environment is required for GCS FUSE volume mounts.
        run.googleapis.com/execution-environment: gen2
    spec:
      serviceAccountName: hyperfy-world-sa@aerial-vehicle-466722-p5.iam.gserviceaccount.com
      # One game-world process; many long-lived WebSocket connections per instance.
      containerConcurrency: 1000
      # WebSocket connections stay open for the session. Cloud Run supports long
      # connections up to 3600s; set the max so players aren't silently dropped.
      timeoutSeconds: 3600
      containers:
        - image: us-central1-docker.pkg.dev/aerial-vehicle-466722-p5/world/hyperfy:latest
          ports:
            - name: http1
              containerPort: 3000
          env:
            - name: NODE_ENV
              value: production
            # WORLD is the directory name joined onto the server's rootDir (/app/).
            # Mounting the GCS bucket at /app/world makes WORLD=world resolve there.
            - name: WORLD
              value: world
            - name: DOMAIN
              value: world.three.ws
            - name: PUBLIC_WS_URL
              value: wss://world.three.ws
            - name: PUBLIC_API_URL
              value: https://world.three.ws
            # Save world state to disk every 30 seconds.
            - name: SAVE_INTERVAL
              value: "30000"
            # Megabytes. Enforced client-side by Hyperfy and server-side on
            # /api/upload via patches/0001-upload-limit-from-env.patch.
            - name: PUBLIC_MAX_UPLOAD_SIZE
              value: "16"
            # Store assets locally (in the world dir, served via PUBLIC_API_URL).
            - name: ASSETS
              value: local
            - name: ASSETS_BASE_URL
              value: https://world.three.ws/assets
            - name: JWT_SECRET
              valueFrom:
                secretKeyRef:
                  name: hyperfy-jwt-secret
                  key: latest
            # Gates building: with this set, visitors join as rank VISITOR and
            # cannot add/move/delete world content; admins unlock via /admin.
            - name: ADMIN_CODE
              valueFrom:
                secretKeyRef:
                  name: hyperfy-admin-code
                  key: latest
          resources:
            limits:
              cpu: "2"
              memory: 2Gi
          volumeMounts:
            # Mount the GCS bucket at /app/world so WORLD=world resolves correctly.
            - name: world-data
              mountPath: /app/world
          startupProbe:
            httpGet:
              path: /status
              port: 3000
            initialDelaySeconds: 10
            periodSeconds: 5
            failureThreshold: 12
          livenessProbe:
            httpGet:
              path: /status
              port: 3000
            periodSeconds: 30
            failureThreshold: 3
      volumes:
        - name: world-data
          csi:
            driver: gcsfuse.run.googleapis.com
            readOnly: false
            volumeAttributes:
              bucketName: world-three-ws-data
  traffic:
    - percent: 100
      latestRevision: true