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

add --port parameter to "dbt docs serve" (#955) #987

Merged
merged 1 commit into from
Sep 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dbt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,12 @@ def parse_args(args):
seed_sub.set_defaults(cls=seed_task.SeedTask, which='seed')

serve_sub = docs_subs.add_parser('serve', parents=[base_subparser])
serve_sub.add_argument(
'--port',
default=8080,
type=int,
help='Specify the port number for the docs server.'
)
serve_sub.set_defaults(cls=serve_task.ServeTask,
which='serve')

Expand Down
8 changes: 5 additions & 3 deletions dbt/task/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ class ServeTask(RunnableTask):
def run(self):
os.chdir(self.project['target-path'])

port = 8080
port = self.args.port

shutil.copyfile(DOCS_INDEX_FILE_PATH, 'index.html')

logger.info("Serving docs at 0.0.0.0:{}".format(port))
logger.info(
"To access from your browser, navigate to http://localhost:8080.")
"To access from your browser, navigate to http://localhost:{}."
.format(port)
)
logger.info("Press Ctrl+C to exit.\n\n")

httpd = TCPServer(
Expand All @@ -29,7 +31,7 @@ def run(self):
)

try:
webbrowser.open_new_tab('http://127.0.0.1:8080')
webbrowser.open_new_tab('http://127.0.0.1:{}'.format(port))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not relevant to this change, but it looks like we serve on 0.0.0.0 but we open 127.0.0.1 in the browser. Is there an appreciable difference between these two addresses? I think that 0.0.0.0 is accessible to others on the network, right?

Copy link
Contributor Author

@beckjake beckjake Sep 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't access 0.0.0.0 - it's intended as a valid address for listening, and means that all source addresses can access it. 127.0.0.0/8 is reserved for loopback adapters and by default 127.0.0.1 is generally bound to a default loopback adapter on every OS, with a hosts file entry of 'localhost' pointing to it.

except webbrowser.Error as e:
pass

Expand Down