加速Heroku上的部署[重复]

时间:2022-04-30 02:43:10

This question already has an answer here:

这个问题在这里已有答案:

Heroku is great. But every time I deploy, Heroku seems to like to redownload and rebuild all the packages. With socket.io and mailparser this is taking around 3 minutes.

Heroku很棒。但每次部署时,Heroku似乎都想重新下载并重建所有软件包。使用socket.io和mailparser大约需要3分钟。

Is there a way to speed up the deployment process? Is there a way to tell Heroku that it can cache these items? Or can I upload prebuilt node_modules?

有没有办法加快部署过程?有没有办法告诉Heroku它可以缓存这些项目?或者我可以上传预构建的node_modules吗?

6 个解决方案

#1


8  

It seems like as of today Heroku is finally caching the node_modules folder!

好像今天Heroku终于缓存了node_modules文件夹!

-----> Deleting 6 files matching .slugignore patterns.

----->删除匹配.slugignore模式的6个文件。

-----> Node.js app detected

----->检测到Node.js应用程序

-----> Requested node range: 0.10.x

----->请求的节点范围:0.10.x

-----> Resolved node version: 0.10.22

----->已解决的节点版本:0.10.22

-----> Downloading and installing node

----->下载并安装节点

-----> Restoring node_modules from cache

----->从缓存中恢复node_modules

-----> Installing dependencies

----->安装依赖项

-----> Pruning unused dependencies

----->修剪未使用的依赖项

-----> Caching node_modules directory for future builds

----->缓存node_modules目录以供将来构建

-----> Cleaning up node-gyp and npm artifacts

----->清理node-gyp和npm工件

Build time is like 3 seconds for me now.

对我来说,构建时间就像3秒钟。

#2


1  

One thing I did to speed up process was to add .slugignore file to the main folder and add all the files and folders I did not want to run the app.

我加快进程的一件事是将.slugignore文件添加到主文件夹并添加我不想运行应用程序的所有文件和文件夹。

Sample content of .slugignore file:
working
mockups
*.psd
*.pdf

.slugignore文件的示例内容:工作模型* .psd * .pdf

#3


1  

I had the same question (see Avoid npm refresh after every deployment on Heroku).

我有同样的问题(请参阅Heroku上的每次部署后避免npm刷新)。

Heroku forces a download/build/etc. sequence because they need to start an app with a 'blank slate': to clean previous undeleted files, when they move your app to another server, when you assign new web dynos, etc.

Heroku强制下载/构建/等。序列,因为他们需要启动一个带有“空白平板”的应用程序:清理以前未删除的文件,将应用程序移动到另一台服务器,分配新的网络动态时等。

The issue is clearly with native packages, and recompilation. For all js-only packages, I commit them with my project, and remove them from package.json. It gains a few seconds, but not that much.

问题显然是本机包和重新编译。对于所有仅限js的包,我使用我的项目提交它们,并从package.json中删除它们。它会增加几秒钟,但不会那么多。

I should definitely be possible to pre-compile and commit native modules (I successfully run wkhtml2pdf on Heroku, for instance, with a binary compiled for linux-amd64), if you get access to a Linux box (or VM) with the same configuration - as of today, Linux [...] 2.6.32-350-ec2 #57-Ubuntu SMP [...] x86_64 GNU/Linux.

我绝对可以预编译和提交本机模块(我在Heroku上成功运行wkhtml2pdf,例如,使用为linux-amd64编译的二进制文件),如果你可以访问具有相同配置的Linux机器(或VM) - 截至今日,Linux [...] 2.6.32-350-ec2#57-Ubuntu SMP [...] x86_64 GNU / Linux。

Though I would not recommend it as a definitive solution, since it is likely to break some day - It does not seem to me that heroku guarantees the platform an app runs onto.

虽然我不推荐它作为一个明确的解决方案,因为它可能会在某一天中断 - 我认为heroku不会保证应用程序运行的平台。

#4


1  

I'm running into the same problem.

我遇到了同样的问题。

Some discussion here about caching the node_modules folder: https://github.com/heroku/heroku-buildpack-nodejs/pull/37

这里有一些关于缓存node_modules文件夹的讨论:https://github.com/heroku/heroku-buildpack-nodejs/pull/37

Another idea: https://github.com/heroku/heroku-buildpack-nodejs/issues/25

另一个想法:https://github.com/heroku/heroku-buildpack-nodejs/issues/25


I'm thinking about a few solutions right now.

