3
votes

I'm trying to deploy a golang app to app engine. Now I'm able to do it via the gcloud CLI on my mac, and this works fine (running gcloud app deploy app.yaml). However, I'm getting the following error on Bitbucket Pipelines:

+ gcloud --quiet --verbosity=error app deploy app.yaml --promote
You are about to deploy the following services:
 - some-project/default/20171128t070345 (from [/go/src/bitbucket.org/acme/some-app/app.yaml])
     Deploying to URL: [https://project-url.appspot.com]

Beginning deployment of service [default]...
ERROR: (gcloud.app.deploy) Staging command [/tmp/google-cloud-sdk/platform/google_appengine/goroot/bin/go-app-stager /go/src/bitbucket.org/acme/some-app/app.yaml /tmp/tmpLbUCA5] failed with return code [1].

------------------------------------ STDOUT ------------------------------------
------------------------------------ STDERR ------------------------------------
2017/11/28 07:03:45 failed analyzing /go/src/bitbucket.org/acme/some-app: cannot find package "github.com/gorilla/context" in any of:
    ($GOROOT not set)
    /go/src/github.com/gorilla/context (from $GOPATH)
GOPATH: /go
--------------------------------------------------------------------------------

Here's my bitbucket-pipelines.yaml content:

image: golang:onbuild

pipelines:
  branches:
    develop:
    - step:
        script: # Modify the commands below to build your repository.
          # Downloading the Google Cloud SDK
          - curl -o /tmp/google-cloud-sdk.tar.gz https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-155.0.0-linux-x86_64.tar.gz
          - tar -xvf /tmp/google-cloud-sdk.tar.gz -C /tmp/
          - /tmp/google-cloud-sdk/install.sh -q
          - source /tmp/google-cloud-sdk/path.bash.inc
          - PACKAGE_PATH="${GOPATH}/src/bitbucket.org/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}"
          - mkdir -pv "${PACKAGE_PATH}"
          - tar -cO --exclude-vcs --exclude=bitbucket-pipelines.yml . | tar -xv -C "${PACKAGE_PATH}"
          - cd "${PACKAGE_PATH}"
          - go get -v
          - go get -u github.com/golang/dep/cmd/dep
          - go build -v
          - go install
          - go test -v
          - echo $GOOGLE_CLIENT_SECRET | base64 --decode --ignore-garbage > ./gcloud-api-key.json
          - gcloud auth activate-service-account --key-file gcloud-api-key.json
          - gcloud components install app-engine-go
          #- GOROOT="/tmp/go"
          # Linking to the Google Cloud project
          - gcloud config set project $CLOUDSDK_CORE_PROJECT
          # Deploying the application
          - gcloud --quiet --verbosity=error app deploy app.yaml --promote
          - echo $GCLOUD_API_KEYFILE | base64 --decode --ignore-garbage > ./gcloud-api-key.json
          #- gcloud auth activate-service-account --key-file gcloud-api-key.json

And, though it shouldn't be an issue since deploying to the cloud works fine, my app.yaml file as well:

runtime: go
api_version: go1

handlers:
- url: /.*
  script: _go_app


nobuild_files:
- vendor

skip_files:
- |
  ^(.*/)?(
  (#.*#)|
  (.*\.mapping)|
  (.*\.po)|
  (.*\.pot)|
  (.*\.py[co])|
  (.*\.sw?)|
  (.*\.yaml)|
  (.*_test\.go)|
  (.*~)|
  (LICENSE)|
  (Makefile.*)|
  (\..*)|
  (vendor/.*)|
  )$

I'm fairly certain my issue is with how my bitbucket yaml file or the docker image I'm starting with, but I'm stuck. Any thoughts?

1
A typical problem causing failures for scripts automatically executed is lacking some environment var which, when successfully executed by hand, is somehow set, either manually or via some .rc file. The ($GOROOT not set) in your error msg could be hinting at this. Compare your environments in the 2 cases.Dan Cornilescu
I'm not a go user, so I'm unsure about this: your app appears to have some external dependencies (/go/src/github.com/gorilla/context) which might already be available on the system where you deploy manually, but might need to be pulled explicitly in the bitbucket pipeline.Dan Cornilescu
@DanCornilescu so I thought that too, and tried to set the GOROOT myself. however, the lines "cannot find package "github.com/gorilla/context" in any of: ($GOROOT not set) /go/src/github.com/gorilla/context (from $GOPATH) tells me that it's actually looking (and finding) something in my GOPATH.ephilip
Is github.com/gorilla/context only used within your test files? If so, go get, will not by default get test dependencies. What if you exclusively add go get github.com/gorilla/context to your pipeline script?PassKit
@PassKit it was only used within Gorilla Mux's package. Your fix worked, however (I swear i tried it before, and it didn't work) by adding go get github.com/gorilla/context to my pipeline. This is weird behaviour because I didn't have it in my local machine either. Anyways If you post your comment as an answer I can mark it as the correct one. Thanks a tonephilip

1 Answers

1
votes

Is github.com/gorilla/context only used within your test files?

go get, will not by default get test dependencies.

You can exclusively add go get github.com/gorilla/context to your pipeline script.