Heroku部署中的路径

时间:2017-04-10 15:28:52

标签: heroku go

我正在尝试将测试golang应用程序部署到Heroku:

enter image description here

我的procfile如下所示:

web: todo

但是在运行我的应用时,我收到以下错误:

2017-04-10T15:24:07.128780+00:00 app[web.1]: panic: could not locate box "./static"

我的 main.go 文件包含:

package main

import (
    "net/http"
    "github.com/kitensei/go-todoist/server"
    "github.com/GeertJohan/go.rice"
    "os"
    "log"
    "fmt"
    "path"
    "strconv"
)

var boxPrefix = getenv("BOXPATH", "")

func main() {
    dir, err := os.Getwd()
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println("DIRECTORY CWD: " + dir)
    ex, err := os.Executable()
    if err != nil {
        panic(err)
    }
    exPath := path.Dir(ex)
    fmt.Println("EXECUTABLE PATH: " + exPath)
    exists, err := exists(boxPrefix + "static")
    if err != nil {
        panic(err)
    }
    fmt.Println("CHECK IF (" +boxPrefix + "static) EXISTS: " + strconv.FormatBool(exists))
    server.RegisterHandlers()
    http.Handle("/", http.FileServer(rice.MustFindBox(boxPrefix + "static").HTTPBox()))
    http.ListenAndServe(":8080", nil)
}

func getenv(key, fallback string) string {
    value := os.Getenv(key)
    if len(value) == 0 {
        return fallback
    }
    return value
}

func exists(path string) (bool, error) {
    _, err := os.Stat(path)
    if err == nil {
        return true, nil
    }
    if os.IsNotExist(err) {
        return false, nil
    }
    return true, err
}

有人能给我一个提示吗?

编辑:这是我尝试查找CWD并相应设置框路径时的输出

