We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Feature/#2439 prefect server telemetry
**Thanks for contributing to Prefect!**

Please describe your work and make sure your PR:

- [x] adds new tests (if appropriate)
- [x] updates `CHANGELOG.md` (if appropriate)
- [x] updates docstrings for any new functions or function arguments, including `docs/outline.toml` for API reference docs (if appropriate)

Note that your PR will not be reviewed unless all three boxes are checked.

## What does this PR change?

This PR closes #2467 and adds some minimal telemetry to Prefect Server.

## Why is this PR important?

This is the first step into collecting usage information that can help the Prefect team understand how Prefect Server is being used and how we can make it better.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/prefect/cli/server.py`
Content:
```
1 import os
2 import shutil
3 import subprocess
4 import tempfile
5 import time
6 from pathlib import Path
7 
8 import click
9 import yaml
10 
11 import prefect
12 from prefect import config
13 from prefect.utilities.configuration import set_temporary_config
14 from prefect.utilities.docker_util import platform_is_linux, get_docker_ip
15 
16 
17 def make_env(fname=None):
18     # replace localhost with postgres to use docker-compose dns
19     PREFECT_ENV = dict(
20         DB_CONNECTION_URL=config.server.database.connection_url.replace(
21             "localhost", "postgres"
22         ),
23         GRAPHQL_HOST_PORT=config.server.graphql.host_port,
24         UI_HOST_PORT=config.server.ui.host_port,
25     )
26 
27     APOLLO_ENV = dict(
28         HASURA_API_URL="http://hasura:{}/v1alpha1/graphql".format(
29             config.server.hasura.port
30         ),
31         HASURA_WS_URL="ws://hasura:{}/v1alpha1/graphql".format(
32             config.server.hasura.port
33         ),
34         PREFECT_API_URL="http://graphql:{port}{path}".format(
35             port=config.server.graphql.port, path=config.server.graphql.path
36         ),
37         PREFECT_API_HEALTH_URL="http://graphql:{port}/health".format(
38             port=config.server.graphql.port
39         ),
40         APOLLO_HOST_PORT=config.server.host_port,
41     )
42 
43     POSTGRES_ENV = dict(
44         POSTGRES_HOST_PORT=config.server.database.host_port,
45         POSTGRES_USER=config.server.database.username,
46         POSTGRES_PASSWORD=config.server.database.password,
47         POSTGRES_DB=config.server.database.name,
48     )
49 
50     UI_ENV = dict(GRAPHQL_URL=config.server.ui.graphql_url)
51 
52     HASURA_ENV = dict(HASURA_HOST_PORT=config.server.hasura.host_port)
53 
54     ENV = os.environ.copy()
55     ENV.update(**PREFECT_ENV, **APOLLO_ENV, **POSTGRES_ENV, **UI_ENV, **HASURA_ENV)
56 
57     if fname is not None:
58         list_of_pairs = [
59             "{k}={repr(v)}".format(k=k, v=v)
60             if "\n" in v
61             else "{k}={v}".format(k=k, v=v)
62             for k, v in ENV.items()
63         ]
64         with open(fname, "w") as f:
65             f.write("\n".join(list_of_pairs))
66     return ENV.copy()
67 
68 
69 @click.group(hidden=True)
70 def server():
71     """
72     Commands for interacting with the Prefect Core server
73 
74     \b
75     Usage:
76         $ prefect server ...
77 
78     \b
79     Arguments:
80         start   ...
81 
82     \b
83     Examples:
84         $ prefect server start
85         ...
86     """
87 
88 
89 @server.command(hidden=True)
90 @click.option(
91     "--version",
92     "-v",
93     help="The server image versions to use (for example, '0.10.0' or 'master')",
94     hidden=True,
95 )
96 @click.option(
97     "--skip-pull",
98     help="Pass this flag to skip pulling new images (if available)",
99     is_flag=True,
100     hidden=True,
101 )
102 @click.option(
103     "--no-upgrade",
104     "-n",
105     help="Pass this flag to avoid running a database upgrade when the database spins up",
106     is_flag=True,
107     hidden=True,
108 )
109 @click.option(
110     "--no-ui",
111     "-u",
112     help="Pass this flag to avoid starting the UI",
113     is_flag=True,
114     hidden=True,
115 )
116 @click.option(
117     "--postgres-port",
118     help="The port used to serve Postgres",
119     default=config.server.database.host_port,
120     type=str,
121     hidden=True,
122 )
123 @click.option(
124     "--hasura-port",
125     help="The port used to serve Hasura",
126     default=config.server.hasura.host_port,
127     type=str,
128     hidden=True,
129 )
130 @click.option(
131     "--graphql-port",
132     help="The port used to serve the GraphQL API",
133     default=config.server.graphql.host_port,
134     type=str,
135     hidden=True,
136 )
137 @click.option(
138     "--ui-port",
139     help="The port used to serve the UI",
140     default=config.server.ui.host_port,
141     type=str,
142     hidden=True,
143 )
144 @click.option(
145     "--server-port",
146     help="The port used to serve the Core server",
147     default=config.server.host_port,
148     type=str,
149     hidden=True,
150 )
151 @click.option(
152     "--no-postgres-port",
153     help="Disable port map of Postgres to host",
154     is_flag=True,
155     hidden=True,
156 )
157 @click.option(
158     "--no-hasura-port",
159     help="Disable port map of Hasura to host",
160     is_flag=True,
161     hidden=True,
162 )
163 @click.option(
164     "--no-graphql-port",
165     help="Disable port map of the GraphqlAPI to host",
166     is_flag=True,
167     hidden=True,
168 )
169 @click.option(
170     "--no-ui-port", help="Disable port map of the UI to host", is_flag=True, hidden=True
171 )
172 @click.option(
173     "--no-server-port",
174     help="Disable port map of the Core server to host",
175     is_flag=True,
176     hidden=True,
177 )
178 def start(
179     version,
180     skip_pull,
181     no_upgrade,
182     no_ui,
183     postgres_port,
184     hasura_port,
185     graphql_port,
186     ui_port,
187     server_port,
188     no_postgres_port,
189     no_hasura_port,
190     no_graphql_port,
191     no_ui_port,
192     no_server_port,
193 ):
194     """
195     This command spins up all infrastructure and services for the Prefect Core server
196 
197     \b
198     Options:
199         --version, -v   TEXT    The server image versions to use (for example, '0.10.0' or 'master')
200                                 Defaults to the current installed Prefect version.
201         --skip-pull             Flag to skip pulling new images (if available)
202         --no-upgrade, -n        Flag to avoid running a database upgrade when the database spins up
203         --no-ui, -u             Flag to avoid starting the UI
204 
205     \b
206         --postgres-port TEXT    Port used to serve Postgres, defaults to '5432'
207         --hasura-port   TEXT    Port used to serve Hasura, defaults to '3001'
208         --graphql-port  TEXT    Port used to serve the GraphQL API, defaults to '4001'
209         --ui-port       TEXT    Port used to serve the UI, defaults to '8080'
210         --server-port   TEXT    Port used to serve the Core server, defaults to '4200'
211 
212     \b
213         --no-postgres-port      Disable port map of Postgres to host
214         --no-hasura-port        Disable port map of Hasura to host
215         --no-graphql-port       Disable port map of the GraphQL API to host
216         --no-ui-port            Disable port map of the UI to host
217         --no-server-port        Disable port map of the Core server to host
218     """
219 
220     docker_dir = Path(__file__).parents[0]
221     compose_dir_path = docker_dir
222 
223     # Remove port mappings if specified
224     if (
225         no_postgres_port
226         or no_hasura_port
227         or no_graphql_port
228         or no_ui_port
229         or no_server_port
230         or platform_is_linux()
231     ):
232         temp_dir = tempfile.gettempdir()
233         temp_path = os.path.join(temp_dir, "docker-compose.yml")
234         shutil.copy2(os.path.join(docker_dir, "docker-compose.yml"), temp_path)
235 
236         with open(temp_path, "r") as file:
237             y = yaml.safe_load(file)
238 
239             if no_postgres_port:
240                 del y["services"]["postgres"]["ports"]
241 
242             if no_hasura_port:
243                 del y["services"]["hasura"]["ports"]
244 
245             if no_graphql_port:
246                 del y["services"]["graphql"]["ports"]
247 
248             if no_ui_port:
249                 del y["services"]["ui"]["ports"]
250 
251             if no_server_port:
252                 del y["services"]["apollo"]["ports"]
253 
254             if platform_is_linux():
255                 docker_internal_ip = get_docker_ip()
256                 for service in list(y["services"]):
257                     y["services"][service]["extra_hosts"] = [
258                         "host.docker.internal:{}".format(docker_internal_ip)
259                     ]
260 
261         with open(temp_path, "w") as f:
262             y = yaml.safe_dump(y, f)
263 
264         compose_dir_path = temp_dir
265 
266     # Temporary config set for port allocation
267     with set_temporary_config(
268         {
269             "server.database.host_port": postgres_port,
270             "server.hasura.host_port": hasura_port,
271             "server.graphql.host_port": graphql_port,
272             "server.ui.host_port": ui_port,
273             "server.host_port": server_port,
274         }
275     ):
276         env = make_env()
277 
278     if "PREFECT_SERVER_TAG" not in env:
279         env.update(
280             PREFECT_SERVER_TAG=version
281             or (
282                 "master"
283                 if len(prefect.__version__.split("+")) > 1
284                 else prefect.__version__
285             )
286         )
287     if "PREFECT_SERVER_DB_CMD" not in env:
288         cmd = (
289             "prefect-server database upgrade -y"
290             if not no_upgrade
291             else "echo 'DATABASE MIGRATIONS SKIPPED'"
292         )
293         env.update(PREFECT_SERVER_DB_CMD=cmd)
294 
295     proc = None
296     try:
297         if not skip_pull:
298             subprocess.check_call(
299                 ["docker-compose", "pull"], cwd=compose_dir_path, env=env
300             )
301 
302         cmd = ["docker-compose", "up"]
303         if no_ui:
304             cmd += ["--scale", "ui=0"]
305         proc = subprocess.Popen(cmd, cwd=compose_dir_path, env=env)
306         while True:
307             time.sleep(0.5)
308     except:
309         click.secho(
310             "Exception caught; killing services (press ctrl-C to force)",
311             fg="white",
312             bg="red",
313         )
314         subprocess.check_output(
315             ["docker-compose", "down"], cwd=compose_dir_path, env=env
316         )
317         if proc:
318             proc.kill()
319         raise
320
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/prefect/cli/server.py b/src/prefect/cli/server.py
--- a/src/prefect/cli/server.py
+++ b/src/prefect/cli/server.py
@@ -38,6 +38,9 @@
             port=config.server.graphql.port
         ),
         APOLLO_HOST_PORT=config.server.host_port,