我现在正在考虑一些解决方案。

  1. Check in node_modules in a separate branch: The core Node.js maintainers actually recommend checking in the node_modules folder into source control (for apps, not libs). I don't like this. A way to get around it though might be to have a separate production branch with a different .gitignore file that doesn't ignore node_modules. When you want to deploy, just do a rebase from your master and node_modules will be checked in. At least this keeps your master branch free from dependencies.

    检查单独分支中的node_modules:核心Node.js维护者实际上建议将node_modules文件夹签入源代码控制(对于应用程序,而不是库)。我不喜欢这个。绕过它的方法可能是使用不同的.gitignore文件的单独生产分支,该文件不会忽略node_modules。当您想要部署时,只需从主服务器执行rebase,并且将检入node_modules。至少这样可以使主分支免于依赖。

  2. Add a preinstall script to package.json to download compressed dependency zip: You could also add a pre-push git hook to bundle up your dependencies and upload them to S3. This would probably be too slow though.

    将一个预安装脚本添加到package.json以下载压缩的依赖zip:您还可以添加一个pre-push git hook来捆绑您的依赖项并将它们上传到S3。但这可能太慢了。

  3. Modify the heroku-buildpack-nodejs: Integrate the outstanding pull request with node_modules caching:

    修改heroku-buildpack-nodejs:将未完成的pull请求与node_modules缓存集成:

    heroku config:set BUILDPACK_URL=https://github.com/opdemand/buildpack-nodejs.git

    heroku config:设置BUILDPACK_URL = https://github.com/opdemand/buildpack-nodejs.git

#5


1  

Seems like there has recently been progress at the heroku-buildpack-nodejs.

好像最近在heroku-buildpack-nodejs上取得了进展。

Once the pull request is merged, you can add

合并拉取请求后,您可以添加

heroku config:set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-nodejs

heroku config:set BUILDPACK_URL = https://github.com/heroku/heroku-buildpack-nodejs

to your heroku environment variables.

你的heroku环境变量。

For now, David Dollar's forked repository is available at

目前,David Dollar的分叉存储库可以在

https://github.com/ddollar/heroku-buildpack-nodejs

https://github.com/ddollar/heroku-buildpack-nodejs

With this as your BUILDPACK_URL it should cache the npm modules. I tried it with node.js 0.10.5a, npm version: 1.3.5 and npm_modules in .gitignore. Tt seems to work fine so far!

将此作为您的BUILDPACK_URL,它应该缓存npm模块。我尝试使用node.js 0.10.5a,npm version:1.3.5和.gitignore中的npm_modules。到目前为止似乎工作正常!

#6


1  

Check out this branch of the new Heroku Node.js buildpack, now in beta, which supports node_modules caching between builds:

查看新的Heroku Node.js buildpack的这个分支,现在处于测试阶段,它支持构建之间的node_modules缓存:

https://github.com/heroku/heroku-buildpack-nodejs/tree/diet

https://github.com/heroku/heroku-buildpack-nodejs/tree/diet

To use it:

要使用它:

heroku config:set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-nodejs#diet -a my-node-app
git commit -am "fakeout" --allow-empty
git push heroku

#1


8  

It seems like as of today Heroku is finally caching the node_modules folder!

好像今天Heroku终于缓存了node_modules文件夹!

-----> Deleting 6 files matching .slugignore patterns.

----->删除匹配.slugignore模式的6个文件。

-----> Node.js app detected

----->检测到Node.js应用程序

-----> Requested node range: 0.10.x

----->请求的节点范围:0.10.x

-----> Resolved node version: 0.10.22

----->已解决的节点版本:0.10.22

-----> Downloading and installing node

----->下载并安装节点

-----> Restoring node_modules from cache

----->从缓存中恢复node_modules

-----> Installing dependencies

----->安装依赖项

-----> Pruning unused dependencies

----->修剪未使用的依赖项

-----> Caching node_modules directory for future builds

----->缓存node_modules目录以供将来构建

-----> Cleaning up node-gyp and npm artifacts

----->清理node-gyp和npm工件

Build time is like 3 seconds for me now.

对我来说,构建时间就像3秒钟。

#2


1  

One thing I did to speed up process was to add .slugignore file to the main folder and add all the files and folders I did not want to run the app.

我加快进程的一件事是将.slugignore文件添加到主文件夹并添加我不想运行应用程序的所有文件和文件夹。

Sample content of .slugignore file:
working
mockups
*.psd
*.pdf

.slugignore文件的示例内容:工作模型* .psd * .pdf

#3


1  

I had the same question (see Avoid npm refresh after every deployment on Heroku).

我有同样的问题(请参阅Heroku上的每次部署后避免npm刷新)。

Heroku forces a download/build/etc. sequence because they need to start an app with a 'blank slate': to clean previous undeleted files, when they move your app to another server, when you assign new web dynos, etc.

Heroku强制下载/构建/等。序列,因为他们需要启动一个带有“空白平板”的应用程序:清理以前未删除的文件,将应用程序移动到另一台服务器,分配新的网络动态时等。

The issue is clearly with native packages, and recompilation. For all js-only packages, I commit them with my project, and remove them from package.json. It gains a few seconds, but not that much.

