duanjieyi6582 2017-04-10 15:28
浏览 94

Heroku部署中的路径

I am trying to deploy a test golang app to Heroku:

enter image description here

My procfile looks like this:

web: todo

But when running my app I get the following error:

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

My main.go file contains:

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
}

Can someone give me an hint ?

EDIT: Here the output when I try to find the CWD and set the box path accordingly

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
~ $

Trying to run the app on the 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

The same with an absolute path:

~ $ 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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?