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

Add dockerfile for prod deploy #83

Merged
merged 3 commits into from
Mar 21, 2024
Merged
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
44 changes: 44 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# All directory paths for COPY commands are relative to the build context

# Ensure this python version stays in sync with CI
FROM python:3.11-slim as base
WORKDIR /backend

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV POETRY_HOME="/opt/poetry"
ENV MYPYPATH="/app/src/stubs"

# Use bash as the shell for the build
# https://github.com/docker/for-linux/issues/408#issuecomment-414748815
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN set -eux && \
apt-get update && \
apt-get install -y \
build-essential \
curl \
libpq-dev \
python3-dev \
libmagic1

# https://python-poetry.org/docs
RUN pip install poetry

# install deps before copying project files so the cache is only invalidated
# when the deps change
COPY ./backend/pyproject.toml ./backend/poetry.lock ./
RUN poetry config virtualenvs.create false
RUN poetry install --no-root --only main

COPY ./backend .

EXPOSE 8080

###
# development image
###
FROM base as development

ENTRYPOINT ["bash", "./scripts/prod_entry_point.sh"]
10 changes: 10 additions & 0 deletions backend/scripts/prod_entry_point.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -e: fail on any nonzero exit status
# -u: fail if any referenced variables are not set
# -x: print commands before running them
# -o pipefail: fail if a command in a pipe has a nonzero exit code
set -euxo pipefail

# For now just create the db if it doesn't exist
# python -m scripts.run_migrations create

uvicorn server.main:app --host 0.0.0.0 --port 8080 --reload
Loading