Set Up Virtualenv:
virtualenv --python=<path_to_python3> venv
Activate the environment:
source venv/bin/activate
Install requirements:
pip install -r requirements.txt
Start up a postgres instance:
docker run --rm -d --name postgres-test -e POSTGRES_PASSWORD=docker -p 5432:5432 postgres
Log into the database and Set up the postgres databases and users:
psql postgres -h localhost -U postgres
create user pta_user with password 'pta_password’;
create database pta_database with owner pta_user;
grant all privileges on all tables in schema public to pta_user;
Export Your Variables
export SQL_ENGINE=django.db.backends.postgresql
export SQL_DATABASE=pta_database
export SQL_USER=pta_user
export SQL_PASSWORD=pta_password
export SQL_HOST=localhost
export SQL_PORT=5432
Django migrate and run the server:
python manage.py makemigrations
python manage.py migrate
python manage.py shell -c "from django.contrib.auth.models import User; User.objects.filter(username='admin').exists() or User.objects.create_superuser('admin','admin.admin@example.com', 'changeme')"
python manage.py runserver 0.0.0.0:8000
Go to the url 0.0.0.0:8000 to test
- Log into the admin interface to add content at 0.0.0.0:8000/admin
- View images and content from the 0.0.0.0:8000/photo_viewer
The sample docker-compose.yml script runs the Django Application and also brings up a Database...It automates the process of creating the specific users and databases on postgres before handling the migration.
The Dockerfile will need to include a .env.dev file which is mounted: Add the following details in the file:
SQL_ENGINE=django.db.backends.postgresql
SQL_DATABASE=pta_database
SQL_USER=pta_user
SQL_PASSWORD=pta_password
SQL_HOST=db
SQL_PORT=5432
PGPASSWORD=docker
Then run the following:
Export the password for the database so it can be connected to via the entrypoint script
export PGPASSWORD=docker
docker-compose build
...
docker-compose up -d
Once the application is running, you use the Django Administration console to add your images and list of countries your images are from.
http://0.0.0.0:8000/admin/
Simply click on the add button next to Countries to add a list of countries
Click on the add button next to Photos and your see a screen similar to the screenshot below. Enter a title for the image, details of the image, browse to where the image is and country the image is from. Then save.
Viewing all the images on the site
http://127.0.0.1:8000/photo_viewer/
Clicking on the Country name on each image or on the main page will bring up all the images for this country
Clicking on the Read More button to view more details about the image
- Nginx Proxy for project
- Correct layout
- Set up testing
- Set up redis caching
- Set up production server
- Document
- Postgresql database
- Dockerise App
- docker-compose
- admin username and password for Django(secure)
- sql username and passwords(secure)