PyCharm cannot find app.yaml when pushing to GAE - python

I can't deploy to app engine.
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/appcfg.py -e my#gmail.com --passin --no_cookies update .
Usage: appcfg.py [options] update <directory> | [file, ...]
appcfg.py: error: Directory does not contain an app.yaml configuration file
Process finished with exit code 2
The project dir contains an app.yaml, which gae ca find when running the devserver.
Is this just another hopeless reinstall everything kind of problem?

Related

Django+Heroku: compilemessages works but not MY translation file.

I find myself in a very weird situation:
I do not have my .mo files committed into my repo. I plan to generate them after I deploy
I installed the gettext buildpack availabe at https://github.com/piotras/heroku-buildpack-gettext.git
So this are the steps I did:
Deploy to heroku.
Run heroku run python manage,py compilemessages
This is being outputted:
processing file django.po in /app/.heroku/python/lib/python3.6/site-packages/django/contrib/redirects/locale/ru/LC_MESSAGES
processing file django.po in /app/.heroku/python/lib/python3.6/site-packages/django/contrib/redirects/locale/cy/LC_MESSAGES
processing file django.po in /app/prometheus/locale/zh_hans/LC_MESSAGES
processing file django.po in /app/.heroku/python/lib/python3.6/site-packages/django/contrib/gis/locale/sk/LC_MESSAGES
List one of files: heroku run ls /app/.heroku/python/lib/python3.6/site-packages/django/contrib/redirects/locale/zh_Hans/LC_MESSAGES RESULTS: django.mo django.po
List our file: heroku run ls /app/prometheus/locale/zh_hans/LC_MESSAGES/
RESULTS: django.po
django.mo is missing.
I ran python manage.py shell to see if I have some variables wrong:
heroku run python manage.py shell
In [1]: from django from django.conf import settings
In [3]: print(settings.BASE_DIR)
/app/prometheus
In [4]: print(settings.LOCALE_PATHS)
('/app/prometheus/locale',)
So i have no idea why my django.mo file is not being generated.
Any guesses?
Since Heroku 20, gettext is automatically added for the default Python build package. This is only during build and not at runtime. Therefore the command should be executed just after build.
Luckily this can be done using the post compile file in bin/post_compile (no extension like procfile) with the following line:
python manage.py compilemessages
Optionally you can add the specific language (e.g. python manage.py compilemessages -l nl)
Since Heroku automatically adds gettext, there is no more need to add additional build packs (at least for gettext) like the one from Piotras mentioned above.
These files are generated in the build phase and will be part of the compressed image. Therefore they should not be deleted afterwards.
TL;DR: Django.mo is generated and then deleted.
I'm in the same situation and tried to generate the files with
$ heroku run django-admin compilemessages
$ heroku run ls locale/LANG/LC_MESSAGES/
django.po
I didn't want to wait for connecting to Heroku on every command and used
$ heroku run "django-admin compilemessages; ls locale/LANG/LC_MESSAGES/"
django.mo django.po
$ heroku run ls locale/LANG/LC_MESSAGES/
django.po
Turns out, django.mo is created but for some reason it is immediately deleted.
Googling this gives Heroku Help -page Why are my file uploads missing/deleted?:
The Heroku filesystem is ephemeral - that means that any changes to the filesystem whilst the dyno is running only last until that dyno is shut down or restarted. Each dyno boots with a clean copy of the filesystem from the most recent deploy.
What happens is
heroku run COMMAND
starts a new dyno, runs the command in it and shuts down the dyno once the command has exited, so all the files the command created are deleted.
As far as I know, options are either to commit the .mo-files to repo or serve them from storage, for example S3.

webpack and django on Heroku: bundling before collectstatic

