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
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
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
image: fastapi_celery_example_web
# '/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
# so if we change code on the host, code in the docker container will also be changed
volumes:

@ -1,9 +1,9 @@
from fastapi import APIRouter
from project.celery_utils import create_celery
users_router = APIRouter(
prefix="/users",
)
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
# pylint: disable=unused-argument
@task
def start_app(c):
"""Starts the app."""
def start_dev(c):
"""Starts the app in a docker-compose developer environment."""
print("Starting the developer environment...")
start_redis(c)
c.run("uvicorn main:app --reload", pty=True)
c.run("docker-compose -f docker-compose.yml up -d")
@task
def stop_dev(c):
"""Stops the developer environment."""
print("Stoping local development environment.")
c.run("docker-compose -f docker-compose.yml down")
@task
@ -52,8 +60,8 @@ def apply_migration(c, revision="head"):
c.run(f"alembic upgrade {revision}")
@task(help={"username": "Username of the application", "email": "User's email"})
def add_user(username="", email=""):
@task(help={"username": "A username", "email": "The user's email"})
def add_user(c, username="", email=""):
"Adds a dummy user to the application Database"
if not username or email:
raise ValueError("You must provide a username and email")
@ -67,3 +75,16 @@ def add_user(username="", email=""):
session.add(user)
session.commit()
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