ARG FUNCTION_DIR="/home/sbx_user1051/"
ARG RUNTIME_VERSION="3.8"
 
FROM apache/spark:v3.2.2 as build-image
 
USER root
 
RUN apt-get update
 
# Set environment variables for Spark and Hadoop
ENV SPARK_HOME=/opt/spark
ENV PATH=$PATH:$SPARK_HOME/bin
ENV PYSPARK_PYTHON=python3
ENV PYTHONPATH=$SPARK_HOME/python:$SPARK_HOME/python/lib/py4j-0.10.9-src.zip
 
RUN apt-get update
RUN apt-get install -y g++
RUN apt-get install -y make
RUN apt-get install -y cmake
RUN apt-get install -y unzip
RUN apt-get install -y libcurl4-openssl-dev
 
RUN apt-get install -y python3
RUN apt-get install -y wget gcc python
RUN apt-get install -y python3-wheel
RUN apt-get install -y python3-setuptools
RUN apt-get install -y python3-dev
RUN apt-get install -y python3-setuptools
RUN apt-get install -y python3-pip
RUN apt-get install -y pip xdg-utils lynx
 
# Include global args in this stage of the build
ARG FUNCTION_DIR
ARG RUNTIME_VERSION

RUN useradd -ms /bin/bash sbx_user1051
RUN usermod -aG 0 sbx_user1051
RUN usermod -u 993 sbx_user1051

USER 993

WORKDIR FUNCTION_DIR

# Create the function directory
# RUN mkdir -p ${FUNCTION_DIR}
RUN mkdir -p conf
# Add handler function
COPY --chown=993:root lambda_handler.py .
# ${FUNCTION_DIR}
# Add conf/ directory
COPY --chown=993:root conf conf
# Install Kedro pipeline
COPY --chown=993:root dist/risk_stream-0.1-py3-none-any.whl .
RUN python3 -m pip install --no-cache-dir risk_stream-0.1-py3-none-any.whl 
# --target ${FUNCTION_DIR}
# Install Lambda Runtime Interface Client for Python
RUN python3 -m pip install --no-cache-dir awslambdaric 
# --target ${FUNCTION_DIR}
 
# Stage 3 - final runtime image
# Grab a fresh copy of the Python image
# FROM python:${RUNTIME_VERSION}-buster
# FROM apache/spark:v3.2.2
 
# Include global arg in this stage of the build
# ARG FUNCTION_DIR
# Set working directory to function root directory

COPY --chown=993:root S3 .

# RUN chmod 777 -R .
# Copy in the built dependencies
COPY --chown=993:root src/requirements.txt requirements.txt
RUN pip install -r requirements.txt

# RUN chown -R sbx_user1051 /home/app/ \
    # && chmod -R 775 /home/app/ \
    # && chown -R sbx_user1051:root /home/app/

RUN export AWS_ACCESS_KEY_ID=
RUN export export AWS_SECRET_ACCESS_KEY=
# COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR}
COPY --chown=993:root prueba.sh .

USER root
RUN chown -R 993:root /opt/spark/
RUN chmod 775 /opt/spark/

USER 993
ENTRYPOINT [ "/usr/bin/python3", "-m", "awslambdaric" ]
# ENTRYPOINT [ "/bin/bash", "prueba.sh" ]
# ENTRYPOINT [ "/usr/bin/python3", "-m", "awslambdaric" ]
CMD [ "lambda_handler.handler" ]
