87 lines
2.3 KiB
Docker
87 lines
2.3 KiB
Docker
FROM drogonframework/drogon:latest
|
|
|
|
WORKDIR /app
|
|
|
|
# Install additional dependencies
|
|
RUN apt-get update && apt-get install -y \
|
|
pkg-config \
|
|
git \
|
|
cmake \
|
|
libhiredis-dev \
|
|
curl \
|
|
libssl-dev \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Try to install redis-plus-plus from package manager first
|
|
RUN apt-get update && \
|
|
(apt-get install -y libredis++-dev || echo "Package not available") && \
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
# If redis-plus-plus wasn't available from package manager, build from source
|
|
RUN if ! pkg-config --exists redis++; then \
|
|
echo "Building redis-plus-plus from source..." && \
|
|
git clone --depth 1 https://github.com/sewenew/redis-plus-plus.git && \
|
|
cd redis-plus-plus && \
|
|
mkdir build && \
|
|
cd build && \
|
|
cmake -DCMAKE_BUILD_TYPE=Release \
|
|
-DREDIS_PLUS_PLUS_CXX_STANDARD=17 \
|
|
-DREDIS_PLUS_PLUS_BUILD_TEST=OFF \
|
|
-DREDIS_PLUS_PLUS_BUILD_STATIC=OFF \
|
|
-DCMAKE_INSTALL_PREFIX=/usr/local .. && \
|
|
make -j$(nproc) && \
|
|
make install && \
|
|
cd ../.. && \
|
|
rm -rf redis-plus-plus; \
|
|
fi
|
|
|
|
# Install jwt-cpp (header-only library)
|
|
RUN git clone --depth 1 https://github.com/Thalhammer/jwt-cpp.git && \
|
|
cd jwt-cpp && \
|
|
mkdir build && \
|
|
cd build && \
|
|
cmake .. && \
|
|
make install && \
|
|
cd ../.. && \
|
|
rm -rf jwt-cpp
|
|
|
|
# Update library cache
|
|
RUN ldconfig
|
|
|
|
# Copy source code
|
|
COPY CMakeLists.txt ./
|
|
COPY src/ src/
|
|
|
|
# Clean any previous build
|
|
RUN rm -rf build CMakeCache.txt
|
|
|
|
# Create build directory
|
|
RUN mkdir -p build
|
|
|
|
# Build the chat service
|
|
RUN cd build && \
|
|
cmake .. -DCMAKE_BUILD_TYPE=Release \
|
|
-DCMAKE_INSTALL_RPATH="/usr/local/lib" \
|
|
-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE && \
|
|
cmake --build . -j$(nproc)
|
|
|
|
# Copy configuration
|
|
COPY config.json .
|
|
|
|
# Expose port
|
|
EXPOSE 8081
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s \
|
|
CMD curl -f http://localhost:8081/api/chat/health 2>/dev/null || exit 1
|
|
|
|
# Create startup script
|
|
RUN echo '#!/bin/bash\n\
|
|
echo "Checking library dependencies..."\n\
|
|
ldd ./build/bin/chat_service\n\
|
|
echo "Starting chat service..."\n\
|
|
exec ./build/bin/chat_service' > start.sh && \
|
|
chmod +x start.sh
|
|
|
|
# Run the service
|
|
CMD ["./start.sh"]
|