# Dockerfile

# base stage
FROM python:3.11-slim-bullseye AS base

# Update and install common packages
RUN apt-get update && apt-get install gcc curl -y

WORKDIR /var/app

# Create and configure virtualenv and uwsgi
RUN python3 -m venv env
RUN env/bin/python3 -m pip install -q -U pip setuptools wheel
RUN env/bin/python3 -m pip install -q uwsgi
RUN useradd uwsgi -s /bin/false

# Add application code
COPY application.py requirements.txt ./
COPY playlist ./playlist

# Install deps
RUN env/bin/python3 -m pip install --use-pep517 -I -r requirements.txt

# deploy stage - build image for live deployment
FROM        base AS deploy

# Add entrypoint

RUN        mkdir /var/app/.snowflake
RUN        chmod 777 /var/app/.snowflake
ENV        SNOWFLAKE_HOME=/var/app/

COPY        uwsgi-start.sh /
RUN         chmod +x /uwsgi-start.sh
ENTRYPOINT ["/uwsgi-start.sh"]

EXPOSE     8080

# pull-request checks stage
FROM        base AS pr_tests

# git because precommit requires it
RUN apt-get install make git -y

COPY requirements-dev.txt dev.py Makefile ./

# copy tests
COPY tests ./tests

# copy files required for pre-commit
COPY .git ./.git
COPY .pre-commit-config.yaml pyproject.toml mypy.ini .flake8 ./

ENTRYPOINT  ["make", "pull_request_job"]