2017-04-10T17:23:57.000000+00:00 app[api]: Build succeeded
2017-04-10T17:24:06.341977+00:00 heroku[web.1]: Starting process with command `go-todoist`
2017-04-10T17:24:08.592486+00:00 app[web.1]: DIRECTORY CWD: /app
2017-04-10T17:24:08.595689+00:00 app[web.1]: panic: could not locate box "static"
2017-04-10T17:24:08.595691+00:00 app[web.1]:
2017-04-10T17:24:08.595692+00:00 app[web.1]: goroutine 1 [running]:
2017-04-10T17:24:08.595718+00:00 app[web.1]: github.com/kitensei/go-todoist/vendor/github.com/GeertJohan/go%2erice.MustFindBox(0x71e08d, 0x6, 0x0)
2017-04-10T17:24:08.595721+00:00 app[web.1]:    /tmp/tmp.Pa1igbANNl/.go/src/github.com/kitensei/go-todoist/vendor/github.com/GeertJohan/go.rice/box.go:110 +0x94
2017-04-10T17:24:08.595724+00:00 app[web.1]: main.main()
2017-04-10T17:24:08.595741+00:00 app[web.1]:    /tmp/tmp.Pa1igbANNl/.go/src/github.com/kitensei/go-todoist/main.go:21 +0x1a8
2017-04-10T17:24:08.660495+00:00 heroku[web.1]: Process exited with status 2
2017-04-10T17:24:08.685016+00:00 heroku[web.1]: State changed from starting to crashed
2017-04-10T17:24:08.686277+00:00 heroku[web.1]: State changed from crashed to starting
2017-04-10T17:24:09.023202+00:00 heroku[web.1]: Starting process with command `go-todoist`
2017-04-10T17:24:10.743837+00:00 app[web.1]: DIRECTORY CWD: /app
2017-04-10T17:24:10.746355+00:00 app[web.1]: panic: could not locate box "static"
2017-04-10T17:24:10.746357+00:00 app[web.1]:
2017-04-10T17:24:10.746360+00:00 app[web.1]: goroutine 1 [running]:
2017-04-10T17:24:10.746361+00:00 app[web.1]: github.com/kitensei/go-todoist/vendor/github.com/GeertJohan/go%2erice.MustFindBox(0x71e08d, 0x6, 0x0)
2017-04-10T17:24:10.746361+00:00 app[web.1]:    /tmp/tmp.Pa1igbANNl/.go/src/github.com/kitensei/go-todoist/vendor/github.com/GeertJohan/go.rice/box.go:110 +0x94
2017-04-10T17:24:10.746363+00:00 app[web.1]: main.main()
2017-04-10T17:24:10.746367+00:00 app[web.1]:    /tmp/tmp.Pa1igbANNl/.go/src/github.com/kitensei/go-todoist/main.go:21 +0x1a8
2017-04-10T17:24:10.791994+00:00 heroku[web.1]: Process exited with status 2
2017-04-10T17:24:10.817345+00:00 heroku[web.1]: State changed from starting to crashed
vagrant@precise64:/code/src/github.com/kitensei/go-todoist$ heroku run bash -a go-todoist-gpr
/usr/local/heroku/lib/heroku/jsplugin.rb:119: warning: Insecure world writable dir /code/bin in PATH, mode 040777
Running bash on ⬢ go-todoist-gpr... up, run.9334 (Free)
~ $ cd /app
~ $ pwd
/app
~ $ ls -lA
total 48
-rw------- 1 u52460 dyno  289 Apr 10 17:23 .gitignore
drwx------ 3 u52460 dyno 4096 Apr 10 17:24 .heroku
drwx------ 2 u52460 dyno 4096 Apr 10 17:24 .profile.d
-rw------- 1 u52460 dyno   15 Apr 10 17:24 Procfile
-rw------- 1 u52460 dyno   26 Apr 10 17:23 README.md
-rw------- 1 u52460 dyno  326 Apr 10 17:23 app.json
drwx------ 2 u52460 dyno 4096 Apr 10 17:24 bin
-rw------- 1 u52460 dyno  592 Apr 10 17:23 main.go
drwx------ 2 u52460 dyno 4096 Apr 10 17:23 server
drwx------ 3 u52460 dyno 4096 Apr 10 17:23 static
drwx------ 2 u52460 dyno 4096 Apr 10 17:23 task
drwx------ 3 u52460 dyno 4096 Apr 10 17:23 vendor
~ $

尝试在Heroku bash上运行应用程序:

~ $ go-todoist
DIRECTORY CWD: /app
EXECUTABLE PATH: /app/bin
CHECK IF (static) EXISTS: true
panic: could not locate box "static"

goroutine 1 [running]:
github.com/kitensei/go-todoist/vendor/github.com/GeertJohan/go%2erice.MustFindBox(0xc4200f0cf0, 0xb, 0x5)
        /tmp/tmp.FmcU3dgw8Y/.go/src/github.com/kitensei/go-todoist/vendor/github.com/GeertJohan/go.rice/box.go:110 +0x94
main.main()
        /tmp/tmp.FmcU3dgw8Y/.go/src/github.com/kitensei/go-todoist/main.go:34 +0x42c

绝对路径相同:

~ $ go-todoist
DIRECTORY CWD: /app
EXECUTABLE PATH: /app/bin
CHECK IF (/app/static) EXISTS: true
panic: given name/path is absolute

goroutine 1 [running]:
github.com/kitensei/go-todoist/vendor/github.com/GeertJohan/go%2erice.MustFindBox(0xc4200f0cf0, 0xb, 0x5)
        /tmp/tmp.FmcU3dgw8Y/.go/src/github.com/kitensei/go-todoist/vendor/github.com/GeertJohan/go.rice/box.go:110 +0x94
main.main()
        /tmp/tmp.FmcU3dgw8Y/.go/src/github.com/kitensei/go-todoist/main.go:34 +0x42c

0 个答案:

没有答案