# Env From Scratch

In this example you will be shown how to create and configure a deployment environment for your game. It will have a basic setup with one general purpose Fleet meant to host game servers for a PC build or community. You can easily duplicate this Fleet for other platforms like PS4 or XBOne, or any other platform you want to target. Here is a simple diagram of such a setup:

<figure><img src="/files/coQ7JZE0hvKMcj8AwliJ" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
It is highly recommended to create multiple environments for e.g. Development, Test, Production, etc. For development, a deployment flow that automatically creates and destroys environments is very useful as well.
{% endhint %}

The following elements will be created in this chapter:

* [DeploymentEnvironment](/game-hosting/elements/deploymentenvironment.md)
* [Fleet](/game-hosting/elements/deploymentenvironment/fleet.md)
* [GameDeploymentTemplate](/game-hosting/elements/deploymentenvironment/index/gamedeploymenttemplate.md)
* [UtilityDeploymentTemplate](/game-hosting/elements/deploymentenvironment/index/utilitydeploymenttemplate.md) (optional)
* [DeploymentProfile](/game-hosting/elements/deploymentenvironment/deploymentprofile.md)
* [DeploymentRegion](/game-hosting/elements/deploymentenvironment/deploymentregion.md)

## Deployment Environment

The DeploymentEnviroment element encapsulates all the deployment related configuration elements for your game / application. The element itself is easy to create; you only need to supply a name:

