FROM 086679231553.dkr.ecr.us-east-1.amazonaws.com/docker-parent-images:python313 AS base

ENV         POETRY_VIRTUALENVS_IN_PROJECT=0
ENV         POETRY_VIRTUALENVS_CREATE=0

USER        root

# Install locales
RUN         apt-get update \
            && apt-get -y upgrade \
            && apt-get -y install locales locales-all \
            && apt-get clean all \
            && rm -rf /var/lib/apt/lists/*

# Install poetry
RUN         pip install --no-cache --upgrade pip && \
            pip install --no-cache poetry==2.3.3

USER        worker

# Switch to the app directory
WORKDIR     /var/app
COPY        pyproject.toml poetry.lock ./

################################
### Generate poetry lockfile ###
################################
FROM        base AS poetry-update

USER        root

WORKDIR     /var/app
COPY        scripts/update-poetry-lock.sh ./scripts/
ENTRYPOINT  ["scripts/update-poetry-lock.sh"]

##############################
### Build image for deploy ###
##############################
FROM        base AS deploy

USER        root
RUN         poetry install --only main --no-root --no-cache
USER        worker

WORKDIR     /var/app
COPY        src ./src

EXPOSE      8080

ENTRYPOINT  ["src/entrypoint.sh"]

#################################
### Build image for unit-lint ###
#################################
FROM        base AS unit-lint

USER        root
RUN         poetry install --no-root --no-cache --extras dev
USER        worker

WORKDIR     /var/app
COPY        src ./src
COPY        tests ./tests
COPY        scripts/unit-lint.sh ./scripts/

ENTRYPOINT  ["scripts/unit-lint.sh"]

########################################
### Build image for integration-test ###
########################################
FROM        base AS integration-test

USER        root
RUN         poetry install --no-root --no-cache --extras dev
USER        worker

WORKDIR     /var/app
COPY        src ./src
COPY        tests ./tests
COPY        scripts/integration.sh ./scripts/

ENTRYPOINT  ["scripts/integration.sh"]
