Skip to content

Commit

Permalink
Merge pull request #122 from ehmatthes/better_streaming
Browse files Browse the repository at this point in the history
Better streaming
  • Loading branch information
ehmatthes authored Oct 18, 2022
2 parents 7e1d986 + 5bce7ce commit 1b303ef
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ For inspiration and motivation, see [Keep a CHANGELOG](https://keepachangelog.co
0.5 - Supporting Fly.io, Platform.sh, and Heroku
---

### 0.5.4

- Streams output of long-running commands `fly postgres create` and `fly deploy`. This makes it much easier to know that the deployment is continuing, rather than hanging.

### 0.5.3

- Generates a `.dockerignore` file when deploying to Fly.io.
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = django-simple-deploy
version = 0.5.3
version = 0.5.4
description = A management command that auto-configures a Django project for deployment.
long_description = file: README.md
long_description_content_type=text/markdown
Expand Down
11 changes: 9 additions & 2 deletions simple_deploy/management/commands/simple_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ def _confirm_automate_all(self):
msg = plsh_msgs.confirm_automate_all
elif self.platform == 'fly_io':
msg = flyio_msgs.confirm_automate_all
else:
# The platform name is not valid!
# DEV: This should be removed when the logic around when to call
# _validate_platform() has been cleaned up.
# See issue #120: https://github.com/ehmatthes/django-simple-deploy/issues/120
error_msg = f"The platform {self.platform} is not currently supported."
raise CommandError(error_msg)

self.write_output(msg, skip_logging=True)
confirmed = self.get_confirmation(skip_logging=True)
Expand Down Expand Up @@ -650,7 +657,7 @@ def execute_subp_run(self, cmd, check=False):
return output


def execute_command(self, cmd):
def execute_command(self, cmd, skip_logging=False):
"""Execute command, and stream output while logging.
This method is intended for commands that run long enough that we
can't use a simple subprocess.run(capture_output=True), which doesn't
Expand All @@ -675,7 +682,7 @@ def execute_command(self, cmd):
with subprocess.Popen(cmd_parts, stderr=subprocess.PIPE,
bufsize=1, universal_newlines=True, shell=self.use_shell) as p:
for line in p.stderr:
self.write_output(line)
self.write_output(line, skip_logging=skip_logging)

if p.returncode != 0:
raise subprocess.CalledProcessError(p.returncode, p.args)
Expand Down
11 changes: 5 additions & 6 deletions simple_deploy/management/commands/utils/deploy_flyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,10 @@ def _conclude_automate_all(self):
self.sd.commit_changes()

# Push project.
# Use execute_command() to stream output of this long-running command.
self.sd.write_output(" Deploying to Fly.io...")
cmd = "fly deploy"
output = self.sd.execute_subp_run(cmd)
self.sd.write_output(output)
self.sd.execute_command(cmd)

# Open project.
self.sd.write_output(" Opening deployed app in a new browser tab...")
Expand Down Expand Up @@ -542,10 +542,9 @@ def _create_db(self):
if not self.sd.automate_all:
self._confirm_create_db(db_cmd=cmd)

# Create database and parse output.
output_obj = self.sd.execute_subp_run(cmd)
output_str = output_obj.stdout.decode()
self.sd.write_output(output_str, skip_logging=True)
# Create database.
# Use execute_command(), to stream output of long-running process.
self.sd.execute_command(cmd, skip_logging=True)

msg = " Created Postgres database."
self.sd.write_output(msg, skip_logging=True)
Expand Down

0 comments on commit 1b303ef

Please sign in to comment.