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 to use docker compose #318

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
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"]
)
Loading