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

switch from docker-compose v1 to docker compose plugin v2 #153

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion features.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Main features

- Cookiecutter template allowing long term support using [Cruft](https://github.com/cruft/cruft) update mechanism
- [Docker](https://www.docker.com) and [docker-compose](https://docs.docker.com/compose/) for easy & simple (c) development and deployment
- [Docker](https://www.docker.com) and [docker compose](https://docs.docker.com/compose/) for easy & simple (c) development and deployment
- Latest [python](https://www.python.org) from 3.11 line
- Latest [Django](https://www.djangoproject.com) LTS release
- [Gunicorn](https://gunicorn.org) for running WSGI instances on prod
Expand Down
6 changes: 3 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ def rm_root_owned(session, dirpath):

@contextlib.contextmanager
def docker_up(session):
session.run("docker-compose", "up", "-d")
session.run("docker", "compose", "up", "-d")
yield
session.run("docker-compose", "down", "-v", "--remove-orphans")
session.run("docker", "compose", "down", "-v", "--remove-orphans")


@nox.session(python=PYTHON_DEFAULT_VERSION, tags=["crufted_project"])
Expand All @@ -181,7 +181,7 @@ def test_crufted_project(session):
@nox.session(python=PYTHON_DEFAULT_VERSION)
def cleanup_crufted_project(session):
if crufted_project.tmpdir:
# workaround for docker-compose creating root-owned files
# workaround for docker compose creating root-owned files
rm_root_owned(session, crufted_project.tmpdir.name)
crufted_project.tmpdir.cleanup()
crufted_project.tmpdir = None
14 changes: 2 additions & 12 deletions {{cookiecutter.repostory_name}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,16 @@ Skeleton of this project was generated with `cookiecutter-rt-django`, which some

# Base requirements

- docker
- docker-compose
- docker with [compose plugin](https://docs.docker.com/compose/install/linux/)
- python 3.11
- [pdm](https://pdm-project.org)
- [nox](https://nox.thea.codes)

# Setup development environment

```sh
# 1st tab
$ ./setup-dev.sh
```

```sh
# 2nd tab
docker-compose up
```

```sh
# 1st tab
docker compose up -d
cd app/src
pdm run manage.py wait_for_database --timeout 10
pdm run manage.py migrate
Expand Down
2 changes: 0 additions & 2 deletions {{cookiecutter.repostory_name}}/bin/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
set -o pipefail

if [ -z "${_COMMON_SH_LOADED:-}" ]; then
# Update PATH in case docker-compose is installed via PIP
# and this script was invoked from e.g. cron
PATH=/usr/local/sbin:/usr/local/bin:$PATH

check_env_vars() {
Expand Down
8 changes: 4 additions & 4 deletions {{cookiecutter.repostory_name}}/bin/prepare-os.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# Copyright 2020, Reef Technologies (reef.pl), All rights reserved.

DOCKER_BIN="$(command -v docker || true)"
DOCKER_COMPOSE_BIN="$(command -v docker-compose || true)"
DOCKER_COMPOSE_INSTALLED="$(docker compose version || true)"
SENTRY_CLI="$(command -v sentry-cli || true)"
B2_CLI="$(command -v b2 || true)"
AWS_CLI="$(command -v aws || true)"
JQ_BIN="$(command -v jq || true)"

if [ -x "${DOCKER_BIN}" ] && [ -x "${DOCKER_COMPOSE_BIN}" ] && [ -x "${SENTRY_CLI}" ] && [ -x "${B2_CLI}" ] && [ -x "${AWS_CLI}" ] && [ -x "${JQ_BIN}" ]; then
if [ -x "${DOCKER_BIN}" ] && [ -n "${DOCKER_COMPOSE_INSTALLED}" ] && [ -x "${SENTRY_CLI}" ] && [ -x "${B2_CLI}" ] && [ -x "${AWS_CLI}" ] && [ -x "${JQ_BIN}" ]; then
echo "\e[31mEverything required is already installed!\e[0m";
exit 0;
fi
Expand Down Expand Up @@ -51,8 +51,8 @@ if [ ! -x "${DOCKER_BIN}" ]; then
usermod -aG docker "$USER"
fi

if [ ! -x "${DOCKER_COMPOSE_BIN}" ]; then
apt-get -y install docker-ce docker-compose
if [ ! -x "${DOCKER_COMPOSE_INSTALLED}" ]; then
apt-get -y install docker-ce docker-compose-plugin
fi

if [ ! -x "${AWS_CLI}" ]; then
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.repostory_name}}/bin/run-manage-py.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
if [ "$(basename "$0")" == 'bin' ]; then
cd ..
fi
docker-compose exec app sh -c "python manage.py $*"
docker compose exec app sh -c "python manage.py $*"
16 changes: 8 additions & 8 deletions {{cookiecutter.repostory_name}}/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
#!/bin/sh -eux
# Copyright 2020, Reef Technologies (reef.pl), All rights reserved.
# Copyright 2024, Reef Technologies (reef.pl), All rights reserved.

if [ ! -f ".env" ]; then
echo "\e[31mPlease setup the environment first!\e[0m";
exit 1;
fi

DOCKER_BUILDKIT=0 docker-compose build
DOCKER_BUILDKIT=0 docker compose build

# Tag the first image from multi-stage app Dockerfile to mark it as not dangling
BASE_IMAGE=$(docker images --quiet --filter="label=builder=true" | head -n1)
docker image tag "${BASE_IMAGE}" {{cookiecutter.django_project_name}}/app-builder

# collect static files to external storage while old app is still running
# docker-compose run --rm app sh -c "python manage.py collectstatic --no-input"
# docker compose run --rm app sh -c "python manage.py collectstatic --no-input"

SERVICES=$(docker-compose ps --services 2>&1 > /dev/stderr \
SERVICES=$(docker compose ps --services 2>&1 > /dev/stderr \
| grep -v -e 'is not set' -e db -e redis)

# shellcheck disable=2086
docker-compose stop $SERVICES
docker compose stop $SERVICES

# start the app container only in order to perform migrations
docker-compose up -d db # in case it hasn't been launched before
docker-compose run --rm app sh -c "python manage.py wait_for_database --timeout 10; python manage.py migrate"
docker compose up -d db # in case it hasn't been launched before
docker compose run --rm app sh -c "python manage.py wait_for_database --timeout 10; python manage.py migrate"

# start everything
docker-compose up -d
docker compose up -d

# Clean all dangling images
docker images --quiet --filter=dangling=true \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,10 @@ build {
"curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg",
"echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null",
"sudo apt-get update",
"sudo apt-get install -y docker-ce docker-ce-cli containerd.io",
"sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin",
"sudo gpasswd -a ubuntu docker",
"sudo mkdir -p /etc/docker/",
"sudo service docker restart",

"sudo curl -L \"https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)\" -o /usr/local/bin/docker-compose",
"sudo chmod +x /usr/local/bin/docker-compose"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ write_files:
permissions: '0755'
content: |
apt-get clean && apt-get update && apt-get install -y ca-certificates curl gnupg lsb-release unzip jq rng-tools

curl https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip
unzip awscliv2.zip
./aws/install
Expand All @@ -20,14 +20,11 @@ write_files:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io
apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
gpasswd -a ubuntu docker
mkdir -p /etc/docker/
service docker restart

curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

- path: /home/ubuntu/cloud-init.sh
permissions: '0755'
content: |
Expand All @@ -51,7 +48,7 @@ write_files:


aws ecr get-login-password --region ${region} | docker login --username AWS --password-stdin "$AWS_ECR_BASE_URL"
docker-compose up -d
docker compose up -d

runcmd:
- chown -R ubuntu:ubuntu /home/ubuntu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ SECRET_KEY=${SECRET_KEY}

EOF

cd $${DEPLOY_DIR} && docker-compose up --build --detach
cd $${DEPLOY_DIR} && docker compose up --build --detach
echo "finishing custom cloud-init"
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Currently, `cookiecutter-rt-django` has no explicit versioning amd we purely rel

## [Unreleased]

* **BREAKING** Switched from `docker-compose` v1 script to `docker compose` v2 plugin (https://docs.docker.com/compose/cli-command/)
* **BREAKING** Added formatting with ruff.
* **BREAKING** Started using [pdm](https://github.com/pdm-project/pdm) for managing Python dependencies.
* **BREAKING** root of repository is used as docker build context instead of just `./app/`.
Expand All @@ -20,4 +21,4 @@ Currently, `cookiecutter-rt-django` has no explicit versioning amd we purely rel
* **BREAKING** Updated Python from 3.9 to 3.11
* **BREAKING** Updated Django from 3.2 to 4.2 (https://docs.djangoproject.com/en/4.2/releases/4.0/#backwards-incompatible-changes-in-4-0)
* **BREAKING** Updated django-cors-headers from 3.7 to 4.0 (https://github.com/adamchainz/django-cors-headers/blob/main/CHANGELOG.rst#400-2023-05-12)
* **BREAKING** Updated django-environ from 0.7 to 0.10 (https://django-environ.readthedocs.io/en/latest/changelog.html)
* **BREAKING** Updated django-environ from 0.7 to 0.10 (https://django-environ.readthedocs.io/en/latest/changelog.html)
Loading