# Versions and deployments

> How a Minekube game goes from your machine to players - versions named by their content, deployed to the servers a label selector picks in a Connect network, rolled back in one command, and swapped in while players stay connected.

On your machine, `mk dev` installs your game on the dev server. For players, the same bundles go to the servers of a [Connect network](https://minekube.com/guide/networks/), wherever those servers run. Each server swaps the new code in while players stay connected, as the dev server does.

> **Preview:**
> `vite.config.ts`, `mk deploy`, `mk versions`, `mk deployments`, `mk rollback` and `mk undeploy` work today, against the Minekube API on your machine (`mk api`) and against staging. Hostnames, custom domains, controlled updates and platform updates are planned; their pages say so.

## Versions and deployments

The model follows [Cloudflare Workers versions and deployments](https://developers.cloudflare.com/workers/configuration/versions-and-deployments/), with label selectors instead of shares of traffic:

| Cloudflare Workers | Minekube Games |
| --- | --- |
| A **version** is a fixed state of code and settings. | A **version** is the bundles of one build. Its id is the hash of its bundles, so the same bundles are the same version. |
| A **deployment** says which versions get traffic, at most two with a share each. | A **deployment** points a [label selector](https://minekube.com/guide/networks/labels#selectors) at a version. A network can have any number of them side by side. |
| A version key keeps a user on one version. | A server runs exactly one version per bundle, so all players on a server see the same game. |
| `wrangler deploy`, `wrangler rollback` | `mk deploy`, `mk rollback` |

A server runs the bundles of every deployment whose selector matches its labels. Where two deployments have a bundle of the same name, the newer one wins. Each server takes the bundles for its own platform: a Paper server the game, a Velocity proxy the proxy bundle.

## Who decides what

| Where | What |
| --- | --- |
| The project, in [`vite.config.ts`](https://minekube.com/games/versions-and-deployments/vite-plugin) | The bundles, and the targets they go to: a network and a selector each |
| The server, in [`connector.json`](https://minekube.com/guide/networks/connector-json) | Its labels, such as `channel=canary`, its key and the network it joins |
| The network, with `mk network` and `mk trust` | Its owner, invites and trust rules |

The server says what it is. The project says which servers it targets.

## Local first

Every command talks to the Minekube API. By default that is the Minekube API on your machine, `mk api` on `http://localhost:4776`, which runs the same code as Minekube's. Point a project at another one with `api` in `vite.config.ts`, the `MINEKUBE_API` environment variable or `--api`: Minekube's, staging, or one you host yourself.

## Steps

- **Create a network** and log in: [Create a network](https://minekube.com/guide/networks/create-a-network), in Connect.
- **Let servers in** with an invite, a trust rule, or your dev server: [Let servers in](https://minekube.com/guide/networks/let-servers-in), in Connect.
- **Name your bundles and targets** in `vite.config.ts`: [Vite plugin and configuration](https://minekube.com/games/versions-and-deployments/vite-plugin).
- **Deploy a version** to the servers a target's selector picks: [Deploy a version](https://minekube.com/games/versions-and-deployments/deploy).
- **Roll back and undeploy**: [Roll back and undeploy](https://minekube.com/games/versions-and-deployments/rollback).
- **How a server gets its bundles**: [How servers get their bundles](https://minekube.com/games/versions-and-deployments/bundle-delivery).
- **What comes next**: the planned pages below.

- [Vite plugin and configuration](https://minekube.com/games/versions-and-deployments/vite-plugin) (Preview)
- [Deploy a version](https://minekube.com/games/versions-and-deployments/deploy) (Preview)
- [Change the platform version](https://minekube.com/games/versions-and-deployments/platform-version) (Preview)
- [Roll back and undeploy](https://minekube.com/games/versions-and-deployments/rollback) (Preview)
- [How servers get their bundles](https://minekube.com/games/versions-and-deployments/bundle-delivery)
- [Controlled updates](https://minekube.com/games/versions-and-deployments/controlled-updates) (Planned)
- [Hostnames and custom domains](https://minekube.com/games/versions-and-deployments/hostnames) (Planned)
- [Platform updates](https://minekube.com/games/versions-and-deployments/platform-updates) (Planned)
