I am trying to follow the instructions for running a simple new Google App Engine web application locally (without Google Web Toolkit, just the Web App) named "tunes".
I am following these instructions. Step one is to make a run configuration. I made one using all the defaults; I checked that under the Server tab the "Run built-in Server" box is checked. However, when I Run the app, I get the Console; right below the console tab it says
<terminated> tunes [Web Application] C:\Program Files (x86)\Java\jre7\bin\javaw.exe (Feb 26, 2014, 5:35:44 PM)
then below the line is what looks like a classic Unix "Usage" error message in the console, in red type, whose first line is
Usage: <dev-appserver> [options] <app directory>
followed by a list of options, and then nothing else happens that I can see.
I tried pointing a browser at http://localhost:8888/tunes as suggested by the documentation, but Firefox could not find a server active at that port.
Under the Arguments tab in the Run Configuration is the following:
"-codeServerPort 9997 --port=8888 org.tunes.gaeproject.Tunes C:\Users\cdf\java\eclipse4.3.1workspace\tunes\war"
I can successfully deploy the web application to the Google App Engine site and run it there.
What do I have misconfigured?
Google AppEngine application is not meant to run on local server, and neither you could create its docker image etc to deploy it anywhere you wish.
Instead I suggest you to port your application to Google Compute Engine (GCE) first within your deployment setup, which might require minor code refactorings, and Kubernetes kinda auto-scaling deployment will functional equivalent to what you have now. But with approach you may port the application easily to local server setup, or a docker image to run from any virtualization environment
Related
I'm using Google App Engine and I've followed the instruction to setup Google Debugger as show here:
https://cloud.google.com/debugger/docs/setup/nodejs
My project is written in Node.js and I'm starting the service with this line:
require('#google-cloud/debug-agent').start({serviceContext: {enableCanary: true}});
I've also generated the source-context file.
When I go to the debugger console (https://console.cloud.google.com/debug) I see the green tick about the debug agent running but nothing is displayed on the left side, under "Deployed files".
Any ideas?
What you're seeing is intended behavior. Deployments to App Engine Standard will show the source code as the source files are included on deployment and not using a Docker container while deployments to App Engine Flex are using a Docker container, which currently need not to include the source files, hence why you need a source context information which is generated from a Git Repository. For more information about differences of standard and flex, please see Choose an App Engine environment.
For App Engine Flex app source code to appear on Cloud Debugger, it must be located on a remote code hosting provider. Make sure that you follow the Selecting source code automatically properly. Your main source code (js, yaml, and source-context.json) should be in the root directory of the repository as shown below.
App-directory/
main.py
app.yaml
source-context.json
I've successfully deployed sample application using Github showing the source codes on the left side as shown below.
Some important notes:
When using "Cloud Source Repositories" or "GitHub" or any of the other remote code hosting options, one must take some care:
Changes to the source file must be committed to version control before running gcloud debug source gen-repo-info-file.
gcloud debug source gen-repo-info must be run before deploying the App.
Commits must have been pushed to Cloud Source Repository/GitHub/etc before running Cloud Debugger.
Access must have been granted to the repo to the Cloud Debugger application.
Always redeploy application when there are changes to the repository or source code.
I would like to debug my Google App Engine (GAE) app locally but without using localhost. Since my application is made up of microservices, the urls in a production environment would be along the lines of:
https://my-service.myapp.appspot.com/
But code in one service can call another service and that means that the urls are hardcoded. I could of course use a mechanism in code to determine whether the app is running locally or on GAE and use urls that are different although I don't see how a local url would handle the since the only way to run an app locally is to use localhost. Hence:
http://localhost:8080/some-service
Notice that "some-service" maps to a servlet, whereas "my-service" is a name assigned to a service when the app is uploaded. These are really two different things.
The only possible solution I was able to find was to use a reverse proxy which would map one url to a different one. Still, it isn't clear whether the GAE development SDK even supports this.
Personally I chose to detect the local development vs GAE environment and build my inter-services URLs accordingly. I feel it was a well-worthy effort, I've been (re)using it a lot. No reverse proxy or any other additional ops necessary, it just works.
Granted, I'm using Python, so I'm not 100% sure a complete similar Java solution exists. But maybe it can point you in the right direction.
To build the per-service URLs I used modules.get_hostname() (the implementation is presented in Resolve Discovery path on App Engine Module). I believe the Java equivalent would be getInstanceHostname() from com.google.appengine.api.modules.
This method, when executed on the local server, automatically provides the particular port the server listens to for each service.
BTW, all my services for an app are executed by a single development server process, which listens on multiple ports (this is, I guess, how it can provide the modules.get_hostname() info). See Running multiple services using dev_appserver.py on different ports. This is part I'm unsure about: if/how the java local dev server can simultaneously run multiple services. Apparently this used to be supported some time ago (when services were still called modules):
Serving multiple GAE modules from one development server?
GAE modules on development server
This can be accomplished with the following steps:
Create an entry in the hosts file
Run the App Engine Dev server from a Terminal using certain options
Use IntelliJ with Remote debugging to attach the App Engine Dev server.
To edit the hosts file on a Mac, edit the file /etc/hosts and supply the domain that corresponds to your service:. Example:
127.0.0.1 my-service.myapp.com
After you save this, you need to restart your computer for the changes to take place.
Run the App Engine Dev server manually:
dev_appserver.sh --address=0.0.0.0 --jvm_flag=-Xdebug
--jvm_flag=-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
[path_to_exploded_war_directory]
In IntelliJ, create a debug configuration. Use the Remote template to create this configuration. Set the host to the url you set in the hosts file and set the port to 8000.
You can set a breakpoint and run the app in IntelliJ. IntelliJ will attach to the running instance of App Engine Dev server.
Because you are using a port during debugging and no port is actually used when the app is uploaded to the GAE during production, you need to add code that identifies when the app is running locally and when it's running on GAE. This can be done as follows:
private String mServiceUrl = "my-service.my-app.appspot.com";
...
if (SystemProperty.environment.value() != SystemProperty.Environment.Value.Production) {
mServiceUrl += ":8000";
}
See https://cloud.google.com/appengine/docs/standard/java/tools/using-local-server
An improved solution is to avoid including the port altogether and not having to use code to determine whether your app is running locally or on the production server. One way to do this is to use Charles (an application for monitoring and interacting with requests) and use a feature called Remote Mapping which lets you map one url to another. When enabled, you could map something like:
https://my-service.my-app.appspot.com/
to
https://localhost:8080
You would then enable the option to include the original host, so that this gets delivered to the local dev server. As far as your code is concerned it only sees:
https://my-service.my-app.appspot.com/
although the ip address will be 127.0.0.1:8080 when remote mapping is enabled. To use https on local host however does require that you enable ssl certificates for Charles.
For a complete overview on how to setup and debug microservices for a GAE Java app in IntelliJ, see:
https://github.com/JohannBlake/gae-microservices
(Background: I am new to Google App Engine, familiar with other cloud providers' services)
I am looking for access/view similar to shell access to production node.
With a Python/Django based Google App Engine App, I would like to view the code in production.
One view I could find is the StackDriver 'Debug' view.
However, apparently the code shown in the Debug view doesn't reflect the updated production code (based on what is showing on the production site, for example, the text on the home page different).
Does Google App Engine allow me to ssh into the VM where the application/code is running?
If not, how can check the code that's running in production?
Thanks.
According to the SSH debugging row in the Comparing environments table SSH access is supported for flex environment apps but not for standard environment apps.
From Connecting to the instance:
If a VM instance is in debug mode, you can connect to its host by
using SSH in the console or with gcloud.
To connect to an instance in the console:
Visit the Cloud Platform Console instances page for your project:
Go to the instances page
Click SSH in the far right of the row containing the instance you want to access:
This puts the instance into debug mode, and opens an SSH session for the instance in a terminal window.
You can also select different options to start an SSH session from the drop-down list.
At this point you are in the instance host, which has several containers running in it. See Understanding common
containers next for more information about these.
In the terminal window, list the containers running in the instance:
sudo docker ps
The output of the sudo docker ps command lists each container by row; locate the row that contains your project ID: this is the
container running your code. Note the NAME of this container.
Optionally, list logging information for your application by invoking:
sudo docker logs [CONTAINER-NAME]
Start a shell in the container that is running your code:
container_exec [CONTAINER-NAME] /bin/bash
When finished debugging, enter exit to exit the container, then exit again to exit the SSH session.
Disable debugging for your instance to allow it to resume normal operation.
If you are using the standard environment, the answer is no, you can't really inspect or see the code directly. You've mentioned looking at it via Stackdriver Debugger, which is one way to see a representation of it.
It sounds like if you have a reason to be looking at the code, then someone in your organization should grant you the appropriate level of access to your source code management system. I'd imagine if you're deployment practices are mature, then they'd likely branch the code to map to your deployed versions and you could inspect in detail locally.
I recently started building applications on Google App Engine. I use an Eclipse plugin to start and stop the server and deploy applications to run on Google App Engine.
I had created a new project and tried to stop and start it as suggested in the tutorials and in Stack Overflow. My old project is still running and hitting the data source successfully. I even removed the old projects from my Eclipse workspace and tried a fresh deploy of the new project with no luck.
How do I stop the server (the RED dot in my Eclipse has no effect)? Is uninstalling the App Engine the only solution?
When you launch the server, a new Java process is started. You can find and kill it independently of Eclipse.
I too ran into this problem and found the solution at Stop or restart a previously started Google App Engine local server in Eclipse
Just in case the link breaks, the key steps are:
In Eclipse, find the Eclipse Console view (looks like below).
Select the arrow next to the small computer and find the server's name
Select the red square to stop the server
Go to http://localhost:8888 to see if the page is still showing (it shouldn't be)
If you are visiting something like http://yourAppId.appspot.com and the server is still running, that's because it's still deployed on App Engine, not locally. In this case, go to Google Developer's Console and stop the service there
The server can be stopped by clicking red square icon in the console window. If this icon is missing or disabled, you may see wrong console window. You must select the javaw console using the drop-down button on the far right of the console window.
Go to Run/Debug Configurations -> Select your project configuration -> Common tab -> Uncheck "Launch in background"
Now, when you terminate the server on Server's console, it will stops the server.
I want to test and develop locally, while having the application on the air, and I'd rather not use two separate application id's because this means I have to change the code every time I deploy a new version and then change it back.
I understand that I can change the host file so that localdev.{{my application URL}} would refer to localhost and the URL will be valid, so I won't get the 191 code, but the Google App Engine launcher forces me to use port 8080, and this can't be defined in the host files. If I try to enter localdev.{{my application URL}}:8080 I get the 191 error code again.
Is there any way to use port 80 with the Google App Engine launcher?
Or is there another solution?
UPDATES:
I managed to run locally on port 80 by using the Python file from the Google App Engine directory and not the Google App Engine launcher GUI. However, Facebook doesn't recognize localdev.{{my application URL}} as the URL, and it still gives me the same error code, 191.
Once I changed the host file into {{my application URL}} without the "localdev." it worked, so this must mean the URLs must match exactly, and not just the domain. Is this true? Anyway, it isn't optimal, because it means I have to change the host file all the time, but it's something you can live with...
I have 2 Facebook apps, one with my real URL (for production), and one with http://127.0.0.1/ (for development). Then I have a utility function in my code which checks self.request.host, and selects the appropriate app id and secret.
The reason I use http://127.0.0.1/ and not http://localhost/ or http://localhost:8080/ is that I found only http://127.0.0.1/ would work in Internet Explorer (other browsers seemed fine with those other two URLs, provided they matched the Facebook app).