Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
Upgrade docker compose to v2.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-sitylb committed May 13, 2024
1 parent 87abd50 commit b8e4213
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,36 @@ jobs:
run: cp .env.example .env

- name: Build/Pull Containers
run: docker-compose build
run: docker compose build

- name: Start full stack
run: docker-compose up -d
run: docker compose up -d

- name: Sanity Checks
run: |
WEB_OK=$(docker ps -aq --filter status="running" --filter name="geocity_web_1") && if [ -z "$WEB_OK" ]; then exit 1; fi
POSTGRES_OK=$(docker ps -aq --filter status="running" --filter name="geocity_postgres_1") && if [ -z "$POSTGRES_OK" ]; then exit 1; fi
- name: Stop web container
run: docker-compose stop web
run: docker compose stop web

- name: Run tests (with 2FA)
env:
ENABLE_2FA: "true"
run: |
docker-compose run --service-ports --name=web --rm --entrypoint="" web coverage run --source='.' ./manage.py test --settings=geocity.settings_test --keepdb
docker compose run --service-ports --name=web --rm --entrypoint="" web coverage run --source='.' ./manage.py test --settings=geocity.settings_test --keepdb
- name: Coverage report (with 2FA)
run: docker-compose run --rm --entrypoint="" web coverage report -m
run: docker compose run --rm --entrypoint="" web coverage report -m

- name: Run tests (without 2FA)
env:
ENABLE_2FA: "false"
run: |
docker-compose run --service-ports --name=web --rm --entrypoint="" web coverage run --source='.' ./manage.py test --settings=geocity.settings_test --keepdb
docker compose run --service-ports --name=web --rm --entrypoint="" web coverage run --source='.' ./manage.py test --settings=geocity.settings_test --keepdb
- name: Coverage report (without 2FA)
run: docker-compose run --rm --entrypoint="" web coverage report -m
run: docker compose run --rm --entrypoint="" web coverage report -m

