Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update prefect server start command to specify and disable port mappings #2228

Merged
merged 12 commits into from Apr 1, 2020
Merged
10 changes: 5 additions & 5 deletions src/prefect/cli/docker-compose.yml
Expand Up @@ -4,7 +4,7 @@ services:
postgres:
image: "postgres:11"
ports:
- "5432:5432"
- "5432:${POSTGRES_HOST_PORT}"
joshmeek marked this conversation as resolved.
Show resolved Hide resolved
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
Expand All @@ -20,7 +20,7 @@ services:
hasura:
image: "hasura/graphql-engine:v1.1.0"
ports:
- "3000:3000"
- "3000:${HASURA_HOST_PORT}"
command: "graphql-engine serve"
environment:
HASURA_GRAPHQL_DATABASE_URL: ${DB_CONNECTION_URL}
Expand All @@ -35,7 +35,7 @@ services:
graphql:
image: "prefecthq/server:${PREFECT_SERVER_TAG:-latest}"
ports:
- "4201:4201"
- "4201:${GRAPHQL_HOST_PORT}"
command: bash -c "${PREFECT_SERVER_DB_CMD} && python src/prefect_server/services/graphql/server.py"
environment:
PREFECT_SERVER_DB_CMD: ${PREFECT_SERVER_DB_CMD:-"echo 'DATABASE MIGRATIONS SKIPPED'"}
Expand All @@ -61,7 +61,7 @@ services:
apollo:
image: "prefecthq/apollo:${PREFECT_SERVER_TAG:-latest}"
ports:
- "4200:4200"
- "4200:${APOLLO_HOST_PORT}"
command: "npm run serve"
environment:
HASURA_API_URL: ${HASURA_API_URL:-http://hasura:3000/v1alpha1/graphql}
Expand All @@ -75,7 +75,7 @@ services:
ui:
image: "prefecthq/ui:${PREFECT_SERVER_TAG:-latest}"
ports:
- "8080:8080"
- "8080:${UI_HOST_PORT}"
command: "/intercept.sh"
networks:
- prefect-server
Expand Down
63 changes: 59 additions & 4 deletions src/prefect/cli/server.py
Expand Up @@ -5,6 +5,7 @@

from pathlib import Path
from prefect import config
from prefect.utilities.configuration import set_temporary_config


def make_env(fname=None):
Expand All @@ -13,7 +14,9 @@ def make_env(fname=None):
PREFECT_ENV = dict(
DB_CONNECTION_URL=config.server.database.connection_url.replace(
"localhost", "postgres"
)
),
GRAPHQL_HOST_PORT=config.server.graphql.host_port,
UI_HOST_PORT=config.server.ui.port,
)

APOLLO_ENV = dict(
Expand All @@ -29,15 +32,17 @@ def make_env(fname=None):
PREFECT_API_HEALTH_URL="http://graphql:{port}/health".format(
port=config.server.graphql.port
),
APOLLO_HOST_PORT=config.server.port,
)

POSTGRES_ENV = dict(
POSTGRES_HOST_PORT=config.server.database.host_port,
POSTGRES_USER=config.server.database.username,
POSTGRES_PASSWORD=config.server.database.password,
POSTGRES_DB=config.server.database.name,
)

HASURA_ENV = dict()
HASURA_ENV = dict(HASURA_HOST_PORT=config.server.hasura.host_port)

ENV = os.environ.copy()
ENV.update(**PREFECT_ENV, **APOLLO_ENV, **POSTGRES_ENV, **HASURA_ENV)
Expand Down Expand Up @@ -96,13 +101,63 @@ def server():
@click.option(
"--no-ui", "-u", help="Pass this flag to avoid starting the UI", is_flag=True,
)
def start(version, skip_pull, no_upgrade, no_ui):
@click.option(
"--postgres-port",
help="The port used to serve Postgres",
default=config.server.database.host_port,
type=str,
)
@click.option(
"--hasura-port",
help="The port used to serve Hasura",
default=config.server.hasura.host_port,
type=str,
)
@click.option(
"--graphql-port",
help="The port used to serve the GraphQL API",
default=config.server.graphql.host_port,
type=str,
)
@click.option(
"--ui-port",
help="The port used to serve the UI",
default=config.server.ui.port,
type=str,
)
@click.option(
"--server-port",
help="The port used to serve the Core server",
default=config.server.port,
type=str,
)
def start(
version,
skip_pull,
no_upgrade,
no_ui,
postgres_port,
hasura_port,
graphql_port,
ui_port,
server_port,
):
"""
This command spins up all infrastructure and services for Prefect Server
"""
docker_dir = Path(__file__).parents[0]

env = make_env()
# Temporary config set for port allocation
with set_temporary_config(
{
"server.database.host_port": postgres_port,
"server.hasura.host_port": hasura_port,
"server.graphql.host_port": graphql_port,
"server.ui.port": ui_port,
"server.port": server_port,
joshmeek marked this conversation as resolved.
Show resolved Hide resolved
}
):
env = make_env()

if "PREFECT_SERVER_TAG" not in env:
env.update(PREFECT_SERVER_TAG=version)
Expand Down
11 changes: 6 additions & 5 deletions src/prefect/config.toml
Expand Up @@ -12,9 +12,9 @@ port = "4200"
endpoint = "${server.host}:${server.port}"

[server.database]

host = "localhost"
port = 5432
port = "5432"
host_port = "5432"
name = "prefect_server"
username = "prefect"
# set to "" to generate a random password each time the database starts
Expand All @@ -23,14 +23,15 @@ endpoint = "${server.host}:${server.port}"

[server.graphql]
host = "0.0.0.0"
port = 4201
port = "4201"
host_port = "4201"
debug = false
path = "/graphql/"

[server.hasura]

host = "localhost"
port = 3000
port = "3000"
host_port = "3000"
admin_secret = "" # a string. One will be automatically generated if not provided.
claims_namespace = "hasura-claims"
graphql_url = "http://${server.hasura.host}:${server.hasura.port}/v1alpha1/graphql"
Expand Down