跳到主要内容
工程

本页尚未翻译,当前显示英文版本。

Deployment

Deployment 展示项目在哪些位置为 Player 提供服务,以及其中哪些位置需要关注。 它把 PlayServ 网络呈现在地图上和接入点表格中,每个接入点都显示实时会话数,以及在那里运行的 game server 副本的健康状况。这是一个概览页面:部署范围本身在 Servers 中修改,每个位置都会链接到那里。


接入点

接入点(PoP)是 PlayServ 中可以运行 game server 的位置,例如 Frankfurt,显示为 FRA。同一个代码在所有出现位置的地方通用:这张地图上、fleet 的区域中,以及为 machine pool 选择 deployment point 时。

状态含义
Active已为本项目配置,并正在为 Player 提供服务。
No traffic已为本项目配置,但当前没有会话路由到这里。
Available属于 PlayServ 网络,但未为本项目配置。

Room 的 region 是你的标签,不是它的位置

Room 计入托管它的 game server 所在的 PoP。你的服务器为 Room 上报的 region 字符串会按原样显示在 Game Rooms 中,Deployment 从不使用它。

每个 PoP 都带有解释其状态的条件。 表格会把需要处理的位置排在前面。

条件严重程度含义
Replica(s) unhealthyProblem“X of Y replicas unhealthy”:副本在运行,但健康检查失败。
Machine pool errorProblem该位置的某个 machine pool 报告了错误;详情中会指出 fleet 和原因。
N replicas drainingNotice副本正在处理完当前会话,随后关闭。
No active sessionsNotice该位置已完成配置,但没有流量路由到这里。
Healthy—一切正常。

Draining 不是故障

处于 draining 的副本是在受控关闭:它们不再接受新会话,让当前会话自然结束。它们显示为 Notice 而不是 Problem,无需任何操作。


阅读页面

区块含义
Situation strip活跃的 PoP 数和活跃会话数;接着是 N locations need attention(每个位置一个标签,注明原因)或 All locations operating normally;最后是正在提供服务的副本数。
Map所有公开了坐标的 PoP。活跃的图钉显示代码,可用的显示为圆点,弧线把最繁忙的 PoP 与其他 PoP 连接起来。鼠标悬停在图钉上可查看会话、fleet 和主要条件。Hide available locations 只保留项目正在使用的位置。
Points of presence每个位置一行:Location(城市和代码)、Condition(主要条件,加上“+N more”)、Sessions 和 Serving capacity(“X / Y healthy”,以及 unhealthy 和 draining 的数量)。没有坐标的位置会标记为 no coordinates published,并且不会出现在地图上。

承载多位置 fleet 一部分的位置,会把会话数显示为“up to N”。

每一行都能带你去处理它的地方。

点击打开
活跃的 PoP为它提供服务的 fleet,位于 Servers 中该 fleet 的 Rooms 标签页。
可用的 PoPDeployment points,并聚焦到该位置,以便把它加入某个 fleet。

分支部署

把分支绑定到某个 Environment 后,每次向该分支推送都会把你的 Function 和 game server 部署到那里。 部署作为 GitHub Action 在你的仓库中运行:它先向 PlayServ 查询该分支绑定的 Environment,然后用 PlayServ CLI 部署。绑定关系保存在 PlayServ 中,从不放在仓库里。

连接仓库并绑定分支

在 Project settings → Deployment 中连接仓库,并把每个分支绑定到它要部署的 Environment。

设置作用
RepositoryGitHub 组织或用户、仓库名称和默认分支。PlayServ 只保存这些信息,从不保存 GitHub 凭据。
Branch → environment bindings每个分支部署到哪个 Environment。一个分支只能部署到一个 Environment;多个分支可以部署到同一个 Environment。禁用的绑定会保留,但向该分支推送不会部署任何内容。复制出来的 Environment 需要先重新关联,才能被绑定。

为每个 Environment 创建服务端 key

在每个有分支部署的 Environment 中创建一个 Server API key。key 只能部署到它自己的 Environment。

把 secret 添加到 GitHub

在仓库的 Settings → Secrets and variables → Actions 中:

