FROM pytorch/torchserve:latest-cpu

USER root

RUN apt update \
    && apt install -y unzip git curl \
    && curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \
    && unzip awscliv2.zip \
    && ./aws/install

RUN pip install "onnxruntime==1.14.1" "onnx==1.13.1" "git+https://github.com/facebookresearch/segment-anything.git" "shapely" "pyproj" "rasterio" "debugpy"

COPY ./deployment/config_decode.properties /home/model-server/config.properties
COPY ./deployment/append_memory_setting.sh /home/model-server/append_memory_setting.sh
RUN chmod +x /home/model-server/append_memory_setting.sh \
    && /home/model-server/append_memory_setting.sh

COPY start ./

WORKDIR /home/model-server
ENV TEMP=/home/model-server/tmp
ENV ENABLE_TORCH_PROFILER=TRUE

CMD ./start