问题显然是本机包和重新编译。对于所有仅限js的包,我使用我的项目提交它们,并从package.json中删除它们。它会增加几秒钟,但不会那么多。

I should definitely be possible to pre-compile and commit native modules (I successfully run wkhtml2pdf on Heroku, for instance, with a binary compiled for linux-amd64), if you get access to a Linux box (or VM) with the same configuration - as of today, Linux [...] 2.6.32-350-ec2 #57-Ubuntu SMP [...] x86_64 GNU/Linux.

我绝对可以预编译和提交本机模块(我在Heroku上成功运行wkhtml2pdf,例如,使用为linux-amd64编译的二进制文件),如果你可以访问具有相同配置的Linux机器(或VM) - 截至今日,Linux [...] 2.6.32-350-ec2#57-Ubuntu SMP [...] x86_64 GNU / Linux。

Though I would not recommend it as a definitive solution, since it is likely to break some day - It does not seem to me that heroku guarantees the platform an app runs onto.

虽然我不推荐它作为一个明确的解决方案,因为它可能会在某一天中断 - 我认为heroku不会保证应用程序运行的平台。

#4


1  

I'm running into the same problem.

我遇到了同样的问题。

Some discussion here about caching the node_modules folder: https://github.com/heroku/heroku-buildpack-nodejs/pull/37

这里有一些关于缓存node_modules文件夹的讨论:https://github.com/heroku/heroku-buildpack-nodejs/pull/37

Another idea: https://github.com/heroku/heroku-buildpack-nodejs/issues/25

另一个想法:https://github.com/heroku/heroku-buildpack-nodejs/issues/25


I'm thinking about a few solutions right now.

我现在正在考虑一些解决方案。

  1. Check in node_modules in a separate branch: The core Node.js maintainers actually recommend checking in the node_modules folder into source control (for apps, not libs). I don't like this. A way to get around it though might be to have a separate production branch with a different .gitignore file that doesn't ignore node_modules. When you want to deploy, just do a rebase from your master and node_modules will be checked in. At least this keeps your master branch free from dependencies.

    检查单独分支中的node_modules:核心Node.js维护者实际上建议将node_modules文件夹签入源代码控制(对于应用程序,而不是库)。我不喜欢这个。绕过它的方法可能是使用不同的.gitignore文件的单独生产分支,该文件不会忽略node_modules。当您想要部署时,只需从主服务器执行rebase,并且将检入node_modules。至少这样可以使主分支免于依赖。

  2. Add a preinstall script to package.json to download compressed dependency zip: You could also add a pre-push git hook to bundle up your dependencies and upload them to S3. This would probably be too slow though.

    将一个预安装脚本添加到package.json以下载压缩的依赖zip:您还可以添加一个pre-push git hook来捆绑您的依赖项并将它们上传到S3。但这可能太慢了。

  3. Modify the heroku-buildpack-nodejs: Integrate the outstanding pull request with node_modules caching:

    修改heroku-buildpack-nodejs:将未完成的pull请求与node_modules缓存集成:

    heroku config:set BUILDPACK_URL=https://github.com/opdemand/buildpack-nodejs.git

    heroku config:设置BUILDPACK_URL = https://github.com/opdemand/buildpack-nodejs.git

#5


1  

Seems like there has recently been progress at the heroku-buildpack-nodejs.

好像最近在heroku-buildpack-nodejs上取得了进展。

Once the pull request is merged, you can add

合并拉取请求后,您可以添加

heroku config:set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-nodejs

heroku config:set BUILDPACK_URL = https://github.com/heroku/heroku-buildpack-nodejs

to your heroku environment variables.

你的heroku环境变量。

For now, David Dollar's forked repository is available at

目前,David Dollar的分叉存储库可以在

https://github.com/ddollar/heroku-buildpack-nodejs

https://github.com/ddollar/heroku-buildpack-nodejs

With this as your BUILDPACK_URL it should cache the npm modules. I tried it with node.js 0.10.5a, npm version: 1.3.5 and npm_modules in .gitignore. Tt seems to work fine so far!

将此作为您的BUILDPACK_URL,它应该缓存npm模块。我尝试使用node.js 0.10.5a,npm version:1.3.5和.gitignore中的npm_modules。到目前为止似乎工作正常!

#6


1  

Check out this branch of the new Heroku Node.js buildpack, now in beta, which supports node_modules caching between builds:

查看新的Heroku Node.js buildpack的这个分支,现在处于测试阶段,它支持构建之间的node_modules缓存:

https://github.com/heroku/heroku-buildpack-nodejs/tree/diet

https://github.com/heroku/heroku-buildpack-nodejs/tree/diet

To use it:

要使用它:

heroku config:set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-nodejs#diet -a my-node-app
git commit -am "fakeout" --allow-empty
git push heroku