Skip to content

Commit

Permalink
Replace docker-compose cli command with docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
marteinn committed Sep 3, 2024
1 parent 3ccdc8a commit 44fcc08
Show file tree
Hide file tree
Showing 30 changed files with 96 additions and 95 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@ jobs:
- name: Run cookiecutter
run: |
cookiecutter . --no-input experimental_use_app_router=${{ matrix.experimental_use_app_router.value }}
- name: Create docker-compose config for running boilerplate tests
- name: Create docker compose config for running boilerplate tests
run: |
cp docker-compose-ci.yml Company-Project/docker-compose-ci.yml
- name: Build image
run: |
cd Company-Project
chmod +x src/docker-entrypoint.sh
docker-compose -f docker-compose-ci.yml build
docker compose -f docker-compose-ci.yml build
- name: Verify backend scaffolder
run: |
cd Company-Project
set -x
docker-compose -f docker-compose-ci.yml run --rm python python manage.py new_page --name=Article
docker compose -f docker-compose-ci.yml run --rm python python manage.py new_page --name=Article
- name: Run tests on container
run: |
cd Company-Project
docker-compose -f docker-compose-ci.yml run --rm python test
docker-compose -f docker-compose-ci.yml run --rm python typecheck
docker-compose -f docker-compose-ci.yml run --rm python lint
docker compose -f docker-compose-ci.yml run --rm python test
docker compose -f docker-compose-ci.yml run --rm python typecheck
docker compose -f docker-compose-ci.yml run --rm python lint
- name: Run frontend tests
run: |
cd Company-Project/frontend
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix 'the input device is not a TTY' error in pre-push githook
- Make sure host query arg are supported when loading redirects from api
- Replace deprecated ruff lint options
- Replace docker-compose cli command with docker-compose

### Removed

Expand Down
2 changes: 1 addition & 1 deletion Company-Project/.githooks/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

# Make sure python code are black formatted
docker-compose run --rm -T python black --exclude "/(\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|_build|buck-out|build|dist|migrations)/" ./ --check
docker compose run --rm -T python black --exclude "/(\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|_build|buck-out|build|dist|migrations)/" ./ --check
2 changes: 1 addition & 1 deletion Company-Project/.githooks/pre-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
# $1 -- Name of the remote to which the push is being done
# $2 -- URL to which the push is being done

docker-compose run -T --rm python test
docker compose run -T --rm python test

exit $?
14 changes: 7 additions & 7 deletions Company-Project/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ init:
ln -nfs $(PWD)/.githooks/bump-version.sh .git/hooks/post-flow-hotfix-start
mkdir -p src/media
mkdir -p src/static
docker-compose up -d
docker compose up -d
cd frontend && npm install && npm run dev

test:
docker-compose run --rm python test
docker compose run --rm python test
cd frontend && npm run test

fixcode:
docker-compose exec python black --exclude "/(\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|_build|buck-out|build|dist|migrations)/" ./
docker compose exec python black --exclude "/(\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|_build|buck-out|build|dist|migrations)/" ./

translate:
docker-compose exec python bash -c "python manage.py makemessages -l sv_SE --ignore=venv"
docker compose exec python bash -c "python manage.py makemessages -l sv_SE --ignore=venv"

coverage:
docker-compose exec python coverage run -m pytest --ds=pipit.settings.test
docker-compose exec python coverage html
docker compose exec python coverage run -m pytest --ds=pipit.settings.test
docker compose exec python coverage html