- name: Upload test output images
if: failure()
Expand Down
50 changes: 25 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ git clone [email protected]:yverdon/geocity.git && cd geocity
# copy default config
cp -n .env.example .env
# start the stack
docker-compose up --build -d --remove-orphans
docker compose up --build -d --remove-orphans
```

**Load demo data**
Expand All @@ -25,7 +25,7 @@ There is some examples in same folder and you can create new ones.

The file will automatically appear once it's created.

`docker-compose run web python manage.py fixturize` is interactive and can use some arguments as :
`docker compose run web python manage.py fixturize` is interactive and can use some arguments as :

- `--help` : Shows description of command and available arguments
- `--list` : List available files to be used as fixtures
Expand All @@ -34,7 +34,7 @@ The file will automatically appear once it's created.

```bash
# Load demo data
docker-compose run web python manage.py fixturize
docker compose run web python manage.py fixturize
```

## Setting up production instance
Expand All @@ -59,19 +59,19 @@ CREATE EXTENSION unaccent;
Set the following variables as follow

```ini
COMPOSE_FILE=docker-compose.yml
COMPOSE_FILE=docker compose.yml
```

And review all other variables in order to fine tune your instance

### Deploying changes

New changes are deployed with the following command. :warning: **WARNING**: on PROD, docker-compose up will automatically
New changes are deployed with the following command. :warning: **WARNING**: on PROD, docker compose up will automatically
run migrations, collect static files, compile messages and update integrator permissions in the entrypoint.

```bash
# update the stack
docker-compose up --build -d --remove-orphans
docker compose up --build -d --remove-orphans
```

## Default Site
Expand Down Expand Up @@ -170,26 +170,26 @@ DEFAULT_SITE=localhost
Run tests in a the running container

```bash
docker-compose exec web python manage.py test --settings=geocity.settings_test
docker compose exec web python manage.py test --settings=geocity.settings_test
```

Run a specific test in the running container (adding the `--keepdb` flag speeds up iterations)

```bash
docker-compose exec web python manage.py test --settings=geocity.settings_test --keepdb geocity.apps.permits.tests.test_a_permit_request.PermitRequestTestCase.test_administrative_entity_is_filtered_by_tag
docker compose exec web python manage.py test --settings=geocity.settings_test --keepdb geocity.apps.permits.tests.test_a_permit_request.PermitRequestTestCase.test_administrative_entity_is_filtered_by_tag
```

Test for report generation will fail when run in the running web container, because they spawn a test server to allow other container to communicate with it. You can run them in their own container, but need first to stop the running web container.

```bash
docker-compose stop web
docker-compose run --service-ports --name=web --rm --entrypoint="" web python manage.py test --settings=geocity.settings_test --keepdb geocity.tests.reports
docker compose stop web
docker compose run --service-ports --name=web --rm --entrypoint="" web python manage.py test --settings=geocity.settings_test --keepdb geocity.tests.reports
```

These tests compare generated PDFs to expected PDFs. To regenerate the expected images, you need to provide the following env var to the docker-compose run command `-e TEST_UPDATED_EXPECTED_IMAGES=TRUE`. By definition, when doing so, tests will succeed, so don't forget to manually review the changes to the files.
These tests compare generated PDFs to expected PDFs. To regenerate the expected images, you need to provide the following env var to the docker compose run command `-e TEST_UPDATED_EXPECTED_IMAGES=TRUE`. By definition, when doing so, tests will succeed, so don't forget to manually review the changes to the files.

```bash
docker-compose run --service-ports --name=web --rm --entrypoint="" -e TEST_UPDATED_EXPECTED_IMAGES=TRUE web python manage.py test --settings=geocity.settings_test --keepdb geocity.tests.reports
docker compose run --service-ports --name=web --rm --entrypoint="" -e TEST_UPDATED_EXPECTED_IMAGES=TRUE web python manage.py test --settings=geocity.settings_test --keepdb geocity.tests.reports
```

### Linting
Expand Down Expand Up @@ -240,10 +240,10 @@ To install a new package, add it to `requirements.in`, without pinning it to a
specific version unless needed. Then run:

```
docker-compose exec web pip-compile requirements.in
docker-compose exec web pip-compile requirements_dev.in
docker-compose exec web pip install -r requirements.txt
docker-compose exec web pip install -r requirements_dev.txt
docker compose exec web pip-compile requirements.in
docker compose exec web pip-compile requirements_dev.in
docker compose exec web pip install -r requirements.txt
docker compose exec web pip install -r requirements_dev.txt
```

Make sure you commit both the `requirements.in` and the `requirements.txt` files.
Expand All @@ -254,17 +254,17 @@ And the `requirements_dev.in` and the `requirements_dev.txt` files.
To upgrade all the packages to their latest available version, run:

```
docker-compose exec web pip-compile -U requirements.in
docker-compose exec web pip install -r requirements.txt
docker compose exec web pip-compile -U requirements.in
docker compose exec web pip install -r requirements.txt
```

To upgrade only a specific package, use `pip-compile -P <packagename>`.
The following commands will upgrade Django to its latest version, making sure
it's compatible with other packages listed in the `requirements.in` file:

```
docker-compose exec web pip-compile -P django requirements.in
docker-compose exec web pip install -r requirements.txt
docker compose exec web pip-compile -P django requirements.in
docker compose exec web pip install -r requirements.txt
```

## Permissions and authentication
Expand Down Expand Up @@ -346,20 +346,20 @@ To run a migration, for example when the model has changed, execute
Then execute `manage.py migrate`.

```
docker-compose exec web python3 manage.py makemigrations <app_label>
docker-compose exec web python3 manage.py migrate <app_label> <migration_name>
docker compose exec web python3 manage.py makemigrations <app_label>
docker compose exec web python3 manage.py migrate <app_label> <migration_name>
```

For more information about Django's migrations, help is available at:

```
docker-compose exec web python3 manage.py makemigrations --help
docker-compose exec web python3 manage.py migrate --help
docker compose exec web python3 manage.py makemigrations --help
docker compose exec web python3 manage.py migrate --help
```

### Practical example

Note: prepend `docker-compose exec web ` to the following python calls if your app is containerized.
Note: prepend `docker compose exec web ` to the following python calls if your app is containerized.

`<app_label>`: this is set automatically depending on which model file is modified. In Geocity, it will always be "permits" => so there is nothing to specify.

Expand Down

0 comments on commit b8e4213

Please sign in to comment.