Skip to content

Commit

Permalink
Merge pull request #236 from EarthSchlange/feat_add_testing_with_docker
Browse files Browse the repository at this point in the history
feat: add testing with docker

Adds the feature to the docker-compose.test.yml for testing; however, it does not add any tests.
  • Loading branch information
Michael Hiiva committed Nov 20, 2021
2 parents e9da1c6 + 5de4ab9 commit 5e8b8a6
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 26 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ ENV TEMPLATE_DIR=/srv/templates
COPY --chown=django:django scripts/ agagd/ /srv/

ENTRYPOINT ["/srv/entrypoint.sh"]
CMD ["gunicorn", "-b", "0.0.0.0:8000", "agagd.wsgi"]
53 changes: 53 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# docker-compose setup for a development environment.
# To use this file, populate config-docker.env with the following:
#
# MYSQL_PASSWORD - a password for the mysql user
# MYSQL_ROOT_PASSWORD - a password for the mysql *root* user
#
# Then you can run:
# - docker-compose build
# - docker-compose up

version: '3.5'

services:
test_app:
build: ./
restart: always
environment:
DB_HOST: test_db
DB_PORT: 3306
APP_DB_NAME: agagd
AGAGD_USER: agagd
MYSQL_PASSWORD: "${MYSQL_PASSWORD}"
SECRET_KEY: insecure-key-for-testing
DEBUG: "true"
LOAD_FIXTURES: "false"
volumes:
- ./agagd/agagd:/srv/agagd
- ./agagd/agagd_core:/srv/agagd_core
- ./agagd/media:/srv/media
- ./agagd/static:/srv/static
- ./agagd/jinja2:/srv/jinja2
- ./agagd/templates:/srv/templates
command: "python manage.py test"
depends_on:
- "test_db"
test_db:
build:
context: ./
dockerfile: Dockerfile.mysql
restart: always
volumes:
- test_database:/var/lib/mysql
environment:
# This is safer than it looks, since without a 'ports' section, docker-compose
# isolates this app to a network local to this compose file.
MYSQL_ROOT_HOST: "%"
MYSQL_ROOT_PASSWORD: "${MYSQL_ROOT_PASSWORD}"
MYSQL_USER: agagd
MYSQL_DATABASE: test_agagd
MYSQL_PASSWORD: "${MYSQL_PASSWORD}"

volumes:
test_database:
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ services:
- ./agagd/static:/srv/static
- ./agagd/jinja2:/srv/jinja2
- ./agagd/templates:/srv/templates
command: "-r" # Initializes python-autoreload for uwsgi via the scripts/entrypoint.sh.
command: "python manage.py runserver 0.0.0.0:8000"
depends_on:
- "db"
db:
build:
context: ./
Expand Down
33 changes: 8 additions & 25 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#!/bin/bash

# Get the r_flag from the options.
while getopts ':r' flag; do
case ${flag} in
r)
get_options_r_flag=0
;;
esac
done
# Cause the script to fail loudly when it fails.
# see: (http://redsymbol.net/articles/unofficial-bash-strict-mode/)
set -euo pipefail

# Set the MySQL Command
MYSQL_COMMAND="mysql --host=$DB_HOST --port=$DB_PORT --user=$AGAGD_USER --password=$MYSQL_PASSWORD"
Expand All @@ -31,22 +26,9 @@ function wait_for_db() {
exit 1
}

wait_for_db

# Start the server by default without py-autoload.
# If the r argument is supplied as in development,
# autoreload the server on py file changes.
function start_server() {
r_flag=${get_options_r_flag:-1}

if [ $r_flag == 0 ];
then
python manage.py runserver 0.0.0.0:8000
elif [ $r_flag == 1 ];
then
gunicorn -b 0.0.0.0:8000 agagd.wsgi
fi
}
if [[ "$3" != "test" ]]; then
wait_for_db
fi

if $LOAD_FIXTURES == "true"; then
python make_fake_fixtures.py 1000 1000 1000 > /tmp/fake_agagd_data.json
Expand All @@ -58,4 +40,5 @@ fi
# other assets shown.
python manage.py collectstatic --noinput

start_server
# Allow the commands to be passed into Entrypoint.
exec "$@"

0 comments on commit 5e8b8a6

Please sign in to comment.