名称类型值
PLAYSERV_HOSTVariablePlayServ 平台 URL,<platform-url>。
PLAYSERV_SERVER_KEYSecret一个服务端 key。所有已绑定分支都部署到同一个 Environment 时,有这一个就够了。
PLAYSERV_SERVER_KEY_<ENV>Secret每个额外的 Environment 再加一个 key,以 Environment 名称的大写形式命名,- 替换为 _:Environment qa-2 → PLAYSERV_SERVER_KEY_QA_2。每一个都要列在 workflow 的 env: 块中。

添加 workflow

把下面的 workflow 保存为 .github/workflows/deploy.yml 并推送。

推送后会发生什么

被推送的分支结果
未绑定,或其绑定已禁用什么也不做:任务成功结束。
已绑定到某个 Environment仓库中的每个云函数(每个带 platform.json 的目录)都通过 playserv publish 部署到该 Environment。
……包含在该 Environment 中新出现的 game server该 game server 以默认 Room 设置和 0 台机器的 machine pool 注册,并推送它的镜像。在你于 Servers 中调大 pool 的规模之前,什么都不会启动。
……包含已有 pool 的 game serverpool 切换到新镜像。

切换 pool 镜像会关闭它的 Room

pool 中的每台机器都会被替换,其上的 Room 连同 Player 一起关闭。请绑定你有意推送的分支,而不是频繁提交的分支。

同一仓库的部署一次只运行一个。每个 platform.json 中的 name 必须是该 Function 在项目中的 slug。部署失败会让任务失败,原因记录在 Actions 日志中。

Workflow

# PlayServ auto-deploy: push to a bound branch, and the functions and game
# servers in this repo deploy to that branch's environment.
# Copy this file into your repo at .github/workflows/deploy.yml.
#
# Repository variable (Settings → Secrets and variables → Actions → Variables):
#   PLAYSERV_HOST              — the PlayServ platform URL
# Repository secrets:
#   PLAYSERV_SERVER_KEY        — a server key; enough when every bound branch
#                                targets the same environment
#   PLAYSERV_SERVER_KEY_<ENV>  — one per additional environment, uppercased, '-' → '_'
#                                (environment "qa-2" → PLAYSERV_SERVER_KEY_QA_2); list
#                                each one in the step's `env:` block below
#
# The branch → environment bindings live in PlayServ (Project settings → Deployment),
# never in this repo.

name: Auto-deploy to PlayServ

on:
  push:
    branches: ['**']   # every branch (not tags) — the binding in PlayServ decides

# One deploy at a time per repo: two pushes must never roll a pool at once, and two
# branches bound to the same env would otherwise race on a first registration.
concurrency:
  group: playserv-deploy-${{ github.repository }}
  cancel-in-progress: false