I am building a django+react app on Heroku, using django-npm which automatically installs all modules from package.json to node-modules dir and then copies everything to staticfiles/ during python manage.py collectstatic (which is triggered by Heroku during deploy).
However, for this configuration to work I need to pre-bundle my React app before deployment and put it into my static folder along with all the CSS, fonts, etc. to be picked up by collectstatic later.
But I don't want to pollute my git diffs with new bundle versions. So, is there a way to make webpack create a bundle during deployment?
I know there is a release command on Heroku where I can put my npm run build. But the problem is it only fires AFTER collectstatic, so my bundle will only be created in static/ folder after this folder is scanned, and won't get copied to staticfiles dir.
Update:
Using bin/pre_compile should no longer be necessary as of March 11, 2019. Heroku will now automatically call an app's build script (if defined in package.json) during Heroku's build process. Source: Heroku Changelog.
Original: You can accomplish this with the (undocumented) pre_compile hook exposed by the heroku/python buildpack.
Add an executable shell file named bin/pre_compile at the top level of your app and it will be called automatically as part of the build process.
cd my-django-app
mkdir bin
echo '#!/usr/bin/env bash' >> bin/pre_compile
echo 'npm run build' >> bin/pre_compile
chmod +x bin/pre_compile

Deploying a simple python script to Heroku without Flask or Django

I'm trying to deploy a python script, but I get this error
Failed to detect app matching https://codon-buildpacks.s3.amazonaws.com/buildpacks/heroku/python.tgz buildpack
What files I have right now:
automation.py
A simple python script which imports praw, time, os and inspect.
requirements.txt
As described in the Heroku documents, I have created this file by running pip freeze > requirements.txt, containing:
astroid==1.5.2
colorama==0.3.8
isort==4.2.5
lazy-object-proxy==1.2.2
mccabe==0.6.1
praw==4.4.1.dev0
prawcore==0.10.1
pylint==1.7.1
requests==2.13.0
six==1.10.0
update-checker==0.16
wrapt==1.10.10
runtime.txt
Again as described in Heroku documents, this file contains the runtime for my script, containing:
python-3.6.0
I have changed my remote to heroku, added all files, commited and pushed to heroku master, but I get the error mentioned in the beginning. Is there something I'm doing wrong? I have seen this answer, but I'm not convinced. Would like to avoid any frameworks if possible.
git ls-files output
.gitignore
LICENSE
README.md
requirements.txt
runtime.txt
automation.py
In addition to runtime.txt and requirements.txt, a Procfile is required - that's how Heroku knows what script to run for your app. Without it, Heroku doesn't know automation.py is anything special. Note though - if your script doesn't listen on any port, define the process name as "worker" or anything other than "web". If you define it as "web" Heroku will expect it to bind to an externally visible port (not on localhost). If Heroku doesn't detect a port bind within 60 seconds, it reports the app as failed to start

Error while deploy my django website on heroku

I created a personal portfolio website using django and it also includes a blog. You can see the exact directory listing and source code in my github repository by clicking here
I have the procfile and the requirements.txt files as said in the heroku website and did the following in command prompt as directed by heroku :
$ heroku login
$ heroku git:clone -a appname
$ cd appname
$ git add .
$ git commit -am "make it better"
$ git push heroku master
Now I see the following error while deploying and the push fails :
Warning: Your application is missing a Procfile. This file tells Heroku how to run your application.
Yes there is a procfile in the directory though.
Please help me deploy this website in heroku.
Your file is called Procfile.txt. It should be called just Procfile.
It might be that you made a .txt file instead of a non-extension one or that you named it procfile and not Procfile. Heroku is sensitive about capitalisation.

Error using Google App Engine cloudshell to upload Python app

I'm trying to use appcfg to upload my helloworld app on GCloud using GAE. According to Google's own quickstarter site, the syntax is:
appcfg.py -A YOUR_PROJECT_ID_ -V v1 update helloworld/
So I did:
appcfg.py -A project_name_123456 -V v1 update c:/users/user/helloworld/
Which makes this error:
"appcfg.py: error: Not a directory: C:/users/user/helloworld"
What am I doing wrong? I have the app.yaml file in C:/users/user/helloworld, and I've tried lots of different things. Thanks

Categories