Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I debug a Dart AppEngine app

I'm now able to run a Dart app using

gcloud --verbosity debug preview app run app.yaml

and also to deploy and run on AppEngine

gcloud --verbosity debug preview app deploy app.yaml

but I haven't found a way to connect a debugger to the Dart app running on the development server.

I found http://dartbug.com/21067 but still couldn't find a way to make it work.

See also https://groups.google.com/a/dartlang.org/forum/#!topic/cloud/OK1nJtg7AjQ

like image 827
Günter Zöchbauer Avatar asked Nov 07 '14 18:11

Günter Zöchbauer


1 Answers

Update 2015-02-27

The app can be run without Docker and then be debugged like any Dart command line application: Source. https://groups.google.com/a/dartlang.org/d/msg/cloud/zrxgOHFz_lA/q5CdLLQPBAgJ

The API server is part of the App Engine SDK, and we are using it for running tests in the appengine package. If you look at https://github.com/dart-lang/appengine/blob/master/tool/run_tests.sh you will see that it expects the environment variable APPENGINE_API_SERVER.

The API server is in /platform/google_appengine/api_server.py

and takes a number of arguments. I just tested running it like this:

$ $CLOUD_SDK/platform/google_appengine/api_server.py \ -A dev~test-application \ --api_port 4444 \ --high_replication \
--datastore_path /tmp/datastore

To run an app engine application outside the normal development server requires that a number of environment variables are set. This worked for my application:

$ GAE_LONG_APP_ID=test-application \ GAE_MODULE_NAME=default \
GAE_MODULE_VERSION=version \ GAE_PARTITION=dev \ API_PORT=4444 \
API_HOST=127.0.0.1 \ dart bin/server.dart

In the Dart Editor you cannot set environment variables for each launch configuration, so they have to be set globally before starting the Dart Editor. In WebStorm it is possible to have run configuration specific environment variables.

This simple setup will of cause not support everything the normal development server support. Some of the issues are:

  • Only one application at the time as it is always listening on port 8080 (can easily be made configurable) * The users API (mocking this shouldn't be that difficult) * The modules API * No health-checks (should not be a problem) * All HTTP headers are direct from the client (no x-appengine- headers) * The admin web interface is not available * Probably other stuff as well

This is all experimental, but it is one solution for a simpler developer setup, which of cause does not match the deployment environment as closely as the development server.

Running the API Server using Docker is also possible as the image google/cloud-sdk with the Cloud SDK is on hub.docker.com.

Use the following Dockerfile

FROM google/cloud-sdk EXPOSE 4444 ENTRYPOINT ["/google-cloud-sdk/platform/google_appengine/api_server.py", \
"-A", "dev~test-application", \ "--api_port", "4444", \
"--high_replication", \ "--datastore_path", "/tmp/datastore"]

Build and run

$ docker build -t api_server . $ docker run -d -p 4444:4444 api_server

Change API_HOST above to 192.166.59.103 (of wherever your Docker containers are) and run.

Regards, Søren Gjesse

Update 2014-11-27

Debugging from DartEditors debugger started working with the bleeding Dart build 1.8.0.edge_042017. I assume that the next dev build (probably 1.9.0-dev1.0) will include the related fixes as well?

Detailed steps how this works can be found here: https://groups.google.com/a/dartlang.org/d/msg/cloud/OK1nJtg7AjQ/u-GzUDI-0VIJ

  • Build a custom Docker image with the latest Dart dev build 1.8.0-dev.4.6.
    The Dart team is actually preparing an easy way to do this yourself (see https://github.com/dart-lang/dart_docker)

  • Installe the latest bleeding_edge on the host system (using this script https://gist.github.com/zoechi/d240f56a32ed5649797f or manual download from http://gsdview.appspot.com/dart-archive/channels/be/raw/latest/editor/darteditor-linux-x64.zip)

  • Add this to the app.yaml file

env_variables:
  DBG_ENABLE: 'true'

# disable health-checking because this is so annoying during debugging
vm_health_check:
  enable_health_check: False

See How to disable health checking for `gcloud preview app run` for more details about customizing health checking.

  • Launch the server code of your app with glcoud --verbosity debug app run app.yaml or glcoud --verbosity debug app run app.yaml index.yaml

  • Wait until the Docker container is ready (check with docker ps if the Command column shows a value starting with /dart_runtime/dart_

  • Open DartEditor

  • Open Menu Run > Remote Connection...

    • Connect to: Command-line VM

    • Host: localhost if you dont use boot2dockeror the IP address returned by the commandboot2docker ip`

    • Port: 5005

    • Select Folder... select the directory which contains the source code of your project.

    • Click OK

    • Set breakpoints and continue as usual.

Old

A first step is using the Observatory which includes a browser based debugger UI.

To make this work add the following lines to the app.yaml file

network:
  forwarded_ports: ["8181"]

This might be useful as well to make the server.dart wait until we had the chance to set breakpoints using the observatory.

env_variables:
  DART_VM_OPTIONS: '--pause-isolates-on-start'

boot2docker gives us the Docker ip (192.168.59.103) and after starting with gcloud preview app run app.yaml we can connect to http://192.168.59.103:8181 which should open the Observatory GUI.

like image 133
Günter Zöchbauer Avatar answered Oct 24 '22 00:10

Günter Zöchbauer