Skip to content

Commit

Permalink
chore(dev): changes for developer ergonomics (pypi#10816)
Browse files Browse the repository at this point in the history
* chore(dev): set web to depend on db

When running `make tests`, the current expectation is that the user has
executed `make serve` and the database container is running in already.

This brings in all the other runtime dependencies, when all the tests
need is a running database instance.

Setting the `depends_on` flag tells docker-compose to start the db
container first, any time we run a `web` container, and saves us the
step of starting it ourselves in another shell.

Signed-off-by: Mike Fiedler <miketheman@gmail.com>

* chore(dev): set elasticsearch to single-node

The current settings for the elasticsearch container place the started
node in "production, single node cluster" mode.
This performs boostrap tests, one of which tests for virtual memory via
the `sysctl` setting of `vm.max_map_count`.

In certain Docker-in-Docker development environments, the end user may
not have access to the underlying host settings, and cannot modify this
setting.
An alternative is to set the `discovery-type` to a single node, placing
the service in "development mode", turning any bootstrap checks from
errors to warnings.

Refs: https://www.elastic.co/guide/en/elasticsearch/reference/7.10/system-config.html#dev-vs-prod
Refs: https://www.elastic.co/guide/en/elasticsearch/reference/7.10/bootstrap-checks.html

Originally reported in pypi#1511, related to pypi#4370

Signed-off-by: Mike Fiedler <miketheman@gmail.com>

* chore: enable context reporting in coverage

coverage.py version 5.0 introduced the notion of measurement contexts.
This adds details to the report to show:

- how many times a given line was executed
- which context executed a given line

Enabling dynamic context measurement during the test execution adds
test class/function contexts to the coverage data to be displayed on
a given report output.

Refs: https://coverage.readthedocs.io/en/6.3.2/contexts.html#dynamic-contexts

Signed-off-by: Mike Fiedler <miketheman@gmail.com>

* chore(dev): enable web port to be set via env var

Creating a port under 1024 often requires superuser privileges.
In some environments this is disallowed.
By using the built-in behavior from Docker Compose, a user can now set:

    WEB_PORT=8080 make serve

and the web application will be made availabel on port 8080.

The default remains port 80.

Signed-off-by: Mike Fiedler <miketheman@gmail.com>
  • Loading branch information
miketheman authored and domdfcoding committed Jun 7, 2022
1 parent 0906b31 commit 02b1d73
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[run]
branch = True
dynamic_context = test_function

source =
warehouse
Expand Down
2 changes: 1 addition & 1 deletion bin/tests
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ set -x

# Actually run our tests.
python -m coverage run -m pytest --strict-markers $COMMAND_ARGS
python -m coverage html
python -m coverage html --show-contexts
python -m coverage report -m --fail-under 100
7 changes: 4 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ services:
image: elasticsearch:7.10.1
environment:
- xpack.security.enabled=false
- node.name=node-1
- cluster.initial_master_nodes=node-1
- discovery.type=single-node
ulimits:
nofile:
soft: 65536
Expand Down Expand Up @@ -90,7 +89,9 @@ services:
- simple:/var/opt/warehouse/simple
- ./bin:/opt/warehouse/src/bin:z
ports:
- "80:8000"
- "${WEB_PORT:-80}:8000"
depends_on:
- db

files:
build:
Expand Down
12 changes: 12 additions & 0 deletions docs/development/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ If the port is in use, the command will produce output, and you will need to
determine what is occupying the port and shut down the corresponding service.
Otherwise, the port is available for Warehouse to use, and you can continue.

Alternately, you may set the ``WEB_HOST`` environment variable for
docker-compose to use instead. An example:

.. code-block:: console
export WEB_HOST=8080
make ...
# or inline:
WEB_HOST=8080 make ...
Building the Warehouse Container
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -265,6 +275,8 @@ At this point all the services are up, and web container is listening on port
`this bug report <https://bugzilla.mozilla.org/show_bug.cgi?id=1262842>`_
for more info).

If you've set a different port via the ``WEB_HOST`` environment variable,
use that port instead.

Logging in to Warehouse
^^^^^^^^^^^^^^^^^^^^^^^
Expand Down

0 comments on commit 02b1d73

Please sign in to comment.