I have a Rails app running on Heroku and on every deploy I get a warning:
Warning: Your slug size (368 MB) exceeds our soft limit (300 MB) which may affect boot time.
I want to get under 300 MB. So I ran du -sh .[^.]* * | sort -hr which returned:
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/* and log/* are in my .gitignore and removed from git.
The others, if I sum them up don't equal 368 MB. Where are those MB coming from?
I know that there are ways to reduce the node_modules etc. but first I would like to solve the issue above.
It's possible that before you added the .slugignore file you had some large files added to the git repo and now they are in the slug cache or as git refs.
You can remove the cache using the heroku-repo plugin
Install the plugin using the command
heroku plugins:install heroku-repo
gc
heroku repo:gc -a appname
This will run a git gc --aggressive against the applications repo. This is done inside a run process on the application.
purge-cache
heroku repo:purge_cache -a appname
This will delete the contents of the build cache stored in the repository. This is done inside a run process on the application.
After following these steps you may push your code to the Heroku.
If it does not work then maybe your requirements files are large in size such that it crosses the slug size limit.
Seems like Heroku may have updated clearing the build cache - from their docs https://help.heroku.com/18PI5RSY/how-do-i-clear-the-build-cache
Clear The Build Cache
You can clear the build cache for an app by using the Heroku Builds plugin:
First install the plugin:
heroku plugins:install heroku-builds
Then use the following command to clear the cache:
heroku builds:cache:purge -a example-app
The cache will be rebuilt on the next deploy. If you do not have any new code to deploy, you can push an empty commit.
$ git commit --allow-empty -m "Purge cache"
$ git push heroku master
Where appname is replaced by the name of the app you want to clear the cache for.
Related
When using eb CLI
eb init
eb create
i get an error:
ERROR: [Instance: i-003165df12360a5c4] Command failed on instance. Return code: 1 Output: Dockerfile and Dockerrun.aws.json are both missing, abort deployment.
It seems like the ZIP file sent to the S3 indeed only contains README.md file. but the local folder does contain the Dockerfile and
eb local run
seems to work fine.
Any ideas?
Answer: It's because the Dockerfile wasn't committed. (By default the EB CLI deploys the latest commit in the current branch).
I had the same problem, and figured out the reason after reading your question and answer. You probable had a new git repo with only a readme file. Once you deleted the .git directory, the EB CLI no longer treated your directory as a git repo.
Seems to be solved.
After removing ".git" folder "eb create" worked.
Seems like a bug in elastic beanstalk as i don't see why the existents of a subfolder should prevent eb from zipping the files in the directory...
I have an app that i am working on that i did not set up and i don't have communication with the dev's that did. I have pushed up to it in the past but today for some reason i was not able to. Rails 4 with capistrano. When i looked at the app directory on the server i could find the .gitignore but no .git folder. I did a "git init && git remote add git_ssh_url" but it didn't work. I was thinking about a git clone but i have no clue what that will do to the app. The app is used daily at a company and i'm sure they wouldn't like me screwing it up :) I'm at a loss, Any help is appreciated.
**
Edit
**
So i realized that there is a staging server set up on the same droplet as well and the code to deploy to each is nearly identical. I had no problems updating the staging server
Here is the error code:
refreshing local cache to revision 4ea064e4826a9880c6bac3e0a2689b688e223911 at /var/folders/qb/6fdgzljs1r9ddgkvqk1ky0y40000gn/T/mpm
executing locally: cd /var/folders/qb/6fdgzljs1r9ddgkvqk1ky0y40000gn/T/mpm && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard 4ea064e4826a9880c6bac3e0a2689b688e223911 && git clean -q -d -x -f
fatal: Not a git repository (or any of the parent directories): .git
command finished in 9ms
shell command failed with return code pid 97172 exit 128
So the solution i came across while asking a friend was that somehow the temp cache file that capistrano creates locally here (this path was pulled form the error that i posted above) :
/var/folders/qb/6fdgzljs1r9ddgkvqk1ky0y40000gn/T/mpm
was throwing the error. At some point there must have been an interrupted deploy that messed up that file. When i ls -la the mpm file above there was a .git file but for whatever reason it wasn't recognized.
The solution was to
rm -rf /var/folders/qb/6fdgzljs1r9ddgkvqk1ky0y40000gn/T/mpm
and rerun the cap production deploy command and it rebuilds the temp cache file and deploys the code.
Hope this helps someone!
On my production server, which is hosted on digital ocean, if that helps, Ubuntu 12.04, I have RoR 4 and rake 10.1.1.
When I deploy, I run rake assets:precompile, and I've noticed a strange issue where if I have a rails console session open when I do this, I get the following output
~# rake assets:precompile
~# Killed
It's mainly annoying, but the reason I want it resolved is when hiring new developers, there will be deploy/console conflict nightmare.
Thanks,
Brian
Your precompile process is probably being killed because you are running out of RAM. You can confirm this by running top in another ssh session. To fix this, create a swap file that will be used when RAM is full.
Create SWAP Space on Ubuntu
You will probably end up needing some swap space if you plan on using Rails on Digital Ocean 512MB RAM droplet. Specifically, you will run out of RAM when compiling the assets resulting in the process being quietly killed and preventing successful deployments.
To see if you have a swap files:
sudo swapon -s
No swap file shown? Check how much disk space space you have:
df
To create a swap file:
Step 1: Allocate a file for swap
sudo fallocate -l 2048m /mnt/swap_file.swap
Step 2: Change permission
sudo chmod 600 /mnt/swap_file.swap
Step 3: Format the file for swapping device
sudo mkswap /mnt/swap_file.swap
Step 4: Enable the swap
sudo swapon /mnt/swap_file.swap
Step 5: Make sure the swap is mounted when you Reboot. First, open fstab
sudo nano /etc/fstab
Finally, add entry in fstab (only if it wasn't automatically added)
# /etc/fstab
/mnt/swap_file.swap none swap sw 0 0
Save and exit. You're done adding swap. Now your rake assets:precompile should complete without being killed.
Rake assets:precompile is a memory eating process.
So make sure you have enough RAM before using that command
I have an opsworks stack on aws and I'd to change my instance type.
I was using t1.micro and i just changed it to t1.small
Thanks a lot.
This uses a lot of RAM. To check how much available RAM memory you have free, use the command
free -m
This will show the available RAM in MB
A temporary solution would be to create a swap space.
I was going to add this as a comment to Jason R post above before you go into his steps, just to make sure it is a RAM resource issue.
you could also run
echo {1,2,3} > /proc/sys/vm/drop_caches
to clean up the cache memory, but it probably will not free up enough.
This might help someone. For me, since i couldn't use 'fallocate' command, i had to do:
sudo dd if=/dev/zero of=/mnt/4GB.swap bs=4096 count=1048576
sudo chmod 600 /mnt/4GBB.swap
sudo mkswap /mnt/4GB.swap
sudo swapon /mnt/4GB.swap
I am storing some .dat files in the public folder of my rails app on heroku. However, I cannot display those files in the heroku bash.
Notice the "total 4" in the ls -l result
~/public/files $ ls
README.txt
~/public/files $ ls -a
. .. README.txt
~/public/files $ ls -l
total 4
-rw------- 1 u5517 5517 25 2013-04-13 23:35 README.txt
So I know they are there, they are just not being shown. I need to be able to look at them to verify my app is working correctly.
Thanks.
Heroku dynos have ephemeral file systems, so if you are writing files in your web process, they will not be available to other dynos, including one created from a heroku run bash session. Please also remember that dynos are restarted at least every 24 hours, so unless these are just temp files, it would be better to put the file somewhere like S3 that has long-term persistance and can be accessed by all your dynos.
Here a step of installation in heroku web hosting website:
Track your application with Git
If you’re already using Git with your application, skip to the next step. If you’re not yet using Git to track your application, run this:
$ cd PATH/TO/MY_APP
$ git init
Initialized empty Git repository in .git/
$ git add .
$ git commit -m "new app"
Created initial commit 5df2d09: new app
44 files changed, 8393 insertions(+), 0 deletions(-)
when I cd to the PATH/TO/MY_APP
there's no such dictionary, So I guess it's a custom path which should add to the user path file manually, Is that right?
It means path to your app, so if your app is in /usr/bin/myapp, than it is "/usr/bin/myapp".