Skip to content

Commit

Permalink
🐳 Dockerfile and builder Action
Browse files Browse the repository at this point in the history
  • Loading branch information
mrharpo committed Aug 2, 2024
1 parent 7f6e9cb commit e9aecc4
Show file tree
Hide file tree
Showing 4 changed files with 309 additions and 299 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: 🪂 Deploy

on:
push:
branches:
- main
pull_request:
branches:
- main
release:
types: [published, edited, prereleased]
merge_group:
workflow_dispatch:

jobs:
build:
name: 🔨 Build and deploy docker image
uses: WGBH-MLA/.github/.github/workflows/build.yml@main
with:
target: production
69 changes: 56 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,67 @@
###########################
# 'base' build stage, common to all build stages
###########################
FROM python as base
FROM python:3.11-slim as base

# Set working dir to /app, where all code lives.
WORKDIR /app
RUN pip install -U pip
RUN pip install -U pip pdm

# Copy app code to container
COPY pyproject.toml pdm.lock ./
COPY pyproject.toml pdm.lock README.md ./
COPY organ organ

# add app directories
ADD organ/ organ/
ADD static/ static/
ADD templates/ templates/
# Copy migration files
# COPY alembic.ini ./
# COPY migrations migrations

# Install PDM dependency manager
RUN pip install pdm

###########################
# 'dev' build stage
###########################
FROM base as dev
# Configure pdm to instal dependencies into ./__pypyackages__/
RUN pdm config python.use_venv false
# Configure python to use pep582 with local __pypyackages__
ENV PYTHONPATH=/usr/local/lib/python3.11/site-packages/pdm/pep582
ENV PATH=$PATH:/app/__pypackages__/3.11/bin/
# Add local packages to $PATH
ENV PATH=/app/__pypackages__/3.11/bin/:$PATH

# Install dev dependencies with pdm
RUN pdm install -G dev
# Start dev server.
CMD uvicorn organ.app:app --host 0.0.0.0 --reload --log-level debug


###########################
# 'build' build stage for production
############################
FROM base as build
RUN apt update && apt install -y gcc libpq-dev git

RUN pdm config venv.with_pip True
RUN pdm install -G production

# Install pip into the virtual environment
RUN /app/.venv/bin/python -m ensurepip

###########################
# 'production' final production image
############################
FROM python:3.11-slim as production
WORKDIR /app

RUN apt update && apt install -y libpq-dev
RUN apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
COPY --from=build /app/ /app/
COPY templates templates
COPY static static

ENV organ_ENV=production
ENV PATH="/app/.venv/bin:$PATH"

RUN pdm install -v
EXPOSE 8000

# CMD gunicorn chowda:app -b 0.0.0.0:8000 -w 2 --worker-class uvicorn.workers.UvicornWorker
CMD uvicorn organ:main --host 0.0.0.0 --port 8000
CMD gunicorn organ.app:app -b 0.0.0.0:8000 -w 2 --worker-class uvicorn.workers.UvicornWorker
Loading

0 comments on commit e9aecc4

Please sign in to comment.