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

issue with: python manage.py simple_deploy --automate-all #57

Closed
qvisty opened this issue Feb 20, 2022 · 17 comments
Closed

issue with: python manage.py simple_deploy --automate-all #57

qvisty opened this issue Feb 20, 2022 · 17 comments

Comments

@qvisty
Copy link

qvisty commented Feb 20, 2022

What do I do now?

PS C:\Users\Jesper\Documents\jq Code\cs50w\wiki> & "c:/Users/Jesper/Documents/jq Code/cs50w/wiki/venvwiki/Scripts/Activate.ps1"
(venvwiki) PS C:\Users\Jesper\Documents\jq Code\cs50w\wiki> python manage.py simple_deploy --automate-all
Configuring project for deployment...
Automating all steps...
  Targeting Heroku deployment...
Configuring project for deployment to Heroku...

The --automate-all flag means simple_deploy will:
- Run `heroku create` for you, to create a new Heroku project.
- Commit all changes to your project that are necessary for deployment.   
  - These changes will be committed to the current branch, so you may want
    to make a new branch for this work.
- Push these changes to Heroku.
- Run the initial set of migrations to set up the remote database.
- Open your deployed project in a new browser tab.

Are you sure you want to do this? (yes|no)
yes
  Running `heroku create`...
Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\Jesper\Documents\jq Code\cs50w\wiki\venvwiki\lib\site-packages\django\core\management\__init__.py", line 425, in execute_from_command_line
    utility.execute()
  File "C:\Users\Jesper\Documents\jq Code\cs50w\wiki\venvwiki\lib\site-packages\django\core\management\__init__.py", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\Jesper\Documents\jq Code\cs50w\wiki\venvwiki\lib\site-packages\django\core\management\base.py", line 373, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\Jesper\Documents\jq Code\cs50w\wiki\venvwiki\lib\site-packages\django\core\management\base.py", line 417, in execute
    output = self.handle(*args, **options)
  File "C:\Users\Jesper\Documents\jq Code\cs50w\wiki\venvwiki\lib\site-packages\simple_deploy\management\commands\simple_deploy.py", line 64, in handle
    self._parse_cli_options(options)
  File "C:\Users\Jesper\Documents\jq Code\cs50w\wiki\venvwiki\lib\site-packages\simple_deploy\management\commands\simple_deploy.py", line 88, in _parse_cli_options       
    hd.deploy()
  File "C:\Users\Jesper\Documents\jq Code\cs50w\wiki\venvwiki\lib\site-packages\simple_deploy\management\commands\utils\deploy_heroku.py", line 27, in deploy
    self._prep_automate_all()
  File "C:\Users\Jesper\Documents\jq Code\cs50w\wiki\venvwiki\lib\site-packages\simple_deploy\management\commands\utils\deploy_heroku.py", line 68, in _prep_automate_all 
    output = subprocess.run(['heroku', 'create'], capture_output=True)
  File "C:\Python38\lib\subprocess.py", line 489, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Python38\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Python38\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] Den angivne fil blev ikke fundet```
@ehmatthes
Copy link
Owner

Hi, thanks for the report. I've done all of my testing on macOS to this point, and now that I run it on Windows I'm getting the same error you see here. I think it's an issue of how subprocess works on Windows. I'll look into it and get back to you on this.

@ehmatthes
Copy link
Owner

ehmatthes commented Feb 21, 2022

In the command subprocess.run(['heroku', 'create']) on macOS and Linux, the command heroku create is run. On Windows, the system looks for a file called 'heroku'. The fix is to include the argument shell=True in the subprocess.run() call. This makes deployment work on Windows. It shouldn't affect anything on macOS or Linux.

I'll test this on macOS shortly, and should have a fix pushed in the next day or two.

@ehmatthes
Copy link
Owner

Implementation

  • Prefer not to use shell=True on macOS or Linux.
  • So, check if os.name is 'nt'. If it is, set use_shell to True, otherwise to False. Then use that setting in all sp.run() calls.

@qvisty
Copy link
Author

qvisty commented Feb 21, 2022

Your replies are a bit too advanced for my skills. I will wait for --automate-all to just run on my machine :)
But thank you for replying so fast btw.

@ehmatthes
Copy link
Owner

@qvisty Yes sorry, those were my notes about how to fix it. I'm hoping to get that fix out sometime today. I think this affects anyone trying to use this on Windows, so I'm trying to get it taken care of soon.

@ehmatthes
Copy link
Owner

Okay, the latest release (0.2.3) works for me on Windows. You should be able to try it again with the following two commands:

$ pip install --upgrade django-simple-deploy
$ python manage.py simple_deploy --automate-all

I'd love to know if that fixes things for you as well.

@qvisty
Copy link
Author

qvisty commented Feb 23, 2022

better, but still not all the way. Maybe I did something wrong?

Configuring project for deployment...
  Found .git dir at C:\Users\Jesper\Documents\jq Code\jqdjangogirls.
Automating all steps...
  Targeting Heroku deployment...
Configuring project for deployment to Heroku...

The --automate-all flag means simple_deploy will:
- Run `heroku create` for you, to create a new Heroku project.
- Commit all changes to your project that are necessary for deployment.
  - These changes will be committed to the current branch, so you may want
    to make a new branch for this work.
- Push these changes to Heroku.
- Run the initial set of migrations to set up the remote database.
- Open your deployed project in a new browser tab.

Are you sure you want to do this? (yes|no)
yes
  Running `heroku create`...
https://whispering-savannah-88705.herokuapp.com/ | https://git.heroku.com/whispering-savannah-88705.git
  Inspecting Heroku app...
=== whispering-savannah-88705
Auto Cert Mgmt: false
Dynos:
Git URL:        https://git.heroku.com/whispering-savannah-88705.git
Owner:          jgq@live.dk
Region:         us
Repo Size:      0 B
Slug Size:      0 B
Stack:          heroku-20
Web URL:        https://whispering-savannah-88705.herokuapp.com/
    Found Heroku app: whispering-savannah-88705
  Setting Heroku environment variable...
ON_HEROKU: 1
    Set ON_HEROKU=1.
    This is used to define Heroku-specific settings.

  Looking for django-simple-deploy in requirements.txt...
    Added django-simple-deploy to requirements.txt.

  Looking in C:\Users\Jesper\Documents\jq Code\jqdjangogirls for Procfile...
    No Procfile found. Generating Procfile...
    Generated Procfile with following process:
      web: gunicorn mysite.wsgi --log-file -

  Looking for gunicorn...
    Added gunicorn to requirements.txt.

  Making sure project can be served from Heroku...
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\Jesper\Documents\jq Code\jqdjangogirls\venvdjangogirls\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line     
    utility.execute()
  File "C:\Users\Jesper\Documents\jq Code\jqdjangogirls\venvdjangogirls\lib\site-packages\django\core\management\__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\Jesper\Documents\jq Code\jqdjangogirls\venvdjangogirls\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\Jesper\Documents\jq Code\jqdjangogirls\venvdjangogirls\lib\site-packages\django\core\management\base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "C:\Users\Jesper\Documents\jq Code\jqdjangogirls\venvdjangogirls\lib\site-packages\simple_deploy\management\commands\simple_deploy.py", line 68, in handle
    self._parse_cli_options(options)
  File "C:\Users\Jesper\Documents\jq Code\jqdjangogirls\venvdjangogirls\lib\site-packages\simple_deploy\management\commands\simple_deploy.py", line 96, in _parse_cli_options
    self._check_platform()
  File "C:\Users\Jesper\Documents\jq Code\jqdjangogirls\venvdjangogirls\lib\site-packages\simple_deploy\management\commands\simple_deploy.py", line 106, in _check_platform
    hd.deploy()
  File "C:\Users\Jesper\Documents\jq Code\jqdjangogirls\venvdjangogirls\lib\site-packages\simple_deploy\management\commands\utils\deploy_heroku.py", line 35, in deploy   
    self._check_allowed_hosts()
  File "C:\Users\Jesper\Documents\jq Code\jqdjangogirls\venvdjangogirls\lib\site-packages\simple_deploy\management\commands\utils\deploy_heroku.py", line 189, in _check_allowed_hosts
    self.write_output(msg, write_to_console=False)
AttributeError: 'HerokuDeployer' object has no attribute 'write_output'```

