Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use docker compose v2 plugin #1121

Merged
merged 3 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CONTRIB.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ You'll first have to start the Docker instance for the OpenOversight app using t

```shell
$ make start
docker-compose build
docker compose build
...
docker-compose up -d
docker compose up -d
[+] Running 2/0
✔ Container openoversight-postgres-1 Running 0.0s
✔ Container openoversight-web-1 Running
Expand Down Expand Up @@ -273,15 +273,15 @@ Next, in your terminal run `docker ps` to find the container id of the `openover
## Debugging OpenOversight - Use pdb with a test
If you want to run an individual test in debug mode, use the below command.
```shell
docker-compose run --rm web pytest --pdb -v tests/ -k <test_name_here>
docker compose run --rm web pytest --pdb -v tests/ -k <test_name_here>
```

where `<test_name_here>` is the name of a single test function, such as `test_ac_cannot_add_new_officer_not_in_their_dept`

Similarly, you can run all the tests in a file by specifying the file path:

```shell
docker-compose run --rm web pytest --pdb -v path/to/test/file
docker compose run --rm web pytest --pdb -v path/to/test/file
```

where `path/to/test/file` is the relative file path, minus the initial `OpenOversight`, such as
Expand Down
30 changes: 15 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,57 @@ default: build start create_db populate test stop clean
# Build containers
.PHONY: build
build:
docker-compose build
docker compose build

.PHONY: build_with_version
build_with_version: create_empty_secret
docker-compose build --build-arg MAKE_PYTHON_VERSION=$(PYTHON_VERSION)
docker compose build --build-arg MAKE_PYTHON_VERSION=$(PYTHON_VERSION)

.PHONY: test_with_version
test_with_version: build_with_version assets
touch OpenOversight/tests/coverage.xml
docker-compose run --rm web-test pytest --cov=OpenOversight --cov-report xml:OpenOversight/tests/coverage.xml --doctest-modules -n 4 --dist=loadfile -v OpenOversight/tests/
docker compose run --rm web-test pytest --cov=OpenOversight --cov-report xml:OpenOversight/tests/coverage.xml --doctest-modules -n 4 --dist=loadfile -v OpenOversight/tests/

# Run containers
.PHONY: start
start: build
docker-compose up -d
docker compose up -d

.PHONY: create_db
create_db: start
@until docker-compose exec postgres psql -h localhost -U openoversight -c '\l' postgres &>/dev/null; do \
@until docker compose exec postgres psql -h localhost -U openoversight -c '\l' postgres &>/dev/null; do \
echo "Postgres is unavailable - sleeping..."; \
sleep 1; \
done
@echo "Postgres is up"
## Creating database
docker-compose run --rm web alembic --config=./OpenOversight/migrations/alembic.ini stamp head
docker compose run --rm web alembic --config=./OpenOversight/migrations/alembic.ini stamp head

.PHONY: assets
assets:
docker-compose run --rm web yarn build
docker compose run --rm web yarn build

.PHONY: dev
dev: create_empty_secret build start create_db populate

# Build and run containers
.PHONY: populate
populate: create_db
@until docker-compose exec postgres psql -h localhost -U openoversight -c '\l' postgres &>/dev/null; do \
@until docker compose exec postgres psql -h localhost -U openoversight -c '\l' postgres &>/dev/null; do \
echo "Postgres is unavailable - sleeping..."; \
sleep 1; \
done
@echo "Postgres is up"
## Populate database with test data
docker-compose run --rm web python ./test_data.py -p
docker compose run --rm web python ./test_data.py -p

# Run tests
.PHONY: test
test: start
if [ -z "$(name)" ]; then \
docker-compose run --rm web-test pytest --cov --doctest-modules -n auto --dist=loadfile -v OpenOversight/tests/; \
docker compose run --rm web-test pytest --cov --doctest-modules -n auto --dist=loadfile -v OpenOversight/tests/; \
else \
docker-compose run --rm web-test pytest --cov --doctest-modules -v OpenOversight/tests/ -k $(name); \
docker compose run --rm web-test pytest --cov --doctest-modules -v OpenOversight/tests/ -k $(name); \
fi

.PHONY: lint
Expand All @@ -69,17 +69,17 @@ clean_assets:
# Stop containers
.PHONY: stop
stop:
docker-compose stop
docker compose stop

# Remove containers
.PHONY: clean
clean: clean_assets stop
docker-compose rm -f
docker compose rm -f

# Wipe database
.PHONY: clean_all
clean_all: clean stop
docker-compose down -v
docker compose down -v

# Build project documentation in live reload for editing
.PHONY: docs
Expand All @@ -97,7 +97,7 @@ help:

.PHONY: attach
attach:
docker-compose exec postgres psql -h localhost -U openoversight openoversight-dev
docker compose exec postgres psql -h localhost -U openoversight openoversight-dev

# This is needed to make sure docker doesn't create an empty directory, or delete that directory first
.PHONY: create_empty_secret
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ services:
secrets:
- source: service-account-key
target: /usr/src/app/service_account_key.json
user: "${UID:?Docker-compose needs UID set to the current user id number. Try 'export UID' and run docker-compose again}"
user: "${UID:?Docker-compose needs UID set to the current user id number. Try 'export UID' and run docker compose again}"
links:
- postgres:postgres
expose:
Expand Down
Loading