Git ignores all files - django

My gitignore file looks straighforward:
env/
.idea
*.pyc
__pycache__
*.env
/environment
db.sqlite3
*.log
When I do git add . from my root project folder and then check status - I see there is no files tracked.
When I do git status --ignored, I see that all folders are ignored:
.flake8
.gitignore
.idea/
Procfile
env/
requirements.txt
runtime.txt
src/
So it somehow ignores all the folders and files.
I tried to comment everything in gitignore - and the result is the same.
I tried to reinitialize the git by:
rm -rf .git
git init
And the result is the same.
How can I add my files, without git add --force?
I want files that are added in gitignore to be ignored, but still to commit other files.

As in the comments: it seems that venv or virtualenv created a global .gitignore (in /Users/admin/.gitignore) whose second line read *, ignoring all files.
It's not clear what caused this venv entry to be created in /Users/admin in the first place, so finding out if anything depends on it remains to be done, but in the meantime, any virtual environment data in the home directory here should be moved or removed, so that the global .gitignore isn't there any more.

Related

Django elastic beanstalk CLI deployment failure after adding .env files to gitignore

I'm new to Django/EB/Git and been working on a django project and have successfully separated my setttings and separated .env files for both development and production which all works as expected and deployed- see the following project structure:
Project Structure
project root
myapp
settings
__init__
base.py
dev.py
prod.py
.env.dev
.env.prod
.gitignore
manage.py
requiremnts.txt
However the moment I add my my .env files to the .gitignore file I now received the following error with deployment within eb logs (cfn-init-cmd.log):
.gitignore
# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
.env.dev
.env.prod
Error: eb logs (cfn-init-cmd.log)
FileNotFoundError: [Errno 2] No such file or directory: '.env.prod'
If i remove .env.prod from the .gitignore file then my project deploys successfully.
Moreoever, I read online that might be due to me git adding and comitting the .env.prod file to the repo however believe I have also excluded git add/commit when I started fresh and re-created the git repo with the following command (commands run on local project):
git add --all -- :!.env.dev :!.env.prod
git commit -m "Initial commit"
Followed by:
eb deploy myproject-env
See my .ebextensions config file as follows:
.ebextensions/django.config
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: myproject.wsgi:application
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: "myproject.settings.prod"
aws:elasticbeanstalk:environment:proxy:staticfiles:
"/static": "static/"
packages:
yum:
python3-devel: []
mariadb-devel: []
container_commands:
01_collectstatic:
command: "source /var/app/venv/staging-LQM1lest/bin/activate && python manage.py collectstatic --noinput"
02_migrate:
command: "source /var/app/venv/staging-LQM1lest/bin/activate && python manage.py migrate --noinput"
leader_only: true
I was not sure if I'm supposed to add any git commands to my .ebextensions config but assumed it's just to be done on local git repo and then push to github, I have also tried to deploy with and without codecommit but made no difference to the above.
I have spent a about a week figuring this all out and finally being able to deploy and this I believe was supposed to be the very last step adding .env files to .gitignore file, I'm just not sure what I'm missing or have done something I correctly with the git repo.
Elastic beanstalk use .gitignore file if .ebignore file does not exist. So you can use both for your file management.
AWS doc says:
You can tell the EB CLI to ignore certain files in your project
directory by adding the file .ebignore to the directory. This file
works like a .gitignore file.
...
If .ebignore isn't present, but .gitignore is, the EB CLI ignores
files specified in .gitignore. If .ebignore is present, the EB CLI
doesn't read .gitignore.
When .ebignore is present, the EB CLI doesn't use git commands to
create your source bundle. This means that EB CLI ignores files
specified in .ebignore, and includes all other files. In particular,
it includes uncommitted source files.

Is it good practice to add .git folder to Github?

After i entered git init I have directory D:myproject\.git
Is it good to add .git folder it in Github or should i add it in .gitignore?
You should not worry about .git folder. It contains git internals and all information in your repository like commits, branches and blobs. So .git is a repository itself and is handled automatically.
If you are in the root directory of your app and you do git init command what happens is that the command says initialize this directory and everything below it as a git repository. And it will set up a local repository for you on your machine.
Local repository on your machine allows git to track version changes in our files. Once we are happy with all those changes and our files then we push them to a remote repository on GitHub.
And you don't have to add your .git folder in .gitignore file.

