我正在Docker映像中的AWS Elastic Beanstalk(EB)中运行Sails.js应用程序。我的工作流程是在本地构建Docker映像,推送到ECR,然后部署我的AWS配置(例如:Dockerrun.aws.json
和Nginx的其他配置)。我的应用程序是用于测试不同技术集成的POC,所以是的,我现在正在使用MemoryStore,但是我主要遵循Deployment Guide
在本地运行我的Docker映像(通过将NODE_ENV
设置为production
在生产模式下),容器/应用程序可以正常运行并可以使用。我构建了一个模仿EB反向代理的Nginx映像,以便可以在本地测试SSL终止,安全cookie等(使用docker-compose将所有内容捆绑在一起),而且一切都很好。
但是,当我部署到EB时,我的容器/应用需要很长时间才能启动。拉出我看到的日志:
debug: Please note: since `sails.config.session.cookie.secure` is set to `true`, the session cookie
debug: will _only_ be sent over TLS connections (i.e. secure https:// requests).
debug: Requests made via http:// will not include a session cookie!
debug:
debug: For more help:
debug: • https://sailsjs.com/config/session#?the-secure-flag
debug: • https://sailsjs.com/config/session#?do-i-need-an-ssl-certificate
debug: • https://sailsjs.com/config/sails-config-http#?properties
debug: • https://sailsjs.com/support
debug:
Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
[33mwarn[39m: The default `sails-disk` adapter is not designed for use as a production database.
[33mwarn[39m: Instead, please use another adapter like sails-postgresql or sails-mongo.
[33mwarn[39m: For more info, see: http://sailsjs.com/docs/concepts/deployment
[33mwarn[39m: To hide this warning message, enable `sails.config.orm.skipProductionWarnings`.
[33mwarn[39m: [?] If you're unsure, see https://sailsjs.com/support
[31merror[39m: Failed to lift app:
... repeats the above ~30 times
debug: Please note: since `sails.config.session.cookie.secure` is set to `true`, the session cookie
debug: will _only_ be sent over TLS connections (i.e. secure https:// requests).
debug: Requests made via http:// will not include a session cookie!
debug:
debug: For more help:
debug: • https://sailsjs.com/config/session#?the-secure-flag
debug: • https://sailsjs.com/config/session#?do-i-need-an-ssl-certificate
debug: • https://sailsjs.com/config/sails-config-http#?properties
debug: • https://sailsjs.com/support
debug:
Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
[33mwarn[39m: The default `sails-disk` adapter is not designed for use as a production database.
[33mwarn[39m: Instead, please use another adapter like sails-postgresql or sails-mongo.
[33mwarn[39m: For more info, see: http://sailsjs.com/docs/concepts/deployment
[33mwarn[39m: To hide this warning message, enable `sails.config.orm.skipProductionWarnings`.
[33mwarn[39m: [?] If you're unsure, see https://sailsjs.com/support
[32minfo[39m:
[32minfo[39m: .-..-.
[32minfo[39m:
[32minfo[39m: Sails <| .-..-.
[32minfo[39m: v1.2.2 |\
[32minfo[39m: /|.\
[32minfo[39m: / || \
[32minfo[39m: ,' |' \
[32minfo[39m: .-'.-==|/_--'
[32minfo[39m: `--'-------'
[32minfo[39m: __---___--___---___--___---___--___
[32minfo[39m: ____---___--___---___--___---___--___-__
[32minfo[39m:
[32minfo[39m: Server lifted in `/usr/src/app`
[32minfo[39m: To shut down Sails, press <CTRL> + C at any time.
[32minfo[39m: Read more at https://sailsjs.com/support.
[34mdebug[39m: -------------------------------------------------------
[34mdebug[39m: :: Thu Sep 05 2019 06:22:35 GMT+0000 (Coordinated Universal Time)
[34mdebug[39m: Environment : production
[34mdebug[39m: Port : 1337
[34mdebug[39m: -------------------------------------------------------
鉴于使用Docker,我不知道为什么我在EB的日志中得到[31merror[39m: Failed to lift app:
而不是在本地。我应该拉的容器中是否有任何日志(我是Sails的新手,但我认为它可以将所有内容打印到控制台)?
我想知道这是否与生产模式的资产建设有关,该生产方式以某种方式导致错误。有没有办法预编译资产?然后,我可以在构建映像时运行命令,这将节省将映像/容器部署到EB盒中的时间。
更新:
自升级到sails@1.2.3
以来,我遇到了更多有用的错误
2019-09-14T11:17:29.226Z warn: [?] If you're unsure, see https://sailsjs.com/support
2019-09-14T11:19:29.084Z error: Failed to lift app:Sails is taking too long to load.
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Troubleshooting tips:
-• Were you still reading/responding to an interactive prompt?
(Whoops, sorry! Please lift again and try to respond a bit more quickly.)
-• Do you have a lot of stuff in `assets/`? Grunt might still be running.
(Try increasing the hook timeout. Currently it is 300000.
e.g. `sails lift --hookTimeout=600000`)
-• Is `grunt` a custom or 3rd party hook?
(*If* `initialize()` is using a callback, make sure it's being called.)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
我通过添加config/env/production.js
hookTimeout: 300000
中的挂接超时时间
我假设超时以毫秒为单位,因此我将超时设置为5分钟。但是,根据新日志,Sails仅等待2分钟。我是否正确增加了超时时间?
更新:
我怀疑资产建设有贡献。作为构建Docker映像的一部分,我通过预编译资产将启动时间从6分钟以上减少到了3分钟。
tasks/register/prod.js
复制到tasks/register/docker-prod.js
(或任何您想要的文件),然后重命名任务以匹配文件名(例如:docker-prod
)tasks/register/prod.js
以包含// don't build assets as part of running prod; 'docker-prod' instead
grunt.registerTask('prod', []);
Dockerfile
# Build the assets for Docker
RUN ./node_modules/.bin/grunt docker-prod