减少用于Heroku的Rails应用程序的碎片大小



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

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中删除。

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

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

在添加.slugignore文件之前,可能有一些大文件添加到git repo中,现在它们在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文件的大小太大,以至于超过了段塞大小限制。

看起来Heroku可能已经更新了从他们的文档中清除构建缓存https://help.heroku.com/18PI5RSY/how-do-i-clear-the-build-cache

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

首先安装插件:

heroku插件:安装heroku构建然后使用以下命令清除缓存:

heroku构建:缓存:清除-一个示例应用程序缓存将在下次部署时重新生成。如果没有任何要部署的新代码,可以推送一个空提交。

$git-commit—允许空-m";清除高速缓存";$gitpush英雄大师其中,appname被要清除其缓存的应用程序的名称替换。

最新更新