typecheck:
docker-compose run --rm python typecheck
docker compose run --rm python typecheck
16 changes: 8 additions & 8 deletions Company-Project/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
6. Start project
```
docker-compose up
docker compose up
```
7. Install and start frontend
Expand Down Expand Up @@ -127,10 +127,10 @@ You should now be able to attach to the running Django server instance.
### pdb in Docker
To use pdb you need to start the container with service-ports exposed instead of docker-compose up. This will create a container called `<project_prefix>_python_run_1`
To use pdb you need to start the container with service-ports exposed instead of docker compose up. This will create a container called `<project_prefix>_python_run_1`
```
docker-compose run --rm --service-ports python
docker compose run --rm --service-ports python
```
Expand Down Expand Up @@ -195,7 +195,7 @@ Read the instructions for [Mac OS](https://docs.docker.com/docker-for-mac/instal
### How do I run the test suite locally?

```
docker-compose run --rm python test
docker compose run --rm python test
```


Expand All @@ -206,13 +206,13 @@ To run manage.py commands in docker is pretty straightforward, instead of target
- Example: Create migrations

```
docker-compose exec python ./manage.py makemigrations
docker compose exec python ./manage.py makemigrations
```

- Example: Run migrations

```
docker-compose exec python ./manage.py migrate
docker compose exec python ./manage.py migrate
```

We also have a manage.sh script to make running management commands easier.
Expand All @@ -227,8 +227,8 @@ We also have a manage.sh script to make running management commands easier.
First update your requirements/base.txt, then rebuild your container:

```
docker-compose stop
docker-compose up --build
docker compose stop
docker compose up --build
```


Expand Down
2 changes: 1 addition & 1 deletion Company-Project/docker-compose.override.local.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# docker-compose override for running python with a local interpreter
# docker compose override for running python with a local interpreter
services:
web:
depends_on: []
Expand Down
6 changes: 3 additions & 3 deletions Company-Project/scripts/enable_ssl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ mkcert --cert-file docker/files/certs/cert.pem --key-file docker/files/certs/cer
sed -i.bak 's/\#mkcert\ //g' docker/files/config/nginx.conf.template
rm -f docker/files/config/nginx.conf.template.bak

docker-compose stop
docker-compose rm -f web
docker-compose up -d
docker compose stop
docker compose rm -f web
docker compose up -d

echo "---"
echo "Done!"
Expand Down
2 changes: 1 addition & 1 deletion Company-Project/scripts/manage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ set -e
# Example usage `scripts/manage.sh migrate`

manage_command="./manage.py $@"
docker-compose exec python $manage_command
docker compose exec python $manage_command
2 changes: 1 addition & 1 deletion Company-Project/scripts/pip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ set -e
# Example usage `scripts/pip.sh install requests`

pip_command="pip $@"
docker-compose exec python $pip_command
docker compose exec python $pip_command
8 changes: 4 additions & 4 deletions Company-Project/scripts/prod_to_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ scp $SSH_HOST:/tmp/db-dump.sql $docker_dir/files/db-dumps/db-dump.sql
ssh $SSH_HOST "rm /tmp/db-dump.sql"

echo "Rebuilding database..."
docker-compose stop db
docker-compose rm -f db
docker-compose up -d db
docker compose stop db
docker compose rm -f db
docker compose up -d db

echo "Waiting for database ($DB_WAIT_TIME seconds)..."
sleep $DB_WAIT_TIME
Expand All @@ -46,7 +46,7 @@ if [[ $use_local_python == 1 ]]
then
manage_command="$src_dir/manage.py"
else
manage_command="docker-compose exec python ./manage.py"
manage_command="docker compose exec python ./manage.py"
fi

echo "Adjusting database..."
Expand Down
8 changes: 4 additions & 4 deletions Company-Project/scripts/restore_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ scripts_dir="$(cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd)"
docker_dir=${scripts_dir}/../docker

echo "Rebuilding docker containers."
docker-compose stop db
docker-compose rm -f db
docker-compose up -d db
docker compose stop db
docker compose rm -f db
docker compose up -d db

echo "Waiting for database ($DB_WAIT_TIME seconds)..."
sleep $DB_WAIT_TIME
Expand All @@ -29,7 +29,7 @@ if $use_local_python;
then
manage_command="$src_dir/manage.py"
else
manage_command="docker-compose exec python ./manage.py"
manage_command="docker compose exec python ./manage.py"
fi

echo "Adjusting database..."
Expand Down
8 changes: 4 additions & 4 deletions Company-Project/scripts/stage_to_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ scp $SSH_HOST:/tmp/db-dump.sql $docker_dir/files/db-dumps/db-dump.sql
ssh $SSH_HOST "rm /tmp/db-dump.sql"

echo "Rebuilding database..."
docker-compose stop db
docker-compose rm -f db
docker-compose up -d db
docker compose stop db
docker compose rm -f db
docker compose up -d db

echo "Waiting for database ($DB_WAIT_TIME seconds)..."
sleep $DB_WAIT_TIME
Expand All @@ -46,7 +46,7 @@ if [[ $use_local_python == 1 ]]
then
manage_command="$src_dir/manage.py"
else
manage_command="docker-compose exec python ./manage.py"
manage_command="docker compose exec python ./manage.py"
fi

echo "Adjusting database..."
Expand Down
4 changes: 2 additions & 2 deletions Company-Project/scripts/store_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
# to allow you to rebuild the db container without data-loss.
#
# Or if you want to send it to a friend you could just send it over and if they put
# it in docker/files/db-dumps it will be read after docker-compose build -- Sharing is caring.
# it in docker/files/db-dumps it will be read after docker compose build -- Sharing is caring.

docker-compose exec db bash -c "export PGUSER=postgres && pg_dump app --no-owner > /shared/export.sql"
docker compose exec db bash -c "export PGUSER=postgres && pg_dump app --no-owner > /shared/export.sql"
4 changes: 2 additions & 2 deletions docs/adding-sentry.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ Before you get started, make sure you have the following:
- We are done editing `python.env`, save the file
- Restart your project
```
docker-compose stop && docker-compose up
docker compose stop && docker compose up
```
- Open the python repl in docker
```
docker-compose exec python -c "./manage.py shell"
docker compose exec python -c "./manage.py shell"
```
- Trigger a divison by zero error
```
Expand Down
12 changes: 6 additions & 6 deletions docs/backend-developer-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Make sure you follow the install instructions in the project README.md, in short

## Running docker

To run docker, run `docker-compose up` from the project root (the folder contains a `docker-compose.yml` file).
To run docker, run `docker compose up` from the project root (the folder contains a `docker compose.yml` file).

This will create the following docker containers:

Expand All @@ -94,7 +94,7 @@ When all the containers are running, open your browser and navigate to either:
Start by generating a new page in Wagtail, we have a management command to simplify the process called `new_page`.

```
docker-compose exec python ./manage.py new_page --name=About
docker compose exec python ./manage.py new_page --name=About
```

This will create the following files:
Expand Down Expand Up @@ -159,13 +159,13 @@ class AboutPage(HeadlessPreviewMixin, BasePage):
After adding our field we need to create a new database migration.

```
docker-compose exec python ./manage.py makemigrations
docker compose exec python ./manage.py makemigrations
```

We also need to run the migration so database changes are applied.

```
docker-compose exec python ./manage.py migrate
docker compose exec python ./manage.py migrate
```

Now login to the Wagtail cms at `http://blog.acme.com.test:8081/wt/cms` using:
Expand Down Expand Up @@ -195,7 +195,7 @@ def test_that_company_name_are_retuned(self):
Now run it.

```
docker-compose exec python pytest
docker compose exec python pytest
```

Oh no - It fails. But that's all right, that means we need to add `company_name` to our serializer.
Expand All @@ -221,7 +221,7 @@ class AboutPageSerializer(BasePageSerializer):
Now run the tests again.

```
docker-compose exec python pytest
docker compose exec python pytest
```

Tests pass.
Expand Down
8 changes: 4 additions & 4 deletions docs/getting-started-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ services:
The Django application will be served through Docker. To start it, run the following from the project root:
```
docker-compose up
docker compose up
```

When Docker is finished, your app should be up and running on the `docker_web_port` specified in the wizard (`http://localhost:8081` in our example).
Expand All @@ -117,7 +117,7 @@ For convenience we are providing a script for that, so instead of running the us
```
If you rather want to work within a shell in the docker container, you can do so:
```
docker-compose exec python bash
docker compose exec python bash
```

### Installing requirements need to happen `within` the docker environment
Expand All @@ -129,7 +129,7 @@ Like for management commands, we provide a script to for this. When adding requi
If you prefer, you can start a shell in the container and go on as you are used to:

```
docker-compose exec python bash
docker compose exec python bash
```


Expand Down Expand Up @@ -186,7 +186,7 @@ For us to support local certificates you need to install a tool called [mkcert](
sed -i.bak 's/\#mkcert\ //g' docker/files/config/nginx.conf && rm -f docker/files/config/nginx.conf.bak
```
- Remove your docker container `web` (`docker-compose stop && docker-compose rm -f web`)
- Remove your docker container `web` (`docker compose stop && docker compose rm -f web`)
- Restart docker
...there is also a alternative way by running `./scripts/enable_ssl.sh`
Expand Down
6 changes: 3 additions & 3 deletions docs/running-python-locally.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ Lets start with us saying that docker is a great tool. But in all this greatness

## Setup

Begin by adding our included docker-compose override, it will change the `PYTHON_HOST` environment variable in `docker-compose.yml` for the container `web` so we use a local running python interpreter instead of the docker version. This override will also replace the python container with a no-op container.
Begin by adding our included docker compose override, it will change the `PYTHON_HOST` environment variable in `docker-compose.yml` for the container `web` so we use a local running python interpreter instead of the docker version. This override will also replace the python container with a no-op container.

```
cp docker-compose.override.local.yml docker-compose.override.yml
```

If you have a existing web container, remove it `docker-compose rm web`
If you have a existing web container, remove it `docker compose rm web`

Create a custom .env file for your local db instance

Expand Down Expand Up @@ -57,7 +57,7 @@ Tip: If you are having issues installing `psycopg2` because your are lacking pos
Start docker (without the `python` container)

```
docker-compose up db web
docker compose up db web
```

And then finally start your python server
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.project_name}}/.githooks/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

# Make sure python code are black formatted
docker-compose run --rm -T python black --exclude "/(\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|_build|buck-out|build|dist|migrations)/" ./ --check
docker compose run --rm -T python black --exclude "/(\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|_build|buck-out|build|dist|migrations)/" ./ --check
2 changes: 1 addition & 1 deletion {{cookiecutter.project_name}}/.githooks/pre-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
# $1 -- Name of the remote to which the push is being done
# $2 -- URL to which the push is being done

docker-compose run -T --rm python test
docker compose run -T --rm python test

exit $?
Loading

0 comments on commit 44fcc08

Please sign in to comment.