3

I'm creating a web app in beego that I need to have running in Heroku.

I can get it running normally if I just specify the binary for the app in the Procfile. But I want to have swagger available in the app, so I need to use bee to start the app like:

bee run -downdoc=true -gendoc=true

so that it automatically creates and downloads all the swagger related icons, html, etc.

But, if I specify that as the command in Procfile (even after adding bee to vendor so that it is available), it fails because the app doesn't have the go command available in runtime. The exact error is this:

0001 There was an error running 'go version' command: exec: "go": executable file not found in $PATH

How can I bypass this without adding the whole swagger specification to heroku (and github, since it is a repository)?

mjgalindo
  • 856
  • 11
  • 26

1 Answers1

1

You can not run bee command on heroku, because it is a executable program.

But you can run beego app on heroku with adding project dependencies. In order to that you should use tools like https://github.com/kardianos/govendor.

1. After install govendor try following steps in your project folder;

$ govendor init

This command will create ./vendor/vendor.json file in current directory.

{
  "comment": "https://github.com/ismailakbudak/beego-api-example",
  "heroku": {
    "install" : [ "./..." ],
    "goVersion": "go1.11"
  },
  "ignore": "test",
  "package": [],
  "rootPath": "reporting-api"
}

Add heroku tag like above example. There is a information about this configuration on heroku docs in here https://devcenter.heroku.com/articles/go-dependencies-via-govendor#build-configuration

2. After this add beego package dependency with this command

$ govendor fetch github.com/astaxie/beego 

It will download the beego packages to ./vendor directory

3. Lastly you should configure listen ports and beego runmode as prod for heroku in main.go file

To deploy your app without problem, default config must be runmode = prod in conf/app.conf. I tried to set it default as dev and change it from heroku config vars as below, but it compiles packages before the set runmode and gives exception with this message panic: you are running in dev mode.

func main() {
    log.Println("Env $PORT :", os.Getenv("PORT"))
    if os.Getenv("PORT") != "" {
        port, err := strconv.Atoi(os.Getenv("PORT"))
        if err != nil {
            log.Fatal(err)
            log.Fatal("$PORT must be set")
        }
        log.Println("port : ", port)
        beego.BConfig.Listen.HTTPPort = port
        beego.BConfig.Listen.HTTPSPort = port
    }
    if os.Getenv("BEEGO_ENV") != "" {
        log.Println("Env $BEEGO_ENV :", os.Getenv("BEEGO_ENV"))
        beego.BConfig.RunMode = os.Getenv("BEEGO_ENV")
    }

    beego.BConfig.WebConfig.DirectoryIndex = true
    beego.BConfig.WebConfig.StaticDir["/"] = "swagger"

    beego.Run()
}

You can use BEEGO_ENV=dev bee run to continue develop your app without change it again