cloudfoundry / go-buildpack

Cloud Foundry buildpack for the Go Language
http://docs.cloudfoundry.org/buildpacks/
Apache License 2.0
82 stars 119 forks source link

Error while deploying go app with cf BP #55

Closed JenneyJ closed 6 years ago

JenneyJ commented 6 years ago

HI,

I've tried to push very simple go application to cloud foundry and I got the following error

successfully created container
Downloading app package...
Downloaded app package (3.5K)
-----> Download go 1.9.1
-----> Running go build supply
-----> Go Buildpack version 1.8.13
-----> Installing godep v79
-----> Installing glide v0.13.0
       Download [https://buildpacks.cloudfoundry.org/dependencies/dep/dep-v0.3.2-linux-x64-8910d5c1.tgz]
       Download [https://buildpacks.cloudfoundry.org/dependencies/godep/godep-v79-linux-x64-9e37ce0f.tgz]
-----> Installing dep v0.3.2
-----> Installing go 1.8.5
       Download [https://buildpacks.cloudfoundry.org/dependencies/go/go1.8.5.linux-amd64-fe5c03fb.tar.gz]
       Download [https://buildpacks.cloudfoundry.org/dependencies/glide/glide-v0.13.0-linux-x64-f13fe16b.tgz]
-----> Running go build finalize
       environment variable to your app's package name
       **ERROR** To use go native vendoring set the $GOPACKAGENAME
       **ERROR** Unable to determine import path: GOPACKAGENAME unset

ive created this simple example which provide the same error, any idea?

package main

import (
    "net/http"
    "fmt"
    "github.com/gorilla/mux"
    "strings"
    "os"
    //"github.com/cloudfoundry-community/go-cfenv"
)

func main(){

    r := mux.NewRouter()

    http.HandleFunc("/auth", auth)

    http.Handle("/", r)
    ports := getPorts()
    http.ListenAndServe(ports, nil)
}

func getPorts() string {
     port := os.Getenv("PORT")
    if port != "" {
        return port
    }else{
        return "8080"
    }
}

func auth(res http.ResponseWriter, req *http.Request) {
    //Set OS env
...

}

When I push my app I use cf push -b https://github.com/cloudfoundry/go-buildpack.git

the yaml is the following

applications:
- name: go_app
  buildpack: https://github.com/cloudfoundry/go-buildpack.git
  memory: 256M

Any idea what could be the problem ?

cf-gitbot commented 6 years ago

We have created an issue in Pivotal Tracker to manage this:

https://www.pivotaltracker.com/story/show/152713285

The labels on this github issue will be updated when the story is started.

dgodd commented 6 years ago

@JenneyJ You need to set the environment variable GOPACKAGENAME to the package that this app is (eg. your git repo path : github.com/org/repo). If the package name doesn't matter, (for instance you only have a main package) then you can set that variable to anything you like.

JenneyJ commented 6 years ago

@dgodd - I've only main package so i've tried(Mac) with export GOPACKAGENAME="" and also with export GOPACKAGENAME mygoapp and I got the same error .(not sure if importent - In the terminal I run those commads on the root project ) , ive only have package and main.go file...., any idea?

dgodd commented 6 years ago

@JenneyJ Sorry I was ambiguous, you need to set GOPACKAGENAME on your app in CF. You could either use cf set-env or more easily change your manifest.yml to

applications:
- name: go_app
  buildpack: https://github.com/cloudfoundry/go-buildpack.git
  memory: 256M
  env:
     GOPACKAGENAME: goapp
JenneyJ commented 6 years ago

@dgodd - Thanks a lot ! Now that I've add the the env I dont get the previous error, now I got this error.

       Download [https://buildpacks.cloudfoundry.org/dependencies/go/go1.8.5.linux-amd64-fe5c03fb.tar.gz]
-----> Running go build finalize
       **WARNING** Installing package '.' (default)
main.go:6:2: cannot find package "github.com/gorilla/mux" in any of:
-----> Running: go install -tags cloudfoundry -buildmode pie .
        /tmp/contents359235140/deps/0/go1.8.5/go/src/github.com/gorilla/mux (from $GOROOT)
        /tmp/gobuildpack.gopath575791729/.go/src/github.com/gorilla/mux (from $GOPATH)
       **ERROR** Unable to compile application: exit status 1
Exit status 223
Stopping instance 011200f7-z074-4aed-97b5-91235523c5b3
Failed to compile droplet: Failed to run finalize script: exit status 12
Destroying container

I've just create simple Go program as I write above and I use 'mux' ,any idea how to overcome this erorr, thanks!

dgodd commented 6 years ago

You will need to either use one of the dependency managers (eg. dep) or use native vendoring (probably best done using a dependency tool like dep)

You can see an example dep project at: https://github.com/cloudfoundry/go-buildpack/tree/master/fixtures/go18_dep_vendored/src/go18_dep

A simple example of native vendoring at: https://github.com/cloudfoundry/go-buildpack/tree/master/fixtures/native_vendoring

JenneyJ commented 6 years ago

@dgodd - ive installed the `dep' and now my program have in addition

vendor
Gopkg.lock
Gopkg.toml

but still i wasnt able to push it successfully to CF , now there is no error but the container crush... can you please check what can be wrong in this simple program ? why I cant simply push it to CF? Here is the program https://goo.gl/zxPLxE This is just some starting program which should be extended...

Thanks a lot!

dgodd commented 6 years ago

Hi @JenneyJ

The problem with your app is that http.ListenAndServe requires a ip:port combo, not just a port. If you change

http.ListenAndServe(ports, nil)

to

if err := http.ListenAndServe(":"+ports, nil); err != nil {
  panic(err)
}

all should work as you expect,

sclevine commented 6 years ago

Closing as addressed.