docker composed local dev env

drew/tilt-local-dev
Drew Bednar 2 years ago
parent 6b432a750e
commit aa3dc3dba4

@ -24,7 +24,7 @@ RUN chmod +x /entrypoint
COPY ./compose/local/fastapi/start /start-web COPY ./compose/local/fastapi/start /start-web
RUN sed -i 's/\r$//g' /start-web RUN sed -i 's/\r$//g' /start-web
RUN chmod +x /start RUN chmod +x /start-web
COPY ./compose/local/fastapi/celery/worker/start /start-celeryworker COPY ./compose/local/fastapi/celery/worker/start /start-celeryworker
RUN sed -i 's/\r$//g' /start-celeryworker RUN sed -i 's/\r$//g' /start-celeryworker

@ -0,0 +1,6 @@
#!/bin/bash
set -o errexit
set -o nounset
celery -A main.celery worker --loglevel=info

@ -7,7 +7,7 @@ services:
dockerfile: ./compose/local/fastapi/Dockerfile dockerfile: ./compose/local/fastapi/Dockerfile
image: fastapi_celery_example_web image: fastapi_celery_example_web
# '/start' is the shell script used to run the service # '/start' is the shell script used to run the service
command: /start command: /start-web
# this volume is used to map the files and folders on the host to the container # this volume is used to map the files and folders on the host to the container
# so if we change code on the host, code in the docker container will also be changed # so if we change code on the host, code in the docker container will also be changed
volumes: volumes:

@ -1,9 +1,9 @@
from fastapi import APIRouter from fastapi import APIRouter
from project.celery_utils import create_celery
users_router = APIRouter( users_router = APIRouter(
prefix="/users", prefix="/users",
) )
from . import models, tasks # noqa from . import models, tasks # noqa
from project.celery_utils import create_celery

@ -3,13 +3,21 @@ A set of `invoke` helper commands used for this project.
""" """
from invoke import task from invoke import task
# pylint: disable=unused-argument
@task @task
def start_app(c): def start_dev(c):
"""Starts the app.""" """Starts the app in a docker-compose developer environment."""
print("Starting the developer environment...") print("Starting the developer environment...")
start_redis(c) c.run("docker-compose -f docker-compose.yml up -d")
c.run("uvicorn main:app --reload", pty=True)
@task
def stop_dev(c):
"""Stops the developer environment."""
print("Stoping local development environment.")
c.run("docker-compose -f docker-compose.yml down")
@task @task
@ -52,8 +60,8 @@ def apply_migration(c, revision="head"):
c.run(f"alembic upgrade {revision}") c.run(f"alembic upgrade {revision}")
@task(help={"username": "Username of the application", "email": "User's email"}) @task(help={"username": "A username", "email": "The user's email"})
def add_user(username="", email=""): def add_user(c, username="", email=""):
"Adds a dummy user to the application Database" "Adds a dummy user to the application Database"
if not username or email: if not username or email:
raise ValueError("You must provide a username and email") raise ValueError("You must provide a username and email")
@ -67,3 +75,16 @@ def add_user(username="", email=""):
session.add(user) session.add(user)
session.commit() session.commit()
session.close() session.close()
@task(
help={
"requirements": "Path to a pip requirements file.",
"dev_requirements": "Path to a pip dev requirements file.",
}
)
def sync_env(
c, requirements="requirements.txt", dev_requirements="dev-requirements.txt"
):
"""Uses pip-sync to sync the local virtualenv."""
c.run(f"pip-sync {requirements} {dev_requirements}")

Loading…
Cancel
Save