在 Heroku 上使用 Docker 镜像部署包含 Go 应用和 Vue.js 的应用程序
来源:stackoverflow
时间:2024-03-22 11:34:12 356浏览 收藏
本文介绍了在 Heroku 上部署包含 Go 后端和 Vue.js 前端的应用程序的过程。部署时遇到错误,显示“没有运行的网络进程”,无法访问应用程序。原因是应用程序未从环境变量中读取动态端口,导致 Heroku 无法转发连接。本文提供了解决方案,建议在应用程序启动时读取环境变量中的端口值并侦听传入连接。通过将数据库连接和端口字符串更新为从环境变量中读取,并修复 Axios 中的 baseurl 设置,最终解决了该问题,应用程序可以在 Heroku 上成功运行。
我正在尝试使用 docker 映像在 heroku 上部署应用程序 https://github.com/valasek/timesheet。 应用程序有一个 go 后端 (negroni/gorilla) 和前端 vue.js/vuetify.js,并使用 postgresql 持久性。
我陷入部署困境。我不知道如何调试,如何显示命令行输出,什么失败了......以及任何帮助,高度赞赏。
相关 dockerfile - https://github.com/valasek/timesheet/blob/master/dockerfile
以下是我正在执行的步骤:
> docker build --rm -f "Dockerfile" -t timesheet:latest . Successfully tagged timesheet:latest ... > heroku container:push timesheet:latest --app timesheet-cloud ... The push refers to repository [registry.heroku.com/timesheet-cloud/timesheet] ... Your image has been successfully pushed. You can now release it with the 'container:release' command. > heroku container:release timesheet --app timesheet-cloud Releasing images timesheet to timesheet-cloud... done > heroku ps -a timesheet-cloud Free dyno hours quota remaining this month: 971h 8m (97%) Free dyno usage for this app: 0h 0m (0%) For more information on dyno sleeping and how to upgrade, see: https://devcenter.heroku.com/articles/dyno-sleeping No dynos on ⬢ timesheet-cloud > heroku logs --app timesheet-cloud 2019-02-15T08:33:49.373221+00:00 app[api]: Deployed timesheet (709022e100f9) by user@gmail.com 2019-02-15T08:33:49.373221+00:00 app[api]: Release v20 created by user @gmail.com 2019-02-15T08:34:43.901070+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=timesheet-cloud.herokuapp.com request_id=4c21eb79-5344-4d40-b341-8977128c873f fwd="195.250.152.42" dyno= connect= service= status=503 bytes= protocol=https 2019-02-15T08:34:44.842322+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=timesheet-cloud.herokuapp.com request_id=b66caaee-880a-46a0-918b-e778a49334f4 fwd="195.250.152.42" dyno= connect= service= status=503 bytes= protocol=https 2019-02-15T08:34:54.865321+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=timesheet-cloud.herokuapp.com request_id=d5af6aa7-0279-4f0e-a4cc-0f9e8682ec2f fwd="195.250.152.42" dyno= connect= service= status=503 bytes= protocol=https 2019-02-15T08:34:55.158317+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=timesheet-cloud.herokuapp.com request_id=2d69f4b5-9015-48de-9314-c493703818d1 fwd="195.250.152.42" dyno= connect= service= status=503 bytes= protocol=https
解决方案
这很可能发生,因为 heroku 没有检测到您的应用程序的任何端点(默认绑定在端口 3000 上)。
heroku 为您的应用程序分配一个动态端口,并将端口值放在名为 $port
的环境变量中。
您的应用必须使用 heroku 在此变量中指定的值并侦听其上的传入连接,因为这是 heroku 转发连接的位置。
应用程序启动时必须读取该变量: https://help.heroku.com/PPBPA231/how-do-i-use-the-port-environment-variable-in-container-based-apps
您可以使用 heroku run printenv
检查应用程序上的当前环境变量
(我看到你正在使用 viper,它应该处理 env 变量。但是他们在文档中说,当来自 env 时,它区分大小写,也许这可以解释为什么它不适合你:https://github.com/spf13/viper#working-with-environment-variables)
谢谢@jonathan muller。解决了! gui 正在 https://timesheet-cloud.herokuapp.com 上运行。
- 在 heroku db 连接和 port 字符串中应从环境变量中读取
更新为文件 timesheet.yaml。
- axios 中的 baseurl 设置为 '',因此 axios 使用相对 api url,这是可行的。已在文件 axiosSettings.js 中修复。
在命令 heroku run printenv
返回之前:
panic: dial tcp 127.0.0.1:5432: connect: connection refused
现在我得到:
Running printenv on ⬢ timesheet-cloud... up, run.1962 (Free) Feb 15 16:22:34.186 [INFO] config file /timesheet.yaml Feb 15 16:22:34.197 [INFO] connecting to DB postgres://user:[email protected]:5432/dbname Feb 15 16:22:34.246 [INFO] connected to DB postgres://user:[email protected]:5432/dbname
今天带大家了解了的相关知识,希望对你有所帮助;关于Golang的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~
-
502 收藏
-
502 收藏
-
501 收藏
-
501 收藏
-
501 收藏
-
139 收藏
-
204 收藏
-
325 收藏
-
477 收藏
-
486 收藏
-
439 收藏
-
357 收藏
-
352 收藏
-
101 收藏
-
440 收藏
-
212 收藏
-
143 收藏
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 542次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 508次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 497次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 484次学习