Images in public folder are not updated while deploying on Heroku - ruby-on-rails-4

I have a strange issue while deploying to Heroku.
Since a few days ago, it seems that when I deploy, my modified images are not updated on Heroku.
The process is this one :
I modify the image (like the size)
I commit the modification
I push on Heroku
I try to load the image -> not updated
I run heroku run bash to witness the file on public/ folder -> not updated, still with the old size
As with this answer, git ls-files public -o shows nothing out of place
I checked on github, my file is well updated in my repo -> not a git problem
I duplicated an image an named it diferently : it is loaded on the repo. I then deleted it : still on the repo.
So I guess it's a cache issue. Therefore I tried this answer to purge the assetscache... with no luck.

Run the command:
heroku run rake assets:clean
If it doesn't work, then run the following command:
heroku run rake assets:precompile

Related

Why is Procfile not recognised by Heroku?

I'm trying to deploy a flask app to heroku, but I keep on getting the error:
Scaling dynos... ! ▸ Couldn't find that process type (web).
whenever I try to run heroku ps:scale web=1.
However, when I run heroku ps:scale, it tells me that I need to Upload a Procfile to add process types.
I do have a Procfile located in my root directory, and it is capitalised and doesn't have any file extensions. I have tried deleting and recreating the Procfile, but this hasn't produced any results.
How do I get Heroku to recognise my Procfile?
Here is what I've been trying to do:
ubuntu terminal
I had to create a new git repo and heroku app, and copy the code over for it to work.

Heroku git push Django migration failure for DuplicateTable

Background
Migrating a Django app from Digital Ocean to Heroku. I had problems migrating the data, so I used pg_dump to get the schema and the data of each table. Then ran those scripts in heroku. I loaded my website and I can see the new data coming through.
Problem
Now when I push new code with the Heroku CLI that auto runs the deployment, it fails for this reason: psycopg2.errors.DuplicateTable: relation "django_content_type" already exists
The commands I run are
git add .
git commit -m "some message"
git push heroku master"
The Procfile has release: python manage.py migrate which runs the commands, which I thought about taking it out but when I have migrations to run in the future this will cause an issue.
Any thoughts?
This sent me down a rabbit hole this morning, and I figured it out. I am going to leave the question up since I could not find a similar one.
The issue came down to migrations being out of sync locally and remotely. Following the instructions for the top answer on this post cleared up the issue: Django Heroku Error "Your models have changes that are not yet reflected in a migration"

Local -> Github working | Local -> Heroku not working

I have a Django application which is present in my local system.
As I want to ignore db.sqlite3 files while transferring the repository, I have put the following in .gitignore
db.sqlite3
I push it to Github using:
git push origin master
When I do this, the updated db.sqlite3 from local system is NOT transferred to git.
As the next step, I need to transfer the files from local system to Heroku using:
git push heroku master
However, it seems that the file from Github is copied to heroku, which is weird.
Perhaps my understanding of the git push heroku master is incorrect.
Deployment method is using heroku cli
To check this weird way of working :
I added couple of entries in db.sqlite3 in my local system
I made a small change to the code in my local system
I made new entries in the Django application which is deployed to heroku
I pushed the application to Github using git push origin master and checked the timestamp on db.sqlite3 in git and it wasn't changed - I downloaded the db.sqlite3 from git and checked, the new entries that I made to the local system weren't there. This is good.
I pushed the application to Heroku using git push heroku master and found that the entries which I made in step 3 are gone and the entries in step 1 are also not reflected.
I checked my Github db.sqlite3 file and heroku db.sqlite3 file and they matched.
My requirements are as follows :
The changes to the data in db that I make in my local system should not reflect in the application deployed to heroku (I believe therefore .gitignore -> db.sqlite3)
The structural and the application changes should only go to production.
Any pointers in the right direction ?
I figured this out, like my last two queries.
I was misled by this command :
git update-index --assume-unchanged db.sqlite3
Though this link clearly tells not do to so.
For the solution, git and .gitignore works perfectly fine (stating the obvious) . It requires only one entry called db.sqlite3 and you need to ensure that you do not send db.sqlite3 to heroku. You need to have your .gitignore file updated with db.sqlite3 and use PostgreSQL in heroku.
When I did this, I received an error called django-session not setup. Basically it meant that PostgreSQL is not ready for use. You need to ensure that you are ready to follow the steps below.
Few things to remember :
When experimenting with Django, locally you use db.sqlite3 and eager to send the database file db.sqlite3 to heroku and do not make entries in .gitignore. Don't do that.
In local, use db.sqlite3 and while deploying to heroku , use PostgreSQL
Create a virtual environment using pipenv
Use pipenv install psycopg2
Use heroku run bash -a <appname>
Go to manage.py folder and run python manage.py migrate
Create your superuser python manage.py createsuperuser
This worked for me. I shall come back and update this a bit more. Three days of brain-wreck.
Finally keep searching in Github , we have a goldmine of problems and solutions already provided. Sometimes we just need to connect the dots.

Hide Django's staticfiles from GitHub stats

To understand what I'm talking about, I call GitHub stat this line:
I have my Django project on GitHub repository and, I use Heroku to deploy this project. To deploy my project to Heroku, I need first to run python manage.py collectstatic that will generate a lot of CSS and JS like on screenshot above.
I want to hide this folder not ignore, because Heroku needs it to work properly.
UPD 1:
So, I created new branch called debug. debug branch is identical with master, but, without staticfiles folder. And when i start Heroku with this branch, as i said, it gives me an 500 Server Error. Ofcourse, I runned python manage.py collectstatic before start.
UPD 2:
After restarting all Heroku dynos (heroku ps:restart in CLI), all works fine without pre compiled staticfiles.
This:
To deploy my project to Heroku, I need first to run python manage.py collectstatic
is not true. Heroku will run collectstatic for you when you deploy. You do not need to run it before deploying, and you definitely do not need to add the destination directory to git.

How to link a folder with an existing Heroku app with mercurial

I have an existing Django app on Bitbucket and I'm able to deploy to Heroku whith hg-git. Whenever i want to run some heroku command inside my app folder i get the following errors:
$ heroku ps
! No app specified.
! Run this command from an app folder or specify which app to use with --app <app name>
$ heroku logs
! No app specified.
! Run this command from an app folder or specify which app to use with --app <app name>
etc.
Current workaround is to specify the app name: heroku ps --app <app name> but i'm looking for a way to link my repository name to the remote Heroku app name like how it's done using git.
I'm not in a position to move my app to github for now.
I'd suggest trying Hg-Git's "intree" configuration option. Set that by adding the following to your hgrc:
[git]
intree = True
With that set, the Git repository used internally by Hg-Git will be stored as a ".git" directory within the working copy, rather than nested within the ".hg" directory.
Heroku will then see this repository's config. Add a remote as suggested in the other answer (quoted below), and you should be all set.
git remote add heroku git#heroku.com:<app-name>.git
For now, the best documentation of Hg-Git configuration options that I've found is the README displayed on the project's Bitbucket page: https://bitbucket.org/durin42/hg-git
Considering heroku is looking at the .git/config file to get the app name, just do the following inside your local repository:
git init
git remote add heroku git#heroku.com:<app-name>.git
In order not to mess your repository, you'll also add the following lines to .hgignore:
#Git setup
.git/**
Now, usual heroku commands no more ask for the default app name.