+        PREFECT_SERVER__TELEMETRY__ENABLED=(
+            "true" if config.server.telemetry.enabled is True else "false"
+        ),
     )
 
     POSTGRES_ENV = dict(

{"golden_diff": "diff --git a/src/prefect/cli/server.py b/src/prefect/cli/server.py\n--- a/src/prefect/cli/server.py\n+++ b/src/prefect/cli/server.py\n@@ -38,6 +38,9 @@\n             port=config.server.graphql.port\n         ),\n         APOLLO_HOST_PORT=config.server.host_port,\n+        PREFECT_SERVER__TELEMETRY__ENABLED=(\n+            \"true\" if config.server.telemetry.enabled is True else \"false\"\n+        ),\n     )\n \n     POSTGRES_ENV = dict(\n", "issue": "Feature/#2439 prefect server telemetry\n**Thanks for contributing to Prefect!**\r\n\r\nPlease describe your work and make sure your PR:\r\n\r\n- [x] adds new tests (if appropriate)\r\n- [x] updates `CHANGELOG.md` (if appropriate)\r\n- [x] updates docstrings for any new functions or function arguments, including `docs/outline.toml` for API reference docs (if appropriate)\r\n\r\nNote that your PR will not be reviewed unless all three boxes are checked.\r\n\r\n## What does this PR change?\r\n\r\nThis PR closes #2467 and adds some minimal telemetry to Prefect Server.\r\n\r\n## Why is this PR important?\r\n\r\nThis is the first step into collecting usage information that can help the Prefect team understand how Prefect Server is being used and how we can make it better.\r\n\n", "before_files": [{"content": "import os\nimport shutil\nimport subprocess\nimport tempfile\nimport time\nfrom pathlib import Path\n\nimport click\nimport yaml\n\nimport prefect\nfrom prefect import config\nfrom prefect.utilities.configuration import set_temporary_config\nfrom prefect.utilities.docker_util import platform_is_linux, get_docker_ip\n\n\ndef make_env(fname=None):\n    # replace localhost with postgres to use docker-compose dns\n    PREFECT_ENV = dict(\n        DB_CONNECTION_URL=config.server.database.connection_url.replace(\n            \"localhost\", \"postgres\"\n        ),\n        GRAPHQL_HOST_PORT=config.server.graphql.host_port,\n        UI_HOST_PORT=config.server.ui.host_port,\n    )\n\n    APOLLO_ENV = dict(\n        HASURA_API_URL=\"http://hasura:{}/v1alpha1/graphql\".format(\n            config.server.hasura.port\n        ),\n        HASURA_WS_URL=\"ws://hasura:{}/v1alpha1/graphql\".format(\n            config.server.hasura.port\n        ),\n        PREFECT_API_URL=\"http://graphql:{port}{path}\".format(\n            port=config.server.graphql.port, path=config.server.graphql.path\n        ),\n        PREFECT_API_HEALTH_URL=\"http://graphql:{port}/health\".format(\n            port=config.server.graphql.port\n        ),\n        APOLLO_HOST_PORT=config.server.host_port,\n    )\n\n    POSTGRES_ENV = dict(\n        POSTGRES_HOST_PORT=config.server.database.host_port,\n        POSTGRES_USER=config.server.database.username,\n        POSTGRES_PASSWORD=config.server.database.password,\n        POSTGRES_DB=config.server.database.name,\n    )\n\n    UI_ENV = dict(GRAPHQL_URL=config.server.ui.graphql_url)\n\n    HASURA_ENV = dict(HASURA_HOST_PORT=config.server.hasura.host_port)\n\n    ENV = os.environ.copy()\n    ENV.update(**PREFECT_ENV, **APOLLO_ENV, **POSTGRES_ENV, **UI_ENV, **HASURA_ENV)\n\n    if fname is not None:\n        list_of_pairs = [\n            \"{k}={repr(v)}\".format(k=k, v=v)\n            if \"\\n\" in v\n            else \"{k}={v}\".format(k=k, v=v)\n            for k, v in ENV.items()\n        ]\n        with open(fname, \"w\") as f:\n            f.write(\"\\n\".join(list_of_pairs))\n    return ENV.copy()\n\n\n@click.group(hidden=True)\ndef server():\n    \"\"\"\n    Commands for interacting with the Prefect Core server\n\n    \\b\n    Usage:\n        $ prefect server ...\n\n    \\b\n    Arguments:\n        start   ...\n\n    \\b\n    Examples:\n        $ prefect server start\n        ...\n    \"\"\"\n\n\n@server.command(hidden=True)\n@click.option(\n    \"--version\",\n    \"-v\",\n    help=\"The server image versions to use (for example, '0.10.0' or 'master')\",\n    hidden=True,\n)\n@click.option(\n    \"--skip-pull\",\n    help=\"Pass this flag to skip pulling new images (if available)\",\n    is_flag=True,\n    hidden=True,\n)\n@click.option(\n    \"--no-upgrade\",\n    \"-n\",\n    help=\"Pass this flag to avoid running a database upgrade when the database spins up\",\n    is_flag=True,\n    hidden=True,\n)\n@click.option(\n    \"--no-ui\",\n    \"-u\",\n    help=\"Pass this flag to avoid starting the UI\",\n    is_flag=True,\n    hidden=True,\n)\n@click.option(\n    \"--postgres-port\",\n    help=\"The port used to serve Postgres\",\n    default=config.server.database.host_port,\n    type=str,\n    hidden=True,\n)\n@click.option(\n    \"--hasura-port\",\n    help=\"The port used to serve Hasura\",\n    default=config.server.hasura.host_port,\n    type=str,\n    hidden=True,\n)\n@click.option(\n    \"--graphql-port\",\n    help=\"The port used to serve the GraphQL API\",\n    default=config.server.graphql.host_port,\n    type=str,\n    hidden=True,\n)\n@click.option(\n    \"--ui-port\",\n    help=\"The port used to serve the UI\",\n    default=config.server.ui.host_port,\n    type=str,\n    hidden=True,\n)\n@click.option(\n    \"--server-port\",\n    help=\"The port used to serve the Core server\",\n    default=config.server.host_port,\n    type=str,\n    hidden=True,\n)\n@click.option(\n    \"--no-postgres-port\",\n    help=\"Disable port map of Postgres to host\",\n    is_flag=True,\n    hidden=True,\n)\n@click.option(\n    \"--no-hasura-port\",\n    help=\"Disable port map of Hasura to host\",\n    is_flag=True,\n    hidden=True,\n)\n@click.option(\n    \"--no-graphql-port\",\n    help=\"Disable port map of the GraphqlAPI to host\",\n    is_flag=True,\n    hidden=True,\n)\n@click.option(\n    \"--no-ui-port\", help=\"Disable port map of the UI to host\", is_flag=True, hidden=True\n)\n@click.option(\n    \"--no-server-port\",\n    help=\"Disable port map of the Core server to host\",\n    is_flag=True,\n    hidden=True,\n)\ndef start(\n    version,\n    skip_pull,\n    no_upgrade,\n    no_ui,\n    postgres_port,\n    hasura_port,\n    graphql_port,\n    ui_port,\n    server_port,\n    no_postgres_port,\n    no_hasura_port,\n    no_graphql_port,\n    no_ui_port,\n    no_server_port,\n):\n    \"\"\"\n    This command spins up all infrastructure and services for the Prefect Core server\n\n    \\b\n    Options:\n        --version, -v   TEXT    The server image versions to use (for example, '0.10.0' or 'master')\n                                Defaults to the current installed Prefect version.\n        --skip-pull             Flag to skip pulling new images (if available)\n        --no-upgrade, -n        Flag to avoid running a database upgrade when the database spins up\n        --no-ui, -u             Flag to avoid starting the UI\n\n    \\b\n        --postgres-port TEXT    Port used to serve Postgres, defaults to '5432'\n        --hasura-port   TEXT    Port used to serve Hasura, defaults to '3001'\n        --graphql-port  TEXT    Port used to serve the GraphQL API, defaults to '4001'\n        --ui-port       TEXT    Port used to serve the UI, defaults to '8080'\n        --server-port   TEXT    Port used to serve the Core server, defaults to '4200'\n\n    \\b\n        --no-postgres-port      Disable port map of Postgres to host\n        --no-hasura-port        Disable port map of Hasura to host\n        --no-graphql-port       Disable port map of the GraphQL API to host\n        --no-ui-port            Disable port map of the UI to host\n        --no-server-port        Disable port map of the Core server to host\n    \"\"\"\n\n    docker_dir = Path(__file__).parents[0]\n    compose_dir_path = docker_dir\n\n    # Remove port mappings if specified\n    if (\n        no_postgres_port\n        or no_hasura_port\n        or no_graphql_port\n        or no_ui_port\n        or no_server_port\n        or platform_is_linux()\n    ):\n        temp_dir = tempfile.gettempdir()\n        temp_path = os.path.join(temp_dir, \"docker-compose.yml\")\n        shutil.copy2(os.path.join(docker_dir, \"docker-compose.yml\"), temp_path)\n\n        with open(temp_path, \"r\") as file:\n            y = yaml.safe_load(file)\n\n            if no_postgres_port:\n                del y[\"services\"][\"postgres\"][\"ports\"]\n\n            if no_hasura_port:\n                del y[\"services\"][\"hasura\"][\"ports\"]\n\n            if no_graphql_port:\n                del y[\"services\"][\"graphql\"][\"ports\"]\n\n            if no_ui_port:\n                del y[\"services\"][\"ui\"][\"ports\"]\n\n            if no_server_port:\n                del y[\"services\"][\"apollo\"][\"ports\"]\n\n            if platform_is_linux():\n                docker_internal_ip = get_docker_ip()\n                for service in list(y[\"services\"]):\n                    y[\"services\"][service][\"extra_hosts\"] = [\n                        \"host.docker.internal:{}\".format(docker_internal_ip)\n                    ]\n\n        with open(temp_path, \"w\") as f:\n            y = yaml.safe_dump(y, f)\n\n        compose_dir_path = temp_dir\n\n    # Temporary config set for port allocation\n    with set_temporary_config(\n        {\n            \"server.database.host_port\": postgres_port,\n            \"server.hasura.host_port\": hasura_port,\n            \"server.graphql.host_port\": graphql_port,\n            \"server.ui.host_port\": ui_port,\n            \"server.host_port\": server_port,\n        }\n    ):\n        env = make_env()\n\n    if \"PREFECT_SERVER_TAG\" not in env:\n        env.update(\n            PREFECT_SERVER_TAG=version\n            or (\n                \"master\"\n                if len(prefect.__version__.split(\"+\")) > 1\n                else prefect.__version__\n            )\n        )\n    if \"PREFECT_SERVER_DB_CMD\" not in env:\n        cmd = (\n            \"prefect-server database upgrade -y\"\n            if not no_upgrade\n            else \"echo 'DATABASE MIGRATIONS SKIPPED'\"\n        )\n        env.update(PREFECT_SERVER_DB_CMD=cmd)\n\n    proc = None\n    try:\n        if not skip_pull:\n            subprocess.check_call(\n                [\"docker-compose\", \"pull\"], cwd=compose_dir_path, env=env\n            )\n\n        cmd = [\"docker-compose\", \"up\"]\n        if no_ui:\n            cmd += [\"--scale\", \"ui=0\"]\n        proc = subprocess.Popen(cmd, cwd=compose_dir_path, env=env)\n        while True:\n            time.sleep(0.5)\n    except:\n        click.secho(\n            \"Exception caught; killing services (press ctrl-C to force)\",\n            fg=\"white\",\n            bg=\"red\",\n        )\n        subprocess.check_output(\n            [\"docker-compose\", \"down\"], cwd=compose_dir_path, env=env\n        )\n        if proc:\n            proc.kill()\n        raise\n", "path": "src/prefect/cli/server.py"}], "after_files": [{"content": "import os\nimport shutil\nimport subprocess\nimport tempfile\nimport time\nfrom pathlib import Path\n\nimport click\nimport yaml\n\nimport prefect\nfrom prefect import config\nfrom prefect.utilities.configuration import set_temporary_config\nfrom prefect.utilities.docker_util import platform_is_linux, get_docker_ip\n\n\ndef make_env(fname=None):\n    # replace localhost with postgres to use docker-compose dns\n    PREFECT_ENV = dict(\n        DB_CONNECTION_URL=config.server.database.connection_url.replace(\n            \"localhost\", \"postgres\"\n        ),\n        GRAPHQL_HOST_PORT=config.server.graphql.host_port,\n        UI_HOST_PORT=config.server.ui.host_port,\n    )\n\n    APOLLO_ENV = dict(\n        HASURA_API_URL=\"http://hasura:{}/v1alpha1/graphql\".format(\n            config.server.hasura.port\n        ),\n        HASURA_WS_URL=\"ws://hasura:{}/v1alpha1/graphql\".format(\n            config.server.hasura.port\n        ),\n        PREFECT_API_URL=\"http://graphql:{port}{path}\".format(\n            port=config.server.graphql.port, path=config.server.graphql.path\n        ),\n        PREFECT_API_HEALTH_URL=\"http://graphql:{port}/health\".format(\n            port=config.server.graphql.port\n        ),\n        APOLLO_HOST_PORT=config.server.host_port,\n        PREFECT_SERVER__TELEMETRY__ENABLED=(\n            \"true\" if config.server.telemetry.enabled is True else \"false\"\n        ),\n    )\n\n    POSTGRES_ENV = dict(\n        POSTGRES_HOST_PORT=config.server.database.host_port,\n        POSTGRES_USER=config.server.database.username,\n        POSTGRES_PASSWORD=config.server.database.password,\n        POSTGRES_DB=config.server.database.name,\n    )\n\n    UI_ENV = dict(GRAPHQL_URL=config.server.ui.graphql_url)\n\n    HASURA_ENV = dict(HASURA_HOST_PORT=config.server.hasura.host_port)\n\n    ENV = os.environ.copy()\n    ENV.update(**PREFECT_ENV, **APOLLO_ENV, **POSTGRES_ENV, **UI_ENV, **HASURA_ENV)\n\n    if fname is not None:\n        list_of_pairs = [\n            \"{k}={repr(v)}\".format(k=k, v=v)\n            if \"\\n\" in v\n            else \"{k}={v}\".format(k=k, v=v)\n            for k, v in ENV.items()\n        ]\n        with open(fname, \"w\") as f:\n            f.write(\"\\n\".join(list_of_pairs))\n    return ENV.copy()\n\n\n@click.group(hidden=True)\ndef server():\n    \"\"\"\n    Commands for interacting with the Prefect Core server\n\n    \\b\n    Usage:\n        $ prefect server ...\n\n    \\b\n    Arguments:\n        start   ...\n\n    \\b\n    Examples:\n        $ prefect server start\n        ...\n    \"\"\"\n\n\n@server.command(hidden=True)\n@click.option(\n    \"--version\",\n    \"-v\",\n    help=\"The server image versions to use (for example, '0.10.0' or 'master')\",\n    hidden=True,\n)\n@click.option(\n    \"--skip-pull\",\n    help=\"Pass this flag to skip pulling new images (if available)\",\n    is_flag=True,\n    hidden=True,\n)\n@click.option(\n    \"--no-upgrade\",\n    \"-n\",\n    help=\"Pass this flag to avoid running a database upgrade when the database spins up\",\n    is_flag=True,\n    hidden=True,\n)\n@click.option(\n    \"--no-ui\",\n    \"-u\",\n    help=\"Pass this flag to avoid starting the UI\",\n    is_flag=True,\n    hidden=True,\n)\n@click.option(\n    \"--postgres-port\",\n    help=\"The port used to serve Postgres\",\n    default=config.server.database.host_port,\n    type=str,\n    hidden=True,\n)\n@click.option(\n    \"--hasura-port\",\n    help=\"The port used to serve Hasura\",\n    default=config.server.hasura.host_port,\n    type=str,\n    hidden=True,\n)\n@click.option(\n    \"--graphql-port\",\n    help=\"The port used to serve the GraphQL API\",\n    default=config.server.graphql.host_port,\n    type=str,\n    hidden=True,\n)\n@click.option(\n    \"--ui-port\",\n    help=\"The port used to serve the UI\",\n    default=config.server.ui.host_port,\n    type=str,\n    hidden=True,\n)\n@click.option(\n    \"--server-port\",\n    help=\"The port used to serve the Core server\",\n    default=config.server.host_port,\n    type=str,\n    hidden=True,\n)\n@click.option(\n    \"--no-postgres-port\",\n    help=\"Disable port map of Postgres to host\",\n    is_flag=True,\n    hidden=True,\n)\n@click.option(\n    \"--no-hasura-port\",\n    help=\"Disable port map of Hasura to host\",\n    is_flag=True,\n    hidden=True,\n)\n@click.option(\n    \"--no-graphql-port\",\n    help=\"Disable port map of the GraphqlAPI to host\",\n    is_flag=True,\n    hidden=True,\n)\n@click.option(\n    \"--no-ui-port\", help=\"Disable port map of the UI to host\", is_flag=True, hidden=True\n)\n@click.option(\n    \"--no-server-port\",\n    help=\"Disable port map of the Core server to host\",\n    is_flag=True,\n    hidden=True,\n)\ndef start(\n    version,\n    skip_pull,\n    no_upgrade,\n    no_ui,\n    postgres_port,\n    hasura_port,\n    graphql_port,\n    ui_port,\n    server_port,\n    no_postgres_port,\n    no_hasura_port,\n    no_graphql_port,\n    no_ui_port,\n    no_server_port,\n):\n    \"\"\"\n    This command spins up all infrastructure and services for the Prefect Core server\n\n    \\b\n    Options:\n        --version, -v   TEXT    The server image versions to use (for example, '0.10.0' or 'master')\n                                Defaults to the current installed Prefect version.\n        --skip-pull             Flag to skip pulling new images (if available)\n        --no-upgrade, -n        Flag to avoid running a database upgrade when the database spins up\n        --no-ui, -u             Flag to avoid starting the UI\n\n    \\b\n        --postgres-port TEXT    Port used to serve Postgres, defaults to '5432'\n        --hasura-port   TEXT    Port used to serve Hasura, defaults to '3001'\n        --graphql-port  TEXT    Port used to serve the GraphQL API, defaults to '4001'\n        --ui-port       TEXT    Port used to serve the UI, defaults to '8080'\n        --server-port   TEXT    Port used to serve the Core server, defaults to '4200'\n\n    \\b\n        --no-postgres-port      Disable port map of Postgres to host\n        --no-hasura-port        Disable port map of Hasura to host\n        --no-graphql-port       Disable port map of the GraphQL API to host\n        --no-ui-port            Disable port map of the UI to host\n        --no-server-port        Disable port map of the Core server to host\n    \"\"\"\n\n    docker_dir = Path(__file__).parents[0]\n    compose_dir_path = docker_dir\n\n    # Remove port mappings if specified\n    if (\n        no_postgres_port\n        or no_hasura_port\n        or no_graphql_port\n        or no_ui_port\n        or no_server_port\n        or platform_is_linux()\n    ):\n        temp_dir = tempfile.gettempdir()\n        temp_path = os.path.join(temp_dir, \"docker-compose.yml\")\n        shutil.copy2(os.path.join(docker_dir, \"docker-compose.yml\"), temp_path)\n\n        with open(temp_path, \"r\") as file:\n            y = yaml.safe_load(file)\n\n            if no_postgres_port:\n                del y[\"services\"][\"postgres\"][\"ports\"]\n\n            if no_hasura_port:\n                del y[\"services\"][\"hasura\"][\"ports\"]\n\n            if no_graphql_port:\n                del y[\"services\"][\"graphql\"][\"ports\"]\n\n            if no_ui_port:\n                del y[\"services\"][\"ui\"][\"ports\"]\n\n            if no_server_port:\n                del y[\"services\"][\"apollo\"][\"ports\"]\n\n            if platform_is_linux():\n                docker_internal_ip = get_docker_ip()\n                for service in list(y[\"services\"]):\n                    y[\"services\"][service][\"extra_hosts\"] = [\n                        \"host.docker.internal:{}\".format(docker_internal_ip)\n                    ]\n\n        with open(temp_path, \"w\") as f:\n            y = yaml.safe_dump(y, f)\n\n        compose_dir_path = temp_dir\n\n    # Temporary config set for port allocation\n    with set_temporary_config(\n        {\n            \"server.database.host_port\": postgres_port,\n            \"server.hasura.host_port\": hasura_port,\n            \"server.graphql.host_port\": graphql_port,\n            \"server.ui.host_port\": ui_port,\n            \"server.host_port\": server_port,\n        }\n    ):\n        env = make_env()\n\n    if \"PREFECT_SERVER_TAG\" not in env:\n        env.update(\n            PREFECT_SERVER_TAG=version\n            or (\n                \"master\"\n                if len(prefect.__version__.split(\"+\")) > 1\n                else prefect.__version__\n            )\n        )\n    if \"PREFECT_SERVER_DB_CMD\" not in env:\n        cmd = (\n            \"prefect-server database upgrade -y\"\n            if not no_upgrade\n            else \"echo 'DATABASE MIGRATIONS SKIPPED'\"\n        )\n        env.update(PREFECT_SERVER_DB_CMD=cmd)\n\n    proc = None\n    try:\n        if not skip_pull:\n            subprocess.check_call(\n                [\"docker-compose\", \"pull\"], cwd=compose_dir_path, env=env\n            )\n\n        cmd = [\"docker-compose\", \"up\"]\n        if no_ui:\n            cmd += [\"--scale\", \"ui=0\"]\n        proc = subprocess.Popen(cmd, cwd=compose_dir_path, env=env)\n        while True:\n            time.sleep(0.5)\n    except:\n        click.secho(\n            \"Exception caught; killing services (press ctrl-C to force)\",\n            fg=\"white\",\n            bg=\"red\",\n        )\n        subprocess.check_output(\n            [\"docker-compose\", \"down\"], cwd=compose_dir_path, env=env\n        )\n        if proc:\n            proc.kill()\n        raise\n", "path": "src/prefect/cli/server.py"}]}