How can I use PHPUnit with Google Cloud's App Engine? - google-app-engine

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.

Related

How to connect via ssh to google cloud run or appengine?

I know cloud run and appengine are different services.
I need connect via ssh to an appengine or cloud run instance to execute some process manually.
The reason to use one of these services is they charge only when I use it, not 24x7 hours
Some way to do that?
Thanks
Short answer: you can't.
In fact, these services are designed to answer to HTTP request, and only when an HTTP request is processed you pay for the service. If you log into an instance in SSH, will you pay for the HTTP request? If you run a process on the instances, will you pay for the HTTP request?
Of course not. But the cost isn't the main reason. Cloud Run and App Engine can create and destroy instances as they wish, according with the traffic or something else. It's useless to log into an instance and to run a process and few seconds/minutes after the instance is deleted and a new one created, you will lost all what you do.
If you use these services, you must accept that the servers are managed by Google, that you can only deploy a service and use it through HTTP. It's not a traditional VM instance, it's "serverless".
After saying that, if you want to explore the runtime configuration, you can use a HTTP reverse shell. But, at the end, it's not very useful...
Context
I code using codeanywhere, because I had multiple places with desktop computers to work and don't want to load a laptop
Actually I had vps's as enviroments, like my projects are long time, don't need to rebuild or change the enviroment in years
The need:
I run some times per month shell commands like test nodejs scripts, before to move them to serverless (cloud run)
The old-approach:
try to run these scripts on a working enviroment connecting via ssh
The moderm developer way:
use codeanywhere containers as code storage and testing + create a gitlab ci/cd to deploy automatically on google cloud run instances

Set traffic for Google App Engine using migrate option

We are on App Engine Standard running Python 3. Always used the following command in App Engine to migrate traffic after tests are passed.
gcloud app versions migrate $VERSION --service=“default”
Today around 11 am EET it stopped working. It waits for very long time and than exits with error. Permissions or anything else we can spot are changed.
After some investigation we found out that the following works:
gcloud app services set-traffic default --splits $VERSION=1
But we are afraid it drops all current connections.
We also tried (same as above but with --migrate):
gcloud app services set-traffic default --splits $VERSION=1 --migrate
But it didn't work in the same way as the original command we used.
Any ideas what may have caused this and is it safe to use the "set-traffic" command without --migrate option?

How to run a non-web-server long running Nodejs process in Google App Engine?

I created a Nodejs program that is intended to be executed as a long-running process unattended. The program works on localhost when running npm start. I need to be able to 'tail -f' its stdout on demand. There is no port it listens to. Does Google App Engine support this use case? If so, how to configure it?
I have deployed the app with following app.yaml file but it doesn't seem to work. At least the stdout of the instance is empty/unexpected. I believe the reason is App Engine is designed for web server and this process failed to pass health check of some sort.
runtime: nodejs
vm: true
btw, on Heroku this use case is clearly supported because it has two types of dyno: web and worker. Obviously worker dyno is the choice.

Google Compute Engine keeps spawning instances, then deploy says no CPU's available

I'm just going through the node.js tutorials with a free trial account, and i'm stuck on the second one where you add a db. I add the mongodb deployment, shows up as a VM instances, fine. And my first deploy worked, but now that i'm trying to edit stuff, my deploy's keep failing.
The error i get is that I've exceeded my CPU quota. Watching the list of VM Instances under Compute Engine, i see it keeps spawning up instances, even though the app isn't being used. Guessing it just spins up 8 instances by default?
But then i guess the build system needs its own VM's, but the CPU capacity is used up, so none available to do subsequent builds?! I feel like i'm missing something...
Also, i see i can explicitly start VM's myself, so what process is creating them form me? And can i turn it off? or set a cap on number of instances it spawns?
Can i tell my project to only use 4
Also, the deploy takes forever, is that normal? Following the tutorials, so far I've only seen this command to deploy:
gcloud preview app deploy app.yaml --set-default
Is there another command that does an incremental deploy or something?
By using gcloud preview app deploy you're actually using Managed VMs which is an App Engine runtime which in turn runs Docker containers on Google Compute Engine, which it creates on its own. In other words, you're not using Google Compute Engine directly.
To get rid of extra VMs, you need to delete old app versions: navigate to Compute > App Engine > Versions and delete the versions you don't want.
See also this answer for more details and suggestions.

executing scripts on Google App Engine localhost

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

Resources