Run custom Python script before appcfg.py update runs - python

Is that possible to run some Python script every time I run deployment process with appcfg.py? I need that to copy some files from external source to my app folder before uploading it to GAE. Thanks!

I checked briefly the sources of appcfg.py, the script that deploys the application to Google App Engine, but I didn't find a place where a pre-deploy hook can be defined.
I believe that modifying appcfg.py itself would me not mantainable and a bit overkill.
You should create a simple deployment script and call your command from the script.
For example, you can create a simple Makefile with only one target that does what you want:
deploy:
your-copy-command
/path/to/gae-devkit/appcfg.py update .
Running the make command will execute the command to copy external files and call the Google App Engine deployment tool.

Related

Edit Azure function (Python) in VS code

I'm new to using Azure function apps and need to publish an updated init.py file to an existing function app.
Since Download app content is missing and I'll need to recreate it locally, what is normally contained in this file?
Is it possible to make sure all of the original settings remain the same and only update the init.py file?
For this requirement, I think you just need to copy the init.py code from azure to your new function in local VS code and copy the function.json from azure to local VS code.
In the new function you created in VS code, you need to use the init.py code and function.json copied above. And you need to run the command pip freeze > requirements.txt in "TERMINAL" in VS code to generate a requirements.txt which contains all of the pip modules used in your new function.
Then you can deploy it from VS code to Azure, the init.py(local) will cover the init.py in Azure and the function.json(local) will also cover the function.json in Azure. The new function in Azure will rebuild(install the pip modules) according to the requirements.txt you generated just now.
You can run this command in "TERMINAL" in VS code to deploy your new function from local to azure.
func azure functionapp publish hurypyfunapp --build remote
The new function you deployed from local to azure will not affect other settings such as "Application settings" and so on.
By the way, before the deployment, you can test your function locally by running the command below in "TERMINAL" in VS code to start your function.
func host start
Hope it helps~

Bamboo Can not detect repository commit when flask application is running

I am doing a Bamboo plan with two task,
check out source code from the git
run the flask (Python) application
And I want to execute the above plans in Bamboo when a new commit happens in in git repository.
I have configured my project as per the Bamboo Documentation
But, After execute the 2nd task (Python application) Bamboo could not detect the commit changes and not executing the tasks also.
Only Works if all tasks are stopped.
Bamboo itself is running the Flask application and not your system. As a result, the Bamboo build never finishes and all other Bamboo threads related to this build plan are locked. Bamboo tasks will often run until they receive an exit code, which will never happen while your Flask app is running.
Instead of attempting to run the code from Bamboo, you should instead run the flask app outside of bamboo. You can then trigger a reload of your flask app from within Bamboo on source code changes. This will require:
Have Bamboo detection setup to trigger on code changes (you have this and it sounds like it is working even though it is currently blocked).
Have a task where you checkout the source code - but check it out to the directory where you are going to be running the Flask app.
Configure your flask application to watch this source code folder outside of Bamboo. When the source code is updated it will reload the app. The Flask documentation explains this but you can also do it with this one line:
$ FLASK_APP=main.py FLASK_DEBUG=1 python -m flask run
There are several good answers here on SO that go over how to reload your flask app with the latest code changes:
Auto reloading python Flask app upon code changes
How to reload python module in flask?
Resolved by using docker inside Bamboo. Working fine.
Done the following.
Check out source code from repository
Created docker container as a task in Bamboo
Run the docker container using bamboo.
Installed python dependencies with docker file

dev_appserver.py doesn't run the app engine, instead it asks how do I want to open .py files for windows 10

I am currently running a tutorial for python on google app engine using the python docs samples repository. When I try to run dev_appserver.py in the hello_world folder, it doesn't open the app engine locally, but instead asks me how I want to display .py files, which if I select an application, will open it as a python text file instead.
Thanks
You're probably best off using the command line to start up the local development server.
From the Start menu, you can search for cmd to open the command prompt. You might need to right click it and choose "Run as administrator."
Change directories to where your application's app.yaml file is located. For example:
cd C:\Users\<myname>\<myfolder_with_app.yaml>\
Run the dev_appserver.py against the current directory (indicated by the dot):
python dev_appserver.py .
If you get a command not found error, then you need to install Python. If you get a could not find the dev_appserver.py file then your PATH environment variable doesn't have the SDK path in it. See Using the Local Development Server for more information including troubleshooting.

App directory doesn't show up on google cloud shell

Probably a stupid question.
I'm new to google app engine. So I followed the tutorial and successfully deployed their HelloWorld app, where the final steps are done on the cloud shell.
Then I built my own app in flask on my local machine, tested it (pushed the repo to the project's cloud repo) and deployed it from the command line (gcloud app deploy) and it works fine, anyone can use the app on their browser and I can also see the source code in the console website.
But I don't see any directories when I use the cloud shell. I get the prompt username#project-id:~$ but when I ls, there's just one README file and no other directories, therefore I can't use the devapp_sever.py, gcloud app deploy or any other shell function on this project.
But when I choose the hello world project that was created initially, the shell shows an src directory which contains the app's code and I can use the shell and deploy the app from there.
What's happening here and what am I supposed to do.?
Think of your Cloud Shell as just another workstation with local disk similar to your local machine. To deploy code to an app engine app, Google will create a Cloud Source Repository. Having said that, this is not related to your Cloud Shell. You can of course git clone any Git repo into your Cloud Shell.
Dan also wrote a nice explanation here -
https://stackoverflow.com/a/42123320/7947020
Hope this clarifies it!

Download sqlite database from Heroku

I have a worker running python script every 2 hour on Heroku.
The problem is each time I 'pull' the changes from git.
There is no changes at all for the sqlite3 database.
But I am sure the program is running and the database has changed by looking at the log file.
heroku log
How to retrieve the .db file then ?
It sounds like you have a little misconception. Heroku's git support is effectively one-way; you can use it to push new code to be run on the server, but you can't use it to copy files from Heroku back to your local tree.
Unfortunately it looks like there's not a good easy way to copy a file from your app to your local machine; you can use heroku run console to get a bash shell, and then scp a file out, but you're "pushing" it out of Heroku, and thus run can only copy to things with valid IP addresses.
If you're really using sqlite for your app's storage, though, you're going to run into a bigger problem. The filesystem for your app on Heroku is ephemeral, in that changes you make can be wiped out at any time. Heroku will delete your app's local storage and start over fresh whenever it wants to.
The right way to do it is use Heroku's built-in Postgres support and store your application's data there. Not only will it persist, but you'll be able to access it directly using the Postgres command-line tools.
Accessing the heroku console can now be done with:
heroku run bash
then i downloaded the linux gdrive application and ran in locally in the folder to upload my file to google drive. https://olivermarshall.net/how-to-upload-a-file-to-google-drive-from-the-command-line/ (skip step 4 and run with ./ like this ./gdrive upload my_file.txt
the other suggestion of heroku run console did not work for me (running a python flask app)

Categories