diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..81df23034 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,16 @@ +# Copied from .gitignore +__pycache__ +data +*.pyc +*.db +locale/*/LC_MESSAGES/django.mo +*/locale/*/LC_MESSAGES/django.mo +.sass-cache/ +.coverage +.direnv +.envrc +djangoproject/cache +djangoproject/static/css/*.map +djangoproject/static/css/*.css +# Additional ignores for Docker +.git/ diff --git a/.github/workflows/docker-test-build.yml b/.github/workflows/docker-test-build.yml index 57f9634b0..5492325f6 100644 --- a/.github/workflows/docker-test-build.yml +++ b/.github/workflows/docker-test-build.yml @@ -25,10 +25,21 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Test docker image build (local development) + - if: matrix.req_file != 'tests.txt' + name: Test docker image build (${{ matrix.req_file }}) uses: docker/build-push-action@v6 with: context: . push: false build-args: | REQ_FILE=requirements/${{ matrix.req_file }} + + - if: matrix.req_file == 'tests.txt' + name: Set up Docker Compose + uses: docker/setup-compose-action@v1 + + - if: matrix.req_file == 'tests.txt' + name: Run the tests via Docker + run: | + docker compose build + docker compose run --rm web make ci diff --git a/Makefile b/Makefile index 78f59e899..910ce300e 100644 --- a/Makefile +++ b/Makefile @@ -33,3 +33,10 @@ test: watch-scss: watchmedo shell-command --patterns=*.scss --recursive --command="make compile-scss-debug" $(SCSS) + +reset-local-db: + python -m manage flush --no-input + python -m manage loaddata dev_sites + python -m manage loaddata doc_releases + python -m manage loaddata dashboard_production_metrics + python -m manage update_metrics diff --git a/README.rst b/README.rst index 1715f5895..5502479f6 100644 --- a/README.rst +++ b/README.rst @@ -343,12 +343,26 @@ Running Locally with Docker docker compose up -3. View the site at http://localhost:8000/ - -4. Run the tests:: +3. Run the tests:: docker compose run --rm web python -m manage test +4. Load the sample / local dev data:: + + docker compose run --rm web make reset-local-db + + If preferred, refer to the "Install and run locally from a virtual environment" + for more granular management commands to load specific data sets. + +5. View the site at http://www.djangoproject.localhost:8000/ + or http://dashboard.djangoproject.localhost:8000/. + +6. For docs, download the documentation (takes awhile):: + + docker compose exec -it web python -m manage update_docs + +7. View the docs at http://docs.djangoproject.localhost:8000/. + Pre-commit checks ----------------- diff --git a/djangoproject/settings/docker.py b/djangoproject/settings/docker.py index 35216e40c..1484a008e 100644 --- a/djangoproject/settings/docker.py +++ b/djangoproject/settings/docker.py @@ -24,8 +24,3 @@ SECRET_KEY = os.environ.get("SECRET_KEY") ALLOWED_HOSTS = [".localhost", "127.0.0.1", "www.127.0.0.1"] - -LOCALE_MIDDLEWARE_EXCLUDED_HOSTS = ["docs.djangoproject.localhost"] - -# django-hosts settings -PARENT_HOST = "djangoproject.localhost:8000" diff --git a/docker-compose.yml b/docker-compose.yml index 3cdd08525..ff6432b79 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -43,4 +43,9 @@ services: timeout: 10s retries: 10 volumes: - - ./initdb/tracdb.sql:/docker-entrypoint-initdb.d/tracdb.sql + # Mount the Postgres initialization scripts + - ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d + # This file contains the initial Trac database schema, but needs + # to be loaded into the database manually (via 02_trac_schema.sh) + # since it applies to the trac database, not the main Django database. + - ./tracdb/trac.sql:/trac.sql diff --git a/initdb/tracdb.sql b/docker-entrypoint-initdb.d/01_trac_db.sql similarity index 100% rename from initdb/tracdb.sql rename to docker-entrypoint-initdb.d/01_trac_db.sql diff --git a/docker-entrypoint-initdb.d/02_trac_schema.sh b/docker-entrypoint-initdb.d/02_trac_schema.sh new file mode 100755 index 000000000..8024f468b --- /dev/null +++ b/docker-entrypoint-initdb.d/02_trac_schema.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +PGPASSWORD=secret psql --username=code.djangoproject --dbname=code.djangoproject < /trac.sql diff --git a/docker-entrypoint.dev.sh b/docker-entrypoint.dev.sh index 9a654950c..06edae540 100755 --- a/docker-entrypoint.dev.sh +++ b/docker-entrypoint.dev.sh @@ -1,16 +1,7 @@ #!/bin/sh -python -m manage flush --no-input -PGPASSWORD=secret psql --host db --port 5432 --username=code.djangoproject --dbname=code.djangoproject < tracdb/trac.sql python -m manage migrate make compile-scss # must come before collectstatic python -m manage collectstatic --no-input --clear -python -m manage loaddata dev_sites -python -m manage loaddata doc_releases -# git config --global url."https://".insteadOf git:// -# python -m manage update_docs -python -m manage loaddata dashboard_production_metrics -# python -m manage loaddata dashboard_example_data -python -m manage update_metrics exec "$@"