Skip to content

Commit a7762e2

Browse files
authored
Merge pull request #318 from torchbox/chore/docker-compose_to_docker_compose
Switch to use `docker compose`
2 parents 1a98458 + 8b22119 commit a7762e2

4 files changed

Lines changed: 22 additions & 19 deletions

File tree

Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:20 as frontend
1+
FROM node:20 AS frontend
22

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

2121
ARG POETRY_INSTALL_ARGS="--no-dev"
2222

@@ -91,10 +91,10 @@ COPY ./docker/bashrc.sh /home/tbx/.bashrc
9191

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

9696
# These steps won't be run on production
97-
FROM production as dev
97+
FROM production AS dev
9898

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

119119
# do nothing forever - exec commands elsewhere
120-
CMD tail -f /dev/null
120+
CMD ["tail", "-f", "/dev/null"]

docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: '3.7'
21
services:
32
web:
43
build:

docker/docker-compose-frontend.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# A custom compose file for $FRONTEND=docker, which also binds frontend ports
22

3-
version: '3.7' # NB synchronise with /docker-compose.yml
43
services:
54
web:
65
ports:

fabfile.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

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

4343

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

57-
local("docker-compose pull")
58-
local("docker-compose build")
57+
local("docker compose pull", pty=True)
58+
local("docker compose build", pty=True)
5959

6060

6161
@task
@@ -64,10 +64,11 @@ def start(c):
6464
Start the development environment
6565
"""
6666
if FRONTEND == "local":
67-
local("docker-compose up -d")
67+
local("docker compose up --detach", pty=True)
6868
else:
6969
local(
70-
"docker-compose -f docker-compose.yml -f docker/docker-compose-frontend.yml up -d"
70+
"docker compose -f docker-compose.yml -f docker/docker-compose-frontend.yml up -d",
71+
pty=True,
7172
)
7273

7374

@@ -76,7 +77,7 @@ def stop(c):
7677
"""
7778
Stop the development environment
7879
"""
79-
local("docker-compose stop")
80+
local("docker compose stop", pty=True)
8081

8182

8283
@task
@@ -93,23 +94,23 @@ def destroy(c):
9394
"""
9495
Destroy development environment containers (database will lost!)
9596
"""
96-
local("docker-compose down")
97+
local("docker compose down --volumes", pty=True)
9798

9899

99100
@task
100101
def sh(c, service="web"):
101102
"""
102103
Run bash in a local container
103104
"""
104-
subprocess.run(["docker-compose", "exec", service, "bash"])
105+
subprocess.run(["docker", "compose", "exec", service, "bash"])
105106

106107

107108
@task
108109
def sh_root(c, service="web"):
109110
"""
110111
Run bash as root in the local web container.
111112
"""
112-
subprocess.run(["docker-compose", "exec", "--user=root", "web", "bash"])
113+
subprocess.run(["docker", "compose", "exec", "--user=root", "web", "bash"])
113114

114115

115116
@task
@@ -118,7 +119,8 @@ def psql(c, command=None):
118119
Connect to the local postgres DB using psql
119120
"""
120121
cmd_list = [
121-
"docker-compose",
122+
"docker",
123+
"compose",
122124
"exec",
123125
"db",
124126
"psql",
@@ -458,7 +460,8 @@ def run_test(c):
458460
"""
459461
subprocess.call(
460462
[
461-
"docker-compose",
463+
"docker",
464+
"compose",
462465
"exec",
463466
"web",
464467
"python",
@@ -475,4 +478,6 @@ def migrate(c):
475478
"""
476479
Run database migrations
477480
"""
478-
subprocess.run(["docker-compose", "run", "--rm", "web", "./manage.py", "migrate"])
481+
subprocess.run(
482+
["docker", "compose", "run", "--rm", "web", "./manage.py", "migrate"]
483+
)

0 commit comments

Comments
 (0)