1- FROM ubuntu:22.04 as base
2-
3- FROM base as build
4-
5- ARG CORTEX_CPP_VERSION=latest
6-
7- ARG CMAKE_EXTRA_FLAGS=""
1+ # Stage 1: Base dependencies (common stage)
2+ FROM ubuntu:22.04 as common
83
94ENV DEBIAN_FRONTEND=noninteractive
105
11- # Install dependencies
6+ # Install common dependencies
127RUN apt-get update && apt-get install -y --no-install-recommends \
138 ca-certificates \
9+ software-properties-common \
1410 curl \
1511 wget \
1612 jq \
@@ -20,71 +16,65 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2016 apt-get clean && \
2117 rm -rf /var/lib/apt/lists/*
2218
23- RUN apt-get update && apt-get install -y --no-install-recommends \
19+ # Stage 2: Build dependencies and compilation
20+ FROM common as build
21+
22+ # Install Dependencies
23+ RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null && \
24+ apt-add-repository "deb https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main" && \
25+ apt-get update && \
26+ apt-get install -y --no-install-recommends \
27+ cmake \
28+ make \
2429 git \
2530 uuid-dev \
2631 lsb-release \
27- software-properties-common \
2832 gpg \
2933 zip \
3034 unzip \
3135 gcc \
3236 g++ \
3337 ninja-build \
3438 pkg-config \
39+ python3-pip \
3540 openssl && \
41+ pip3 install awscli && \
3642 apt-get clean && \
3743 rm -rf /var/lib/apt/lists/*
3844
39- RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null && \
40- apt-add-repository "deb https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main" && \
41- apt-get update && \
42- apt-get install -y cmake && \
43- apt-get clean && \
44- rm -rf /var/lib/apt/lists/*
45+ ARG CORTEX_CPP_VERSION=latest
46+ ARG CMAKE_EXTRA_FLAGS=""
4547
4648WORKDIR /app
4749
50+ # Copy source code
4851COPY ./engine /app/engine
49-
5052COPY ./docs/static/openapi/cortex.json /app/docs/static/openapi/cortex.json
5153
54+ # Build project
55+ # Configure vcpkg binary sources
5256RUN cd engine && make configure-vcpkg && make build CMAKE_EXTRA_FLAGS="-DCORTEX_CPP_VERSION=${CORTEX_CPP_VERSION} -DCMAKE_BUILD_TEST=OFF -DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake ${CMAKE_EXTRA_FLAGS}"
5357
54- FROM base as runtime
55-
56- ENV DEBIAN_FRONTEND=noninteractive
57-
58- # Install dependencies
59- RUN apt-get update && apt-get install -y --no-install-recommends \
60- ca-certificates \
61- curl \
62- wget \
63- jq \
64- tar \
65- openmpi-bin \
66- libopenmpi-dev && \
67- apt-get clean && \
68- rm -rf /var/lib/apt/lists/*
69-
70- ARG CORTEX_LLAMACPP_VERSION=latest
58+ # Stage 3: Runtime
7159
60+ WORKDIR /app
7261COPY --from=build /app/engine/build/cortex /usr/local/bin/cortex
7362COPY --from=build /app/engine/build/cortex-server /usr/local/bin/cortex-server
7463
7564COPY ./docker/download-cortex.llamacpp.sh /tmp/download-cortex.llamacpp.sh
65+ COPY ./docker/entrypoint.sh /usr/local/bin/entrypoint.sh
7666
77- # Get the latest version of the Cortex Llama
67+ # Get the latest version of Cortex Llama
68+ ARG CORTEX_LLAMACPP_VERSION=latest
7869RUN chmod +x /tmp/download-cortex.llamacpp.sh && /bin/bash /tmp/download-cortex.llamacpp.sh ${CORTEX_LLAMACPP_VERSION}
7970
80- # Copy the entrypoint script
81- COPY ./docker/entrypoint.sh /usr/local/bin/entrypoint.sh
82-
71+ # Configure entrypoint
8372RUN chmod +x /usr/local/bin/entrypoint.sh
8473
8574EXPOSE 39281
8675
76+ # Healthcheck
8777HEALTHCHECK --interval=300s --timeout=30s --start-period=10s --retries=3 \
8878 CMD curl -f http://127.0.0.1:39281/healthz || exit 1
89-
79+
9080ENTRYPOINT ["/usr/local/bin/entrypoint.sh" ]
0 commit comments