Skip to content

Commit

Permalink
Invoke gunicorn from the poetry-managed environment
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Feb 17, 2024
1 parent 822755a commit af2d144
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ This service is built to run on Heroku. Route traffic through a CDN to cache gen
You can also build this service as a container simply by running either of the following commands:

```bash
# Using Podman:
podman build --tag memegen --file Containerfile .

# Using Docker:
docker build --tag memegen --file Containerfile .

# Using Podman:
podman build --tag memegen --file Containerfile .
```

You can then run the container by running:

```bash
# Run the container
podman run -p 5000:5000 -e DOMAIN="set.your.domain" memegen
docker run --publish 5000:5000 --env DOMAIN="set.your.domain" memegen

# Validate functionality
$ curl http://127.0.0.1:5000/docs/ -sI
Expand All @@ -109,7 +109,7 @@ access-control-allow-origin: *

### Multi-Architecture Container Builds

If you want to build the image for multiple CPU architectures, you can either use `buildah` or `docker buildx`. Below are examples for both, and assume you're in the root of the memegen git repo.
If you want to build the image for multiple CPU architectures, you can either use `buildah` or `docker buildx`. Below are examples for both, and assume you're in the root of the repository:

#### System Requirements

Expand Down
18 changes: 8 additions & 10 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,41 @@ ARG ARG_PORT=5000
ARG ARG_MAX_REQUESTS=0
ARG ARG_MAX_REQUESTS_JITTER=0

# Prep everything
FROM docker.io/python:3.12.0-bullseye as build

# Install webp dependencies
# Install system dependencies
RUN apt update && apt install --yes webp cmake
RUN pip install poetry

# Create the memegen user
RUN useradd -md /opt/memegen -u 1000 memegen
USER memegen

# Set the Working Directory to /opt/memegen
# Set the working directory
WORKDIR /opt/memegen

# Copy Directories
# Copy project files
COPY --chown=memegen templates /opt/memegen/templates
COPY --chown=memegen scripts /opt/memegen/scripts
COPY --chown=memegen fonts /opt/memegen/fonts
COPY --chown=memegen docs /opt/memegen/docs
COPY --chown=memegen bin /opt/memegen/bin
COPY --chown=memegen app /opt/memegen/app

# Copy Specific Files
COPY --chown=memegen pyproject.toml /opt/memegen/
COPY --chown=memegen poetry.lock /opt/memegen/
COPY --chown=memegen CHANGELOG.md /opt/memegen/CHANGELOG.md

# Install Python Requirements
RUN pip install poetry && python -m poetry install --no-dev
# Install project dependencies
RUN poetry install --no-dev

# Set the environment variables
# Set environment variables
ENV PATH="/opt/memegen/.local/bin:${PATH}"
ENV PORT="${ARG_PORT:-5000}"
ENV MAX_REQUESTS="${ARG_MAX_REQUESTS:-0}"
ENV MAX_REQUESTS_JITTER="${ARG_MAX_REQUESTS_JITTER:-0}"

# Set the entrypoint
ENTRYPOINT gunicorn --bind "0.0.0.0:$PORT" \
ENTRYPOINT poetry run gunicorn --bind "0.0.0.0:$PORT" \
--worker-class uvicorn.workers.UvicornWorker \
--max-requests="$MAX_REQUESTS" \
--max-requests-jitter="$MAX_REQUESTS_JITTER" \
Expand Down

0 comments on commit af2d144

Please sign in to comment.