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.
Related
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.
I have a Django app running in a Docker container. I am using Nginx to serve as the production server with a docker-compose file putting the app, Nginx and Postgres together in a network of containers. I set up my Dockerfile as follows:
FROM python:3.9.6-buster
ENV HOME=/home/app/
ENV APP_HOME=/home/app/web
RUN mkdir -p "${APP_HOME}/staticfiles"
# Create user
ENV PYTHONBUFFERED=1
WORKDIR $APP_HOME
COPY requirements.txt $APP_HOME
RUN pip install -r requirements.txt
COPY . $APP_HOME
which as you can see sets a staticfiles directory. However, following normal Django principals my file structure is /home/app/web/quote_checklist/static/quote_checklist when I exec into the web container.
I'm using the following in my settings.py
BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
When I access the index page I am getting an error that the directory/file /home/app/web/staticfiles/quote_checklist/css/base.css is not found, suggesting my app is looking in this staticfiles directory, which has nothing in it. I tried removing the /staticfiles/ bit from my static volume as well but then the system just looks in /home/app/web/static/quote_checklist/css/base.css rather than following the normal Django path, which would be to look in quote_checklist/static/quote_checklist/css/base.css.
Does anyone have suggestions?
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.
Starting a new project and realized that the structure for the tutorial and my structure do not match. It looks like a directory was created for the myproject and a directory AND a file were created for myapp... I don't understand. Is this correct?
Tutorial structure shows:
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
asgi.py
wsgi.py
My structure shows:
mysite/
myapp
myappp
__init__.py
settings.py
urls.py
wsgi.py
manage.py
#NinaPy, Your directory structure seems to be correct but there exist an issue.
Please follow the steps:
1) Go to your directory where you want to keep your project. Example--myproject folder
cd myproject
2) Now you are within your desired folder. run the command from CLI(Command Line Interface)
django-admin startproject mysite //mysite is the project name
it will create
1 directory[mysite] and 1 file[manage.py]
3) Now if you want to create an app: Go to mysite directory because manage.py exist in there.
cd mysite
run the command from CLI
python manage.py startapp myapp
It will create myapp in same level.
myproject/
mysite
manage.py
myapp
If you use the CLI then you are quite safe for folder directory and file structure. Do not try it to do manually unless you need some extra files.
Please have a look on here:
https://docs.djangoproject.com/en/3.0/intro/tutorial01/#creating-a-project
your can run python manage.py startproject to create a new project
yes its correct
before run type on terminal(enter the directory mysite)
cd mysite
then run
python manage.py runserver
python manage.py startapp appmane
........
..........
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.