# Deploy a version

> Build your project with Vite and roll it out to the servers a target's label selector picks in a Connect network, with mk deploy. Each server swaps the new version in while players stay connected.

`mk deploy` takes your game from your machine to the servers of a network. It builds the project as `vite build` does, uploads what the build wrote to `dist/` as a version, and deploys the version to a target: every server the target's selector picks runs it.

**Before you start:** you need a network with at least one server in it. See [Create a network](https://minekube.com/guide/networks/create-a-network) and [Let servers in](https://minekube.com/guide/networks/let-servers-in) in Connect. `mk` talks to the Minekube API on your machine (`mk api`) unless you name another; for staging during the preview, set `MINEKUBE_API=https://api.staging.minekube.com` or `api` in `vite.config.ts`.

## Name a target

A target is a network and the servers a [label selector](https://minekube.com/guide/networks/labels#selectors) picks there. Add one to `vite.config.ts`:

```ts title="vite.config.ts"

export default defineConfig({
  plugins: [
    minekube({
      bundles: { "my-game": { platform: "paper", entry: "src/game.ts" } },
      targets: {
        prod: { network: "my-network", selector: "*" },
        canary: { network: "my-network", selector: "channel=canary" },
      },
    }),
  ],
});
```

`"*"` is every server of the network, written out, so a forgotten selector never rolls out to all of them.

## Deploy

In your project:

```sh
mk deploy canary
```

With only one target, `mk deploy` needs no argument. It prints the version it deployed:

```txt
Built my-game (paper 26.3, 652 KB) into dist
Deployed version 536a8f9a9253 to canary (the servers channel=canary picks in my-network): my-game (paper 26.3, 652 KB)
```

The version is named by the hash of its bundles, so deploying the same code twice makes no new version. Every server whose labels match runs it. A label comes from the server itself, in its `connector.json`, or from the invite or trust rule that let it in. A canary is a set of servers labelled `channel=canary`: try a version there first, then deploy it to `prod`.

`--message` and `--tag` describe the version, up to 100 and 25 characters. Without them, `mk deploy` takes the subject of the project's last git commit and its hash, 12 characters with `-dirty` for uncommitted changes.

## Upload now, deploy later

```sh
mk versions upload
mk versions deploy 536a8f9a9253 --target prod
```

`mk versions upload` builds and uploads a version without deploying it. `mk versions deploy` deploys a version uploaded before to a target. The id as `mk versions list` prints it is enough, or more of it (`mk versions list --full`) should two versions share those 12 characters.

## Watch it arrive

Each server's connector gets the new deployment, downloads the bundles it does not have, and the Minekube plugin swaps the game in. Players stay connected. On the server, the log says `Reloaded <id> (<revision>)`.

```sh
mk versions list
mk deployments list
```

`mk versions list` shows the network's 50 newest versions with the selectors that run each. `mk deployments list` shows what runs where, since when and by whom, and which of your targets each deployment belongs to.

## What goes up

`mk deploy` uploads exactly what `dist/` holds after the build. `dist/minekube.json` names each bundle with its platform, the [platform version](https://minekube.com/games/concepts/platform-version) it is built for and its SHA-256, and `mk` checks every file against it first. Before it deploys, `mk deploy` lists the servers of the target that run another version of the platform, by the registry's `minekube.com/version` label; `--strict-versions` refuses then. Client bundles stay on your machine: networks run server bundles only.

## Related

- [Roll back and undeploy](https://minekube.com/games/versions-and-deployments/rollback): go back to an earlier version.
- [Vite plugin and configuration](https://minekube.com/games/versions-and-deployments/vite-plugin): every field of `minekube()`.
- [How servers get their bundles](https://minekube.com/games/versions-and-deployments/bundle-delivery): what happens between `mk deploy` and the swap.
- [CLI reference](https://minekube.com/games/reference/cli#mk-deploy): every flag of `mk deploy`.