[Full API reference](/api/api_one.md#v3-deploymentenvironment)

#### HTTP request

[`POST /v3/deploymentEnvironment`](/api/api_one.md#v3-deploymentenvironment)

#### Request body

```
{
  "name": "Bluewolf"
}
```

#### Response body

```
[
  {
    "id": "173892217340309897",
    "name": "Bluewolf",
    "createdAt": 1568312996
  }
]
```

## Fleet

This example Fleet represents deployments for a PC platform or community.

Amongst a Fleet's properties is `deploymentEnvironmentId`. We take this value from the response of previous request, assigning the Fleet to the DeploymentEnvironment we've just created. Other properties like `deploymentProfileId`, `gameDeploymentTemplateId` and `utilityDeploymentTemplateId` can be left empty for now. We will be creating these elements next and add them to the Fleet afterwards.

[Full API reference](/api/api_one.md#v3-fleet)

#### HTTP request

[`POST /v3/fleet`](/api/api_one.md#v3-fleet)

#### Request body

```
{
  "name": "Bluewolf PC",
  "deploymentEnvironmentId": "173892217340309897",
  "deploymentProfileId": "",
  "gameDeploymentTemplateId": "",
  "utilityDeploymentTemplateId": ""
}
```

#### Response body

```
[
  {
    "id": "7420099900751948711",
    "name": "Bluewolf PC",
    "deploymentEnvironmentId": "173892217340309897",
    "deploymentProfileId": "",
    "gameDeploymentTemplateId": "",
    "utilityDeploymentTemplateId": "",
    "operationalStatus": 0
  }
]
```

The `operationalStatus` property in the response is 0. This means automatic deployment is disabled. We will enable this in the next chapter, Starting Automatic Deployment after all configuration elements are in place.

## Game Deployment Template

The GameDeploymentTemplate element defines which game ApplicationBuild you want to deploy.

[Full API reference](/api/api_one.md#v3-deploymenttemplate-game)

#### HTTP request

[`POST /v3/deploymentTemplate/game`](/api/api_one.md#v3-deploymenttemplate-game)

#### Request body

```
{
  "name": "Bluewolf-server PC Game Deployment Template",
  "gameDeploymentTemplateBuild": [
    {
      "applicationBuildId": "2324653987059528218"
    }
  ]
}
```

#### Response body

```
[
  {
    "id": "4748702875218694016",
    "fleetIds": [],
    "name": "Bluewolf-server PC Game Deployment Template",
    "inUse": 0,
    "createdAt": 1568371305,
    "gameDeploymentTemplateBuild": [
      {
        "applicationBuildId": "2324653987059528218"
      }
    ]
  }
]
```

## Utility Deployment Template (optional)

The UtilityDeploymentTemplate describes any utilities (sidecars) you want to deploy onto each host that we deploy game instances onto.

You can indicate whether these should be installed on BM, VM or both and how many per DC location.

[Full API reference](/api/api_one.md#v3-deploymenttemplate-utility)

#### HTTP request

[`POST /v3/deploymentTemplate/game`](/api/api_one.md#v3-deploymenttemplate-utility)

#### Request body

```
{
  "name": "Bluewolf-server PC Utility Deployment Template",
  "utilityDeploymentTemplateBuild": [
    {
      "applicationBuildId": "3801243597300703061",
      "deployOn": 3,
      "installsPerLocation": 0
    }
  ]
}
```

#### Response body

```
[
  {
    "id": "6793353982360875057",
    "fleetIds": [],
    "name": "Bluewolf-server PC Utility Deployment Template",
    "inUse": 0,
    "createdAt": 1568371472,
    "utilityDeploymentTemplateBuild": [
      {
        "applicationBuildId": "3801243597300703061",
        "deployOn": 3,
        "installsPerLocation": 0
      }
    ]
  }
]
```

## Deployment Profile

Next, we create a DeploymentProfile. You create one per Fleet and as such has a 1:1 relation with a Fleet.

This element describes how to deploy your applications. You must set the deployment strategy, minimum deployment figures and the buffer value defining the pool of warm game servers that are ready to be allocated. These are global values that apply per DeploymentRegion and can be overridden on a per-DeploymentRegion basis.

A DeploymentProfile contains the DeploymentRegions that define where to deploy your applications. These are added to the DeploymentProfile afterwards.

[Full API reference](/api/api_one.md#v3-deploymentprofile)

#### HTTP request

[`POST /v3/deploymentProfile`](/api/api_one.md#v3-deploymentprofile)

#### Request body

```
{
  "name": "Bluewolf-server PC Deployment Profile",
  "description": "PC Fleet Deployment Profile",
  "strategyType": 1,
  "minimumCapacity": 0,
  "maximumCapacity": 0,
  "bufferValue": 0,
  "bufferValueType": 0,
  "bufferValueMin": 0,
  "bufferValueMax": 0
}
```

#### Response body

```
[
  {
    "id": "88465290039742335",
    "fleetIds": [],
    "name": "Bluewolf-server PC Deployment Profile",
    "description": "PC Fleet Deployment Profile",
    "strategyType": 1,
    "minimumCapacity": 0,
    "maximumCapacity": 0,
    "bufferValue": 0,
    "bufferValueType": 0,
    "bufferValueMin": 0,
    "bufferValueMax": 0,
    "markedForDeletion": 0,
    "inUse": 0,
    "deploymentRegions": [],
    "createdAt": 1568376027
  }
]
```

## Deployment Region

Next add a DeploymentRegion to the profile we have just created. This tells the platform in which data center(s) you want to deploy your game. Each DeploymentRegion is based on an i3D.net bare metal location (PoP) to which cloud datacenters can be added for the purpose of bursting onto when running out of bare metal capacity.

You can optionally override global DeploymentProfile parameters such as deployment strategy, minimumCapacity and buffer value if desired.

You can repeat this step for all the DeploymentRegions you want to create in your profile.

[Full API reference](/api/api_one.md#v3-deploymentregion-deploymentregionid)

#### HTTP request

[`POST /v3/deploymentProfile/88465290039742335/deploymentRegion`](/api/api_one.md#v3-deploymentregion-deploymentregionid-1)

#### Request body

```
{
  "name": "EU: Rotterdam",
  "i3dDcLocationIds": [
    6
  ],
  "containers": [
    {
      "containerLocations": [
        {
          "cloudProviderId": 31,
          "dcLocationId": 63,
          "primaryInstanceTypeName": "n1-highcpu-64",
          "secondaryInstanceTypeName": "n1-highcpu-32",
          "cpuPlatform": "Intel Broadwell"
        }
      ]
    }
  ]
}
```

#### Response body

```
[
  {
    "id": "2468882381297501628",
    "name": "EU: Rotterdam",
    "i3dDcLocationIds": [
      6
    ],
    "i3dDcLocationIdsToBeRemoved": [],
    "minimumCapacity": null,
    "maximumCapacity": null,
    "bufferValue": null,
    "bufferValueType": null,
    "bufferValueMin": null,
    "bufferValueMax": null,
    "strategyType": null,
    "markedForDeletion": 0,
    "containers": [
      {
        "id": "345414563890737521",
        "markedForDeletion": 0,
        "containerLocations": [
          {
            "id": "403382638377965874",
            "cloudProviderId": 31,
            "dcLocationId": 63,
            "primaryInstanceTypeName": "n1-highcpu-64",
            "secondaryInstanceTypeName": "n1-highcpu-32",
            "cpuPlatform": "Intel Broadwell",
            "markedForDeletion": 0
          }
        ]
      }
    ],
    "inUse": 0
  }
]
```

## Finalize the Fleet

Finally we can assign the previously created DeploymentTemplates and DeploymentProfile to the PC Fleet from earlier.

[Full API reference](/api/api_one.md#v3-fleet-fleetid)

#### HTTP request

[`PUT /v3/fleet/7420099900751948711`](/api/api_one.md#v3-fleet-fleetid)

#### Request body

```
{
  "deploymentProfileId": "88465290039742335",
  "gameDeploymentTemplateId": "4748702875218694016",
  "utilityDeploymentTemplateId": "6793353982360875057"
}
```

#### Response body

```
[
  {
    "id": "7420099900751948711",
    "name": "Bluewolf PC",
    "deploymentEnvironmentId": "173892217340309897",
    "deploymentProfileId": "88465290039742335",
    "gameDeploymentTemplateId": "4748702875218694016",
    "utilityDeploymentTemplateId": "6793353982360875057",
    "operationalStatus": 0
  }
]
```

Everything you need to start your first deployment is in place!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.i3d.net/game-hosting/examples/env-from-scratch.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
