.circleci | ||
gallery | ||
.editorconfig | ||
.gitignore | ||
docker-compose.yaml | ||
Dockerfile | ||
LICENSE | ||
manage.py | ||
README.docker.md | ||
requirements.txt | ||
run.sh |
local development
You'll need to have installed docker-compose
and docker
, and have a running
docker daemon.
starting services with docker-compose
You should be inside the django-gallery
directory when running this command.
docker-compose up
You'll see labeled output from each service.
When you make changes on your local copy of django-gallery, they will automatically propagate to the running container.
accessing the database (cli)
There are cases where you may need access to the database (such as restoring a backup). These commands will allow you access into the database over the command line.
- Have docker running. Eg.
docker-compose up -f docker-compose.yaml
- Locate your container.
docker ps
, select the CONTAINER ID for postgres - Establish a shell in the container.
docker exec -t -i (CONTAINER ID) bash
- Connect to the database.
su postgres -c psql
Now that you are connected to the database CLI, you can perform queries as the root postgres user.
For remote access to this database, you may create a role for yourself with the following query.
create role your-name with superuser createdb login password 'your-password';
To restore a database backup from the command line:
- Find a way to copy the database into the container (or access it externally)
- Become the postgres root user.
su postgres -c bash
- Stop the portal docker container (this can be accomplished with
docker stop (CONTAINER ID)
) - Verify that there are no other connections to the DB and enter psql
- Rename or drop the imagehost_db database so it is out of the way
- create the database and public schema
- set permissions for the imagehost user
- leave psql and run
pg_restore -F -c imagehost_dbDB.custom
on newly created imagehost_db db
Some errors are expected from the above, such as a non-existant usagereports role. These can safely be ignored for development use (the role requires read-only access in prod)
accessing the database (GUI)
GUI access to the database can be established with PGAdmin (3 or 4) connected to localhost. This assumes that you created a user for yourself in the previous section (if you haven't, you can use the imagehost user at limited permissions)
- Open PGAdmin and add a new server with an identifying name
- Under the connection tab
- Hostname/address should be localhost
- Username should be what you added in the previous section
- Password should be what you added in the previous section
- Save and connect, you should now be able to run queries with administrative privileges.
To restore a database backup inside PGAdmin:
- Copy the imagehost_dbDB.custom to your desktop (or somewhere easy) and rename to imagehost_dbDB.backup
- Connect to the database server
- Stop the portal docker container (this can be accomplished with
docker stop (CONTIANER ID)
) - Verify that there are no other connections to the db and either rename or drop the database
- Create a new database with the owner set to imagehost
- Right-click the newly created database and click restore
- Navigate to your .backup file and select that
- Let the restore run
Some errors are expected from the above, such as a non-existant usagereports role. These can safely be ignored for development use (the role requires read-only access in prod)
applying migrations
After you have made changes to the database or models, migrations need to be made and then applied. To accomplish that in the docker env:
- Have docker running. Eg.
docker-compose up -f docker-compose.yaml
- Locate your container.
docker ps
, select the CONTAINER ID for the portal - Establish a shell in the container.
docker exec -t -i (CONTIANER ID) bash
- CD to the portal directory (in docker-compose.yaml, this is defined as /portal)
- Make your migrations.
python manage.py makemigrations
- Apply the migrations.
python manage.py migrate
- Optionally exit the shell. It is no longer needed.
You may get errors on your last step if you are restoring from a database
backup. Before making the migrations, first run python manage.py --fake-initial
If your database has migrations applied, it should be able to continue from whichever the last applied migration was.
staging/testing
You'll need to have docker-machine
installed. You can create a fully
provisioned VM on ESXi using this command:
docker-machine create \
--driver vmwarevsphere \
--vmwarevsphere-username root \
--vmwarevsphere-password password \
--vmwarevsphere-vcenter 500.500.500.500 \
my-docker
You should replace my-docker
with whatever you want to uniquely reference this
VM by.
Note: If you get an error similar to "ServerFaultCode: Current license or ESXi version prohibits execution of the requested operation." you must first put the vmserver in "Evaluation Mode" as the Free tier license does not support remote management of VMs. This can be accomplished by logging into the esxi interface, navigating to configuration and changing the license config.
remote environment
First, you'll set up your local docker client to connect to the remote docker host:
eval $(docker-machine env my-docker)
You can see the containers running on the remote host using regular docker
commands like docker ps
.
create a production environment
docker-compose -f docker-compose.yaml -f docker-compose.production.yaml up