You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

45 lines
1.3 KiB

# Use an official Python runtime as a parent image
FROM python:3.8-alpine3.18 as builder
RUN apk update && apk upgrade
RUN apk add --no-cache --virtual .build-deps build-base git
RUN apk add --upgrade --no-cache bash sqlite libffi-dev tzdata
ENV TZ America/New_York
ENV PYTHONUNBUFFERED 1
# Set the working directory in the container to /app
WORKDIR /app
RUN mkdir -p /app/instance/data
# Copy the current directory contents into the container at /app
COPY app.py /app
COPY requirements.txt /app
COPY models.py /app
COPY init_db.py /app/init_db.py
# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
RUN apk del .build-deps
# ---- Production Stage ----
FROM python:3.8-alpine3.18 as production
# Create a user to run our application
RUN adduser -D myuser -u 1000
# Copy the dependencies and installed packages from the builder image
WORKDIR /app
COPY --from=builder /app /app
COPY --from=builder /usr/local /usr/local
COPY --from=builder /usr/bin /usr/bin
RUN chown -R myuser:myuser /app
# Switch to the created user
USER myuser
# Start gunicorn with the appropriate options
# Without "2>&1" the gunicorn internal logging shows in 'docker logs' but doesn't go to stdout like our 'printf' commands.
CMD ["sh", "-c", "gunicorn -b 0.0.0.0:3000 --log-level=debug --workers=1 app:app 2>&1"]