jobs:
  deploy:
    runs-on: ubuntu-latest   # curl, jq and Docker (with buildx) are preinstalled
    steps:
      - uses: actions/checkout@v4

      - name: Resolve branch mapping and deploy
        env:
          PLAYSERV_HOST: ${{ vars.PLAYSERV_HOST }}
          PLAYSERV_SERVER_KEY: ${{ secrets.PLAYSERV_SERVER_KEY }}
          # Multi-env repos: expose each env's key so the script can pick by name.
          # PLAYSERV_SERVER_KEY_DEV: ${{ secrets.PLAYSERV_SERVER_KEY_DEV }}
          # PLAYSERV_SERVER_KEY_PROD: ${{ secrets.PLAYSERV_SERVER_KEY_PROD }}
        run: |
          set -euo pipefail
          BRANCH="${GITHUB_REF_NAME}"

          # ── 1. exchange any held key for a session (reading the bindings works with any environment's key)
          bootstrap_key="${PLAYSERV_SERVER_KEY:-}"
          if [ -z "$bootstrap_key" ]; then
            first_var=$(env | sed -n 's/^\(PLAYSERV_SERVER_KEY_[A-Z0-9_]*\)=.*/\1/p' | head -1)
            [ -n "$first_var" ] && bootstrap_key="${!first_var}"
          fi
          if [ -z "$bootstrap_key" ]; then
            echo "::error::no PLAYSERV_SERVER_KEY / PLAYSERV_SERVER_KEY_<ENV> secret is configured"
            exit 1
          fi

          # --fail-with-body keeps the platform's problem+json detail on errors
          # (a bare curl -f would swallow it and report only an opaque exit 22).
          exchange() {
            local resp
            # Send an explicit zero Content-Length: a bodyless POST can be rejected with 411.
            if ! resp=$(curl -sS --fail-with-body -X POST "$PLAYSERV_HOST/api/v1/auth/cli" \
                -H "Authorization: Bearer $1" -H "Content-Length: 0"); then
              echo "::error::auth/cli failed: $resp" >&2
              return 1
            fi
            printf '%s' "$resp"
          }
          session=$(exchange "$bootstrap_key")
          token=$(jq -r .access_token <<<"$session")
          project_id=$(jq -r .project_id <<<"$session")
          key_env=$(jq -r .env <<<"$session")

          # ── 2. fetch the branch→environment binding from PlayServ
          branch_q=$(jq -rn --arg v "$BRANCH" '$v|@uri')
          mapping=$(curl -sS --fail-with-body \
            "$PLAYSERV_HOST/api/v1/projects/$project_id/branch-env-bindings?branch=$branch_q" \
            -H "Authorization: Bearer $token") \
            || { echo "::error::mapping fetch failed: $mapping"; exit 1; }
          target_env=$(jq -r '[.data[] | select(.enabled)][0].env_name // empty' <<<"$mapping")

          if [ -z "$target_env" ]; then
            echo "branch '$BRANCH' is not mapped to an environment — nothing to deploy"
            exit 0
          fi
          echo "branch '$BRANCH' deploys to environment '$target_env'"

          # ── 3. one server key per environment: use the key whose environment matches
          deploy_key="$bootstrap_key"
          deploy_session="$session"
          if [ "$key_env" != "$target_env" ]; then
            env_var="PLAYSERV_SERVER_KEY_$(tr '[:lower:]-' '[:upper:]_' <<<"$target_env")"
            deploy_key="${!env_var:-}"
            if [ -z "$deploy_key" ]; then
              echo "::error::branch '$BRANCH' maps to env '$target_env' but no $env_var secret is configured (one deploy key per env)"
              exit 1
            fi
            deploy_session=$(exchange "$deploy_key")
            key_env=$(jq -r .env <<<"$deploy_session")
            if [ "$key_env" != "$target_env" ]; then
              echo "::error::secret $env_var holds a '$key_env' key, not a '$target_env' key"
              exit 1
            fi
          fi
          api_token=$(jq -r .access_token <<<"$deploy_session")
          project_slug=$(jq -r .project_slug <<<"$deploy_session")

          # PlayServ API call in the mapped environment: the body lands in $RESP, the HTTP
          # status is printed (so a 404 is an answer here, not a curl failure).
          RESP=$(mktemp)
          api() {
            local args=(-sS -o "$RESP" -w '%{http_code}' -X "$1" "$PLAYSERV_HOST$2"
              -H "Authorization: Bearer $api_token"
              -H "X-Project-Slug: $project_slug" -H "X-Env: $target_env")
            if [ $# -ge 3 ]; then args+=(-H "Content-Type: application/json" --data "$3"); fi
            curl "${args[@]}"
          }

          # ── 4. sort the manifests: functions go to `publish`, game servers never do
          functions=()
          servers=()
          while IFS= read -r manifest; do
            dir=$(dirname "$manifest")
            name=$(jq -r '.name // empty' "$manifest")
            [ -n "$name" ] || name=$(basename "$dir")
            kind=$(jq -r '.kind // "cloud_function"' "$manifest")
            if [ "$kind" = game_server ]; then
              servers+=("$name|$dir")
            else
              functions+=("$name")
            fi
          done < <(find . -name platform.json -not -path '*/bin/*' -not -path '*/obj/*' \
                     -not -path './.git/*' | sort)

          # ── 5. hand the functions to the CLI: it vendors shared projects into each
          #      bundle, uploads, and polls
          curl -fsSL "$PLAYSERV_HOST/api/v1/cli/download?rid=linux-x64" -o playserv
          chmod +x playserv
          # Talk to the same platform the CLI was downloaded from.
          export PLAYSERV_API_URL="$PLAYSERV_HOST"
          ./playserv login "$deploy_key"
          # The CLI's exit code (0 only if every function deployed) passes or fails the job.
          if [ ${#functions[@]} -gt 0 ]; then
            only=()
            for slug in "${functions[@]}"; do only+=(--only "$slug"); done
            ./playserv publish "${only[@]}" --env "$target_env" --yes
          else
            echo "no cloud functions in this repo"
          fi

          # ── 6. game servers: first push registers, later pushes roll the pool's image
          tag="${GITHUB_SHA::12}"
          room_config='{"capacity":16,"reservation_ttl_seconds":20,"room_lifetime_seconds":86400,"room_idle_timeout_seconds":60,"max_rooms":20}'
          for entry in "${servers[@]}"; do
            slug=${entry%%|*}
            dir=${entry#*|}

            # A server's own Dockerfile is written against its solution folder
            # (it copies nuget.config and the project from there); without one
            # the CLI writes a Dockerfile for the server folder itself.
            build=(--src "$dir")
            if [ -f "$dir/Dockerfile" ]; then
              context=$dir
              while [ "$context" != . ] && ! compgen -G "$context/*.sln*" >/dev/null; do
                context=$(dirname "$context")
              done
              build=(--src "$context" --dockerfile "$dir/Dockerfile")
            fi

            q=$(jq -rn --arg v "$slug" '$v|@uri')
            code=$(api GET "/api/v1/functions?kind=game_server&q=$q&limit=100")
            if [ "$code" != 200 ]; then
              echo "::error::could not read game server '$slug' in '$target_env' (HTTP $code): $(cat "$RESP")"
              exit 1
            fi
            state=$(jq -r --arg s "$slug" '[.data[] | select(.slug == $s)][0] | if . == null then "absent" elif .executor_run == "platform-pooled" and .status != "deleted" and .status != "disabled" then "pooled" else "\(.status) / \(.executor_run // "unknown")" end' "$RESP")

            case "$state" in
              pooled)
                echo "game server '$slug': rolling its pool to $tag"
                ./playserv image push --slug "$slug" "${build[@]}" --tag "$tag" --roll --env "$target_env"
                ;;
              absent)
                echo "game server '$slug' is new in '$target_env': registering it with a pool of 0 machines"
                ./playserv functions declare "$slug" --kind game_server \
                  --hosting-mode multi-room --description playserv-autodeploy --env "$target_env"
                code=$(api GET "/api/v1/functions?kind=game_server&q=$q&limit=100")
                fn_id=$(jq -r --arg s "$slug" '[.data[] | select(.slug == $s)][0].id // empty' "$RESP")
                if [ "$code" != 200 ] || [ -z "$fn_id" ]; then
                  echo "::error::'$slug' was declared but could not be read back (HTTP $code)"
                  exit 1
                fi
                code=$(api PUT "/api/v1/functions/$fn_id/room-config" "$room_config")
                if [[ $code != 2?? ]]; then
                  echo "::error::room configuration for '$slug' refused (HTTP $code): $(cat "$RESP")"
                  exit 1
                fi
                ./playserv image push --slug "$slug" "${build[@]}" --tag "$tag" --env "$target_env"
                pool=$(jq -cn --arg v "$tag" '{desired_size: 0, rooms_per_machine: 1, image_version: $v}')
                code=$(api PUT "/api/v1/machine-pools/$slug" "$pool")
                if [[ $code != 2?? ]]; then
                  echo "::error::pool for '$slug' refused (HTTP $code): $(cat "$RESP")"
                  exit 1
                fi
                echo "::notice::game server '$slug' registered in '$target_env' with a pool of 0 machines on $tag — raise its size in the Backoffice (Engineering → Servers)"
                ;;
              *)
                echo "::error::game server '$slug' exists in '$target_env' as '$state' (status / executor_run) — this workflow only registers a new server or rolls a pooled one. Finish it by hand in the Backoffice or with the PlayServ MCP (declare, room configuration, pool), or rename it in platform.json."
                exit 1
                ;;
            esac
          done

下一步

  • Servers —— fleet、副本、machine pool,以及选择 deployment point
  • Game Rooms —— 这些位置提供服务的实时 Room
  • Platform Health —— PlayServ 平台本身在各个位置是否健康

更新于 2026年10月22日