.gitignore not ignoring files on current server

I'm trying to import my Bitbucket repo into my Digital Ocean Django server (next to env, static and manage.py. But when I do git add . inside the server directory, and then git status, it still shows the env files there. Any reason why this is happening?
Edit:
.gitignore
env/
/env
/bin
/lib
/media
/static
/include
/reports
.DS_Store
*.pyc
celerybeat-schedule.db
__pycache__/
db.sqlite3
settings.py
Try doing it in this format:
env/env
env/bin
env/lib
etc.

Can't find .env file for locally starting Django app using 'heroku local'

I want to local run my Django app with Heroku using, for example, 'heroku local -e .env.test' (see https://devcenter.heroku.com/articles/heroku-local). I am using virtualenvwrapper so my envs (test, dev) are not in my Django project server but located in my $WORKON_HOME directory. I don't know what to specify for the last part of the command because I can't find the .env files in the $WORKON_HOME.
I've tried heroku local -e $WORKON_HOME/dev and heroku local -e $VIRTUAL_ENV and get the same error: ▸ EISDIR: EISDIR: illegal operation on a directory, read
For me, the problem was that I had created a virtualenv directory called .env, conflicting with Heroku's ENV system which uses the same filename. Deleting the virtualenv and recreating it as .venv solved my problem:
deactivate
rm -rf .env
virtualenv .venv
source .venv/bin/activate
NB. You can't just rename the .env directory without having to manually edit the virtualenv configuration too; better just to destroy and recreate.
I think the confusion comes from what you think .env does: that is used by the Procfile (which is called by Foreman https://ddollar.github.io/foreman/ ) to set environment variables like:
A=b
C=d
.env there is not your virtualenv, which you should not git track.
Just use your virtualenv as usual before calling heroku local and track a requirements.txt (and possibly runtime.txt for the Python version, see https://devcenter.heroku.com/articles/deploying-python )
Heroku will automatically use virtualenv when you push.
As usual, look for minimal working examples to get started: https://github.com/heroku/heroku-django-template
Answering my own question:
I was able to solve my issue by issuing the following command from the base directory of my Django project.
echo "source /home/your_username/.virtualenvs/venv_name_here/bin/activate" >> .env
[the command is referenced here: How to create/make your app LOCAL with Heroku/Virtualenv/Django? ]
Reiterating, this was needed because virtualenvwrapper doesn't automatically create .env's. Thus,heroku local's apparent need for a .env requires a manual creation of the environmental file. #ciro-santilli-巴拿馬文件-六四事件-法轮功 if you know a better way, such as some option of heroku local, I'd like to know.

How to import a Django app from Git into a project

I want to include a Django app into the project I'm working on. The app is hosted on Github ( https://github.com/lmorchard/django-badger ). As well as the app's directory containing the goodies, there are some files in the root - README, LICENCE, TODO and setup.py. If I clone the app into my project's root directory, the app folder will be in the correct place, but those root files will be in my project's root. How can I add the app while still tracking the upstream code in Github?
I had a similar issue where I was working on two independent projects where both were in a repo, and one of them used the other as an app:
Create a virtualenv and install all dependencies for both projects. I usually like to have a virtualenv for each project/repo but in this case you need one env which can execute Python from both repos.
Clone both repos to independent location. Do not clone the depending app inside the other project. Your file-structure then might look like this (assuming Django 1.3 project layout):
project/
manage.py
project/
__init__.py
settings.py
...
...
app/
README
...
app/
__init__.py
models.py
...
And final step is to create a symlink (or shortcut on Windows) from the app directory which has __init__.py in it to the project path.
$ ln -s /abs/path/to/app/app /abs/path/to/project/
Now you can use the virtualenv to run the project!
The final result is that you have two independent repos however one of projects is using the other project without directly copying the code, hence allowing you to maintain two repos.
U can install it by running
python setup.py
or through pip
sudo pip install -e git+https://github.com/lmorchard/django-badger#egg=django-badger
Clone the repository from github using git://github.com/lmorchard/django-badger.git. Then open the cloned folder in terminal. Install the app using the command sudo python setup.py install. This will work good. If you want to have the app included in your project, create a folder named badger(or anything you wish) and copy the installed app from dist-packages to created folder.