减少 Heroku 的 Rails 应用程序的 slug 大小

问题描述 投票:0回答:2

我有一个在 Heroku 上运行的 Rails 应用程序,每次部署时我都会收到警告:

Warning: Your slug size (368 MB) exceeds our soft limit (300 MB) which may affect boot time.

我想要低于 300 MB。所以我运行

du -sh .[^.]* * | sort -hr
返回:

2,1G    .git
176M    node_modules
 79M    vendor
 25M    tmp
5,4M    app
5,1M    public
1,2M    db
420K    test
168K    config
132K    log
116K    package-lock.json
 32K    bin
 12K    lib
 12K    Gemfile.lock
8,0K    dump.rdb
8,0K    .DS_Store
4,0K    package.json
4,0K    config.ru
4,0K    Rakefile
4,0K    README.md
4,0K    Procfile
4,0K    Gemfile
4,0K    .gitignore
  0B    storage

tmp/* 和 log/* 位于我的 .gitignore 中并从 git 中删除。

其他的,如果我加起来的话,不等于 368 MB。这些MB从哪里来?

我知道有一些方法可以减少node_modules等。但首先我想解决上述问题。

ruby-on-rails heroku
2个回答
0
投票

在添加 .slugignore 文件之前,您可能已将一些大文件添加到 git 存储库中,现在它们位于 slug 缓存中或作为 git refs。

您可以使用heroku-repo插件删除缓存

使用命令安装插件

heroku plugins:install heroku-repo

gc

heroku repo:gc -a appname

这将针对应用程序存储库运行

git gc --aggressive
。这是在应用程序的运行进程内完成的。

清除缓存

heroku repo:purge_cache -a appname

这将删除存储在存储库中的构建缓存的内容。这是在应用程序的运行进程内完成的。

按照这些步骤操作后,您可以将代码推送到 Heroku。

如果它不起作用,那么可能是您的

requirements
文件太大,超出了 slug 大小限制。


0
投票

Heroku 似乎已经更新清除构建缓存 - 从他们的文档https://help.heroku.com/18PI5RSY/how-do-i-clear-the-build-cache

清除构建缓存 您可以使用 Heroku Builds 插件清除应用程序的构建缓存:

首先安装插件:

heroku plugins:install heroku-builds

然后使用以下命令清除缓存:

heroku builds:cache:purge -a example-app

缓存将在下次部署时重建。如果您没有任何新代码要部署,您可以推送一个空提交。

$ git commit --allow-empty -m "Purge cache"
$ git push heroku master

其中 appname 替换为您要清除缓存的应用程序的名称。

© www.soinside.com 2019 - 2024. All rights reserved.