@qvisty
Copy link
Author

qvisty commented Feb 23, 2022

...update:
I thought it might be because my pip was not fully updated. Did that. I did not help :(

@ehmatthes
Copy link
Owner

Okay, sorry about that. I have a clear fix for that, but I might not be able to get it out until the end of the week. I'll post back here when it's fixed.

@ehmatthes
Copy link
Owner

All right @qvisty, this should finally be fixed. I took longer than expected because I increased the test coverage of the project. If you're making time to report these issues, I want to make sure they're not going to reappear.

This latest issue was coming up because your ALLOWED_HOSTS setting was not empty. Originally I made simple_deploy exit if it found a non-empty ALLOWED_HOSTS, because that can be a sign of a project that's already been deployed. But a number of tutorials have people add something to ALLOWED_HOSTS. Also, simple_deploy only adds to ALLOWED_HOSTS in the section of settings.py that's specific to Heroku. So I simplified the logic to simply append the Heroku host to whatever is currently in ALLOWED_HOSTS. This still only applies to the version of the project that's pushed to Heroku.

You should be able to push your project by updating simple_deploy: pip install --upgrade django-simple-deploy, and then running the command again. If it fails please do let me know the latest issue. There may be a new issue from running the deploy command repeatedly, but it checks for most issues that could come from repeated calls.

Again, thanks for your reports, they've been really helpful!

@qvisty
Copy link
Author

qvisty commented Mar 4, 2022

It looked better for a moment, then a new error happened:
The whole terminal output is here: https://pastebin.com/Li20Z5sp

p.s. Can I add a flag to choose my app name instead of Whispering Savannah or the like on Heroku in any way?

@ehmatthes
Copy link
Owner

Is this the project you're trying to push? If so I'll try to push it from Windows and see if I can save you some back and forth in this issue. If that's not the project, can you post the repository?

p.s. Can I add a flag to choose my app name instead of Whispering Savannah or the like on Heroku in any way?

That's not covered by simple_deploy, but you can do that easily through the Heroku cli. I'm going to add a friendly summary to the logs that explains most of the simple tasks that people might want or need to do after the initial deployment.

I notice from the output log that you have 5 Heroku apps. It's easy to end up in that state. You can run heroku apps:list, and then heroku apps:destroy app_name to get rid of any apps you don't want to keep. Or you can go to your dashboard, click an app, click Settings, scroll to the bottom, and you'll find a delete button that does the same thing.

@ehmatthes
Copy link
Owner

I just figured out your latest issue. These lines from the output of simple_deploy shows that you have a static/ directory in your root project folder:

Configuring static files for Heroku deployment...
    ...
    Checking for static files directory...
    Found non-empty static files directory.

But these lines from Heroku tells us that Heroku is not seeing that folder:

remote:        FileNotFoundError: [Errno 2] No such file or directory: '/tmp/build_7dc728af/static'
remote: 
remote:  !     Error while running '$ python manage.py collectstatic --noinput'.

It's trying to run the management command collectstatic, which finds all static files in the project and copies them to one place, to serve the project more efficiently. Usually when this happens people either have uncommitted changes, or they're working on a branch that's not the main branch, or a resource is being ignored by Git. Heroku only receives files that are being managed by Git; if Git is ignoring a file, it won't push that file to Heroku.

I believe this is your .gitignore file. If you remove these two lines:

# Static folder at project root
/static/

I believe this most recent error will be resolved.

@qvisty
Copy link
Author

qvisty commented Mar 4, 2022

Is this the project you're trying to push?
No, but close. :) (I added you as a collaborator on the right one) This link should work for you: https://github.com/qvisty/jqdjangogirls
The project itself is just a project for the djangogirls tutorial. The purpose was to test simple-deploy for future deploys not specifically to deploy this project.
I will try the other changes you suggested now.

@qvisty
Copy link
Author

qvisty commented Mar 4, 2022

I notice from the output log that you have 5 Heroku apps. It's easy to end up in that state. You can run heroku apps:list, and then heroku apps:destroy app_name to get rid of any apps you don't want to keep. Or you can go to your dashboard, click an app, click Settings, scroll to the bottom, and you'll find a delete button that does the same thing.

I deleted four old tests now so that should be okay for the next test.

@qvisty
Copy link
Author

qvisty commented Mar 4, 2022

Now I ran it again after you suggested changes.
It worked like a charm. Thank you so much!
It there is valuable info in it for you here is the console log:
https://pastebin.com/vL2WgjRB
Now I am really looking forward to deploying for next project without all the hazzle.
Do I as Author click done here or do you as the repo Owner do that? (New to github issues)

@ehmatthes
Copy link
Owner

That's great, thanks for letting me know that it worked. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants