diff --git a/Makefile b/Makefile index 28bfb872c99d..66ce2739cd1f 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +COMPOSE_PROJECT_NAME ?= $(notdir $(abspath .)) DB := example IPYTHON := no @@ -82,11 +83,12 @@ translations: .state/docker-build-web requirements/%.txt: requirements/%.in docker-compose run --rm web bin/pip-compile --allow-unsafe --generate-hashes --output-file=$@ $< -initdb: .state/docker-build-web - docker-compose run --rm web psql -h db -d postgres -U postgres -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname ='warehouse';" - docker-compose run --rm web psql -h db -d postgres -U postgres -c "DROP DATABASE IF EXISTS warehouse" - docker-compose run --rm web psql -h db -d postgres -U postgres -c "CREATE DATABASE warehouse ENCODING 'UTF8'" - docker-compose run --rm web bash -c "xz -d -f -k dev/$(DB).sql.xz --stdout | psql -h db -d warehouse -U postgres -v ON_ERROR_STOP=1 -1 -f -" +resetdb: .state/docker-build-web + docker-compose stop db + docker volume rm $(COMPOSE_PROJECT_NAME)_pgdata + docker-compose up -d --recreate db + +migrate: .state/docker-build-web docker-compose run --rm web python -m warehouse db upgrade head docker-compose run --rm web python -m warehouse sponsors populate-db $(MAKE) reindex diff --git a/dev/environment b/dev/environment index 7ff31f5bc7b5..4a2996310aa6 100644 --- a/dev/environment +++ b/dev/environment @@ -8,7 +8,7 @@ AWS_ACCESS_KEY_ID=foo AWS_SECRET_ACCESS_KEY=foo BROKER_URL=sqs://localstack:4566/?region=us-east-1&queue_name_prefix=warehouse-dev -DATABASE_URL=postgresql://postgres@db/warehouse +DATABASE_URL=postgresql://postgres:password@db/warehouse ELASTICSEARCH_URL=http://elasticsearch:9200/development diff --git a/docker-compose.yml b/docker-compose.yml index e897976a5ff7..8d594ee0f5b4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,6 +3,7 @@ version: '3.9' volumes: simple: packages: + pgdata: sponsorlogos: vault: @@ -25,12 +26,18 @@ services: - ./dev/vault:/etc/vault db: - image: postgres:10.1 + image: postgres:10 ports: # 5432 may already in use by another PostgreSQL on host - "5433:5432" healthcheck: - test: ["CMD", "pg_isready", "-U", "postgres", "-d", "postgres"] + test: ["CMD", "pg_isready", "-d", "warehouse"] + environment: + POSTGRES_DB: warehouse + POSTGRES_PASSWORD: password + volumes: + - pgdata:/var/lib/postgresql/data + - ./dev/example.sql.xz:/docker-entrypoint-initdb.d/example.sql.xz:ro redis: image: redis:4.0 diff --git a/docs/development/getting-started.rst b/docs/development/getting-started.rst index 763c80dbfeee..81fb1e49adc6 100644 --- a/docs/development/getting-started.rst +++ b/docs/development/getting-started.rst @@ -238,7 +238,27 @@ or that the ``static`` container has finished compiling the static assets: static_1 | [20:28:37] Starting 'watch'... static_1 | [20:28:37] Finished 'watch' after 11 ms -or maybe something else. +After the docker containers are setup in the previous step, run: + +.. code-block:: console + + make migrate + +This command will: + +* run migrations on the Postgres database, +* index all the data for the search database, and +* load some example data from `Test PyPI`_. + +The Postgres database is created automatically when its docker +container starts for the first time. It also gets populated with +example data. If you will need to reset the database, use: + +.. code-block:: console + + make resetdb + +Once the ``make initdb`` command has finished, you are ready to continue. Viewing Warehouse in a browser