is there an easy way to execute scripts on Google App Engine localhost?
For instance i have few scripts to generate pilot data, it's quite painful to copy-and-paste them to the interactive console all the time.
Currently, i'm using a simple bash script to do this, but i'm not sure this is the best solution.
curl --data-urlencode "code=`cat src/gen_pilot_data.py`" http://localhost:8079/_ah/admin/interactive/execute
thanks,
V
Check out remote_api_shell.py, included in the SDK. This lets you run code on your local machine against APIs on your App Engine app, be they in production or on the dev_appserver.
The other option you have is to make your scripts into handlers, and simply GET or POST to the relevant URLs.
There is nothing special to do in order to execute script on AppEngine, but if you want to use AppEngine APIs you have to boot AppEngine before. I don't know the builtin one-line way, but you can take look how various projects do this:
https://bitbucket.org/wkornewald/djangoappengine/src/4f5d7a223084/boot.py
http://code.google.com/p/nose-gae/source/browse/trunk/nosegae.py?r=54
You can also try to import your script in console:
import gen_pilot_data
Related
I've setup Google App Engine to run my AdonisJS API for my website. I update the code using the CLI for google cloud services ("gcloud app deploy"). I get a success message from the terminal, and I have checked both the cloud build and version number, and both are the most recent deployment. However, when I try to use my website, I get an error due to the API using old code and trying to access table columns from my database that no longer exist. I have downloaded the most recent cloud build file and checked the codebase within it and the updated code is there. I have also tried deploying multiple times, and it still is using the old code. Does anyone know why this is happening and/or how to fix this?
If you need more information, let me know. Thanks
ANSWER:
Fixed this a while ago, but wanted to update here just in case others ran into this. I discovered that when deploying to GAE through the command line, my build command wasn't running prior to the deploy since my script had an error, so it was uploading updated code, but not an updated build. So just make sure to run the build command prior to uploading to GAE and everything should work.
In console.cloud.google.com, go to your GAE project and check which version of your project is running I.e. which one is receiving traffic
Clear your cache.
I am new at Google Cloud and I would like to know if there is a way to edit only one file inside of an App Engine application.
This is my problem:
I am migrating from a normal hosting to google cloud and I am having some problems with my PHP code, I am using the same version like locally but I am getting some error in the cloud, so I need to change 1 or 2 files, update them and test the app, so is there any way to change that file directly on the server? To deploy i am using this command:
gcloud app deploy
But it takes about 10 minutes to deploy so is too slow my testing. Any suggestions?
Thanks.
Leandro
For the standard environment the answer is no, you need to deploy a new version of the app to modify a file. So the advice would be - make the most of testing your app locally. See somehow related Google AppEngine - updating my webapp after deploy
For the flexible environment (possibly your case as you mentioned 10 min deployment time, typical for the flexible env) there might be stuff to try, but tedious, see Google AppEngine - updating my webapp after deploy
There is a way to edit directly into the instance.
ssh into your instance and then start shell on your running docker as guided in this url. https://cloud.google.com/appengine/docs/flexible/python/debugging-an-instance
After login you can see your php source files.
Basically you will not have any editor. So do
$> apt update
$> apt install nano
$> nano index.php // edit your files
you can see something like
There is no way to change 1-2 files on the server so that it would update the app. Deployment is the process of updating the live app. If you want some changes to be made to the app that is already deployed, you will have to redeploy - there is no way around it. This is why it is recommended to test the app locally before (re)deploying so that you are sure everything is working fine.
If locally everything works fine and issues start happening only when the app is deployed, this should be investigated further and I would advise you to open a new question and provide as much details as possible regarding the problems, including full stack trace of the error, related code parts, your app.yaml contents as well.
I need to test my wordpress install which I have set up already and deployed. I have to debug, so waiting 10-15 mins for it to deploy to test one thing isn't going to work.
All they mention in their docs: https://cloud.google.com/appengine/docs/flexible/php/testing-and-deploying-your-app#running_locally
Running locally
"To test your application's functionality before deploying, run your application in your local environment with the development tools that you usually use."
That's it. How can I actually serve my wordpress application? My tools I "usually use" are xampp...very confused.
Can someone help me run my flex env locally to test it?
You may want to take a look at this for the initial tests for your PHP application. You would have to install composer on your shell for it, if you haven't done it already.
Then, for the WordPress application, follow the steps described here to test the Cloud SQL instance that is associated to the app. There is also the possibility to test all the updates you want to apply to the WordPress side. Skip the deploying part until you confirm all your changes work for you, so that you don't have to wait all that time for a deployment.
I am very, very new to Google App Engine, but I need to administer a WebApp2 (so, Python) -based website that uses it. Specifically I need to filter a queryset and delete certain model instances.
Building the site locally is fine. Locally I can get at the models by hitting
http://localhost:8000/console
in my browser. This pulls up the "interactive console", and in there I can put some code like
from application.models.user import User
and it will work. From there I can create / delete User objects in the Datastore, so this local interactive console seems to have ORM-like functionality. (I'm coming from a Django background, so that's what it reminds me of).
However I don't seem to have this option on the live website. I was hoping to find it at
https://console.cloud.google.com/home/dashboard?project=<my project>
And I thought I had found it when I found the control to "activate google cloud shell". This brings up a command line on the web server, but the website's codebase doesn't seem to exist here, so launching the Python cli and trying to import the applications models like I can do locally doesn't work. And even if I could, I doubt it would be a Django-like ORM the way it is on my local build.
Am I thinking about this in the wrong way? How do you create / filter / delete / etc. Datastore objects via the backend in a GAE / WebApp2 website? Is the "Google cloud shell" even part of the answer?
To get access to your app code in the cloud shell one option would be to create in the shell a local copy of your app repository. For an example (addressing a different question, true) you can peek at Google Cloud: How to deploy mirrored Repository. But I'm not 100% certain if that will automatically give you access to your app's datastore. Worth a try IMHO.
Another option is to hook the desired operations as handler actions inside your app itself and execute them from there. Eventually hidden/protected/restricted via authentication, for example for admin users only. This is what I use for one-time datastore migrations that I need from time to time when I make changes to my entity models.
Finally, but not really a programatic access - you could use the Datastore page in the developer console to manually find, read and modify your entities, see Managing Datastore from the Console.
Use the remote_api_shell. You run this locally where your application code lives. Then you can import your models, and perform the same queries etc, and add modify/delete entities. I use this frequently for a range of tasks. Updating more than 100K records can become slow using this method.
https://cloud.google.com/appengine/docs/standard/python/tools/remoteapi
To run PHPUnit tests on Google Cloud's App Engine, I understand I would need to run a command on the command line like for example phpunit --bootstrap src/autoload.php tests/MoneyTest.
I tried opening the Google Cloud Shell in the Cloud Console, but I cannot seem to locate the code that I uploaded to be able to execute that command. When I use find -name "index.php" it shows me directories like ./etc/docker and ./run/dockerand a bunch of other locations, but all return a Permission denied message.
On the other hand, I tried creating a special webpage test.php that would just run the tests that I wanted to do, but I get a timeout error since the tests take way to long to run and it gets cut off after some seconds.
How could I use PHPUnit tests on the AppEngine, and not only locally on my machine?
App Engine is not the best tool to solve this problem because App Engine is designed to handle short-lived HTTP requests, not running long processes. Yes, there are ways run jobs of up to 10 minutes, but at some point you'll hit that timeout too.
Google Cloud Platform offers better solutions for long running processes. The most straight-forward is Google Compute Engine where you can run a dedicated Linux instance.