英文:
Deploying Go app to heroku error
问题
我将代码文件结构重构为cmd文件夹下,因为我现在添加了一个worker,所以它的结构如下:
所有的go文件都在文件夹中,所以为了在本地安装它,我使用'make install'命令,我配置了它来'go install'每个包。
但是当我尝试推送到Heroku时,它只运行'go install',所以我得到以下错误:
> Running: go install -v -tags heroku . can't load package: package
> github.com/heroku/secretly-sender: no buildable Go source files in
> /tmp/tmp.pTW8NahxGm/.go/src/github.com/heroku/secretly-sender
我该如何解决这个问题?
这是我的其他文件:
Procfile:
web: secretly-sender-web
worker: secretly-sender-worker
Dockerfile:
FROM alpine:latest
WORKDIR "/opt"
ADD .docker_build/secretly-sender /opt/bin/secretly-sender/cmd
ADD ./templates /opt/templates
ADD ./static /opt/static
CMD ["/opt/bin/secretly-sender/cmd"]
Makefile:
GO_BUILD_ENV := GOOS=linux GOARCH=amd64
DOCKER_BUILD=$(shell pwd)/.docker_build
DOCKER_CMD=$(DOCKER_BUILD)/secretly-sender/cmd
$(DOCKER_CMD): clean
mkdir -p $(DOCKER_BUILD)
$(GO_BUILD_ENV) go build -v -o $(DOCKER_CMD) .
clean:
rm -rf $(DOCKER_BUILD)
heroku: $(DOCKER_CMD)
heroku container:push web
heroku container:push worker
install:
go install github.com/heroku/secretly-sender/cmd/secretly-sender-web
go install github.com/heroku/secretly-sender/cmd/secretly-sender-worker
go install github.com/heroku/secretly-sender/shared
build:
go build github.com/heroku/secretly-sender/cmd/secretly-sender-web
go build github.com/heroku/secretly-sender/cmd/secretly-sender-worker
go build github.com/heroku/secretly-sender/shared
我真的不理解这些文件和路径的含义,所以我仍然无法解决我的问题。
非常感谢!
英文:
I refactored my code file structure to be under the cmd folder since I now added a worker and now it has this structure:
All the go files are inside the folders so in order to install it locally I use 'make install' which I configured to go install each package.
But when I try to push to Heroku it just runs go install and so I get the error:
> Running: go install -v -tags heroku . can't load package: package
> github.com/heroku/secretly-sender: no buildable Go source files in
> /tmp/tmp.pTW8NahxGm/.go/src/github.com/heroku/secretly-sender
How can I fix this?
Here are my other files
Procfile:
web: secretly-sender-web
worker: secretly-sender-worker
Dockerfile:
FROM alpine:latest
WORKDIR "/opt"
ADD .docker_build/secretly-sender /opt/bin/secretly-sender/cmd
ADD ./templates /opt/templates
ADD ./static /opt/static
CMD ["/opt/bin/secretly-sender/cmd"]
Makefile
GO_BUILD_ENV := GOOS=linux GOARCH=amd64
DOCKER_BUILD=$(shell pwd)/.docker_build
DOCKER_CMD=$(DOCKER_BUILD)/secretly-sender/cmd
$(DOCKER_CMD): clean
mkdir -p $(DOCKER_BUILD)
$(GO_BUILD_ENV) go build -v -o $(DOCKER_CMD) .
clean:
rm -rf $(DOCKER_BUILD)
heroku: $(DOCKER_CMD)
heroku container:push web
heroku container:push worker
install:
go install github.com/heroku/secretly-sender/cmd/secretly-sender-web
go install github.com/heroku/secretly-sender/cmd/secretly-sender-worker
go install github.com/heroku/secretly-sender/shared
build:
go build github.com/heroku/secretly-sender/cmd/secretly-sender-web
go build github.com/heroku/secretly-sender/cmd/secretly-sender-worker
go build github.com/heroku/secretly-sender/shared
I don't really understand what these files and path mean so I still couldn't solve my issue
Thank you very much!
答案1
得分: 1
答案是添加以下内容:
"heroku": {
"install": [
"./cmd/..."
]
},
到 vendor/vendor.json 文件中
英文:
The answer was to add this:
"heroku": {
"install": [
"./cmd/..."
]
},
to vendor/vendor.json
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论