igrigorik / ga-beacon

Google Analytics collector-as-a-service (using GA measurement protocol).
MIT License
3.54k stars 358 forks source link

Unable to deploy on own app engine #55

Closed mxbi closed 7 years ago

mxbi commented 7 years ago

Hi,

I'm trying to deploy this beacon on my own GCP app engine. The repo says:

Deploying your own instance is trivial: fork this repo, modify the project name in app.yaml, and follow the normal GAE deploy instructions. You should be up and running in less than five minutes.

But this doesn't seem to work for me. After modifying the app name, I get the following error when doing gcloud app deploy:

ERROR: (gcloud.app.deploy) The [application] field is specified in file [/home/mikel/ga-beacon/app.yaml]. This field is not used by gcloud and must be removed. Project name should instead be specified either by gcloud config set project MY_PROJECT or by setting the --project flag on individual command executions.

The same error appears about the version field. If I comment both fields out at the top of the yaml and specifying the project with --project I no longer get this error, however, I get the following error:

ERROR: (gcloud.app.deploy) Staging command [/usr/lib/google-cloud-sdk/platform/google_appengine/go-app-stager /home/mikel/ga-beacon/app.yaml /home/mikel/ga-beacon /tmp/tmpgyTDyh/tmpjjKhHK] failed with return code [1].

------------------------------------ STDOUT ------------------------------------
------------------------------------ STDERR ------------------------------------
2017/07/30 00:01:28 failed analyzing /home/mikel/ga-beacon: could not get package for dir "/home/mikel/ga-beacon": no buildable Go source files in /home/mikel/ga-beacon
GOPATH: /home/mikel/go
--------------------------------------------------------------------------------

It seems to be a problem with the fact that the go files are in a subdirectory but gcloud is only looking in the directory where the app.yaml is. I'm not familiar with app engine so I feel like this is an easy fix but I'm not sure what to do.

I've tried moving all the files from the ga-beacon subdirectory into the main directory, and while this does deploy, I simply get a internal error occured page when I try to go to the page.

I'm running Google Cloud SDK 164.0.0 on Ubuntu 14.04.

Thanks

igrigorik commented 7 years ago

AFAIK, this is a problem with your GOPATH. Take a look at Go documentation: https://github.com/golang/go/wiki/GOPATH

kshitijb commented 7 years ago

I don't think that's the reason. gcloud might have changed some configurations (I didn't really check that. The error message suggested it though). I just restructured the project as below and it worked just fine.

  go-beacon/
    static/
    app.yaml
    go-beacon.go
    page.html
igrigorik commented 7 years ago

@kshitijb interesting. If that's the case, can you make a PR so we can land this here too?

mxbi commented 7 years ago

@kshitijb I tried that, however when I deploy I am simply getting an HTTP 500 error when I try visiting the page, see https://mxbi-beacon.appspot.com/

EDIT: Looking at the app engine logs I see the error in go is: panic: open ga-beacon/page.html: no such file or directory

I've tried copying the stuff from inside the ga-beacon subdirectory to the root directory instead of simply moving it, so that the original page.html file still exists. However, I still get the same error.

kshitijb commented 7 years ago

Oh yeah! @mxbi You need to change pageTemplate value on line 26 to page.html instead of ga-beacon/page.html as the folder structure has changed.

Let me know if it works (It should :) ).

mxbi commented 7 years ago

@kshitijb Okay, by changing the pageTemplate value as suggested and then deleting the original files (only keeping the files in the root directory and not in the subfolder - without doing this I still got the error as it was using both go files for some reason) I was able to get the service to deploy without any errors! Thanks for the help,

I'll put the changes into a quick pull request (once I test that the beacon functionality actually reports to google analytics)