Skip to content

Commit

Permalink
Merge pull request #318 from torchbox/chore/docker-compose_to_docker_…
Browse files Browse the repository at this point in the history
…compose

Switch to use `docker compose`
  • Loading branch information
helenb authored Jan 14, 2025
2 parents 1a98458 + 8b22119 commit a7762e2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20 as frontend
FROM node:20 AS frontend

# Make build & post-install scripts behave as if we were in a CI environment (e.g. for logging verbosity purposes).
ARG CI=true
Expand All @@ -16,7 +16,7 @@ RUN npm run build:prod
# ones becase they use a different C compiler. Debian images also come with
# all useful packages required for image manipulation out of the box. They
# however weight a lot, approx. up to 1.5GiB per built image.
FROM python:3.11 as production
FROM python:3.11 AS production

ARG POETRY_INSTALL_ARGS="--no-dev"

Expand Down Expand Up @@ -91,10 +91,10 @@ COPY ./docker/bashrc.sh /home/tbx/.bashrc

# Run the WSGI server. It reads GUNICORN_CMD_ARGS, PORT and WEB_CONCURRENCY
# environment variable hence we don't specify a lot options below.
CMD gunicorn tbx.wsgi:application
CMD ["gunicorn", "tbx.wsgi:application"]

# These steps won't be run on production
FROM production as dev
FROM production AS dev

# Swap user, so the following tasks can be run as root
USER root
Expand All @@ -117,4 +117,4 @@ RUN curl https://raw.githubusercontent.com/nvm-sh/nvm/v${NVM_VERSION}/install.sh
COPY --chown=tbx --from=frontend ./node_modules ./node_modules

# do nothing forever - exec commands elsewhere
CMD tail -f /dev/null
CMD ["tail", "-f", "/dev/null"]
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.7'
services:
web:
build:
Expand Down
1 change: 0 additions & 1 deletion docker/docker-compose-frontend.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# A custom compose file for $FRONTEND=docker, which also binds frontend ports

version: '3.7' # NB synchronise with /docker-compose.yml
services:
web:
ports:
Expand Down
29 changes: 17 additions & 12 deletions fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

def dexec(cmd, service="web"):
return local(
"docker-compose exec -T {} bash -c {}".format(quote(service), quote(cmd))
"docker compose exec -T {} bash -c {}".format(quote(service), quote(cmd))
)


Expand All @@ -54,8 +54,8 @@ def build(c):
local("chown -R $USER:{} {}".format(group, directories_arg))
local("chmod -R 775 " + directories_arg)

local("docker-compose pull")
local("docker-compose build")
local("docker compose pull", pty=True)
local("docker compose build", pty=True)


@task
Expand All @@ -64,10 +64,11 @@ def start(c):
Start the development environment
"""
if FRONTEND == "local":
local("docker-compose up -d")
local("docker compose up --detach", pty=True)
else:
local(
"docker-compose -f docker-compose.yml -f docker/docker-compose-frontend.yml up -d"
"docker compose -f docker-compose.yml -f docker/docker-compose-frontend.yml up -d",
pty=True,
)


Expand All @@ -76,7 +77,7 @@ def stop(c):
"""
Stop the development environment
"""
local("docker-compose stop")
local("docker compose stop", pty=True)


@task
Expand All @@ -93,23 +94,23 @@ def destroy(c):
"""
Destroy development environment containers (database will lost!)
"""
local("docker-compose down")
local("docker compose down --volumes", pty=True)


@task
def sh(c, service="web"):
"""
Run bash in a local container
"""
subprocess.run(["docker-compose", "exec", service, "bash"])
subprocess.run(["docker", "compose", "exec", service, "bash"])


@task
def sh_root(c, service="web"):
"""
Run bash as root in the local web container.
"""
subprocess.run(["docker-compose", "exec", "--user=root", "web", "bash"])
subprocess.run(["docker", "compose", "exec", "--user=root", "web", "bash"])


@task
Expand All @@ -118,7 +119,8 @@ def psql(c, command=None):
Connect to the local postgres DB using psql
"""
cmd_list = [
"docker-compose",
"docker",
"compose",
"exec",
"db",
"psql",
Expand Down Expand Up @@ -458,7 +460,8 @@ def run_test(c):
"""
subprocess.call(
[
"docker-compose",
"docker",
"compose",
"exec",
"web",
"python",
Expand All @@ -475,4 +478,6 @@ def migrate(c):
"""
Run database migrations
"""
subprocess.run(["docker-compose", "run", "--rm", "web", "./manage.py", "migrate"])
subprocess.run(
["docker", "compose", "run", "--rm", "web", "./manage.py", "migrate"]
)

0 comments on commit a7762e2

Please sign in to comment.