# -*- coding: utf-8 -*-
# iechelle - My Great Project description.
# Copyright (C) 2025 - CEA (Dinil Bose Palakkatharappil
# This file is part of iechelle <https://gitlab.com/dinilbose/iechelle>
# SPDX-License-Identifier:

ARG DEBIAN_NAME="bullseye"
ARG PYTHON_VERSION="3.12"
FROM python:${PYTHON_VERSION}-slim-${DEBIAN_NAME} AS base

WORKDIR /app
RUN apt-get update -qq \
      && apt upgrade --yes \
      && apt-get clean all \
      && rm -rf /var/lib/apt/lists/*

FROM base AS builder
ARG CI_JOB_TOKEN
ENV project_url=https://gitlab.com/dinilbose/iechelle.git

WORKDIR /app

RUN apt-get update -qq \
      && apt upgrade --yes \
      && apt-get -y --no-install-recommends install \
         build-essential \
         ca-certificates \
         gdb \
         gfortran \
         wget \
         file \
         apt-utils \
         git  \
      && apt-get clean all \
      && rm -r /var/lib/apt/lists/*

RUN pip install poetry && poetry config installer.max-workers 10 && poetry config virtualenvs.create false
COPY . .
RUN make

FROM python:3.12-slim-bullseye AS release
ARG BUILD_DATE
ARG VERSION
ARG DEBIAN_FRONTEND=noninteractive

WORKDIR /app

# Labels (based on OCI Image Format Specification)
LABEL \
    org.opencontainers.image.version=$VERSION \
    org.opencontainers.image.created=$BUILD_DATE \
    org.opencontainers.image.title="iechelle" \
    org.opencontainers.image.ref.name="iechelle" \
    org.opencontainers.image.description="My Great Project description." \
    org.opencontainers.image.licenses="Apache V2.0" \
    org.opencontainers.image.source="https://gitlab.com/dinilbose/iechelle" \
    org.opencontainers.image.documentation="https://gitlab.com/dinilbose/iechelle" \
    org.opencontainers.image.authors="Dinil Bose Palakkatharappil <dinilbose@gmail.com>"

# Get the installed libraries and application from the ealier stage
COPY --from=builder /usr/local/ /usr/local/

# Regenerate the shared-library cache
RUN ldconfig
