-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathDockerfile
94 lines (74 loc) · 3.2 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# syntax=docker/dockerfile:1
FROM python:3.12-slim-bullseye AS base
LABEL maintainer="Endstone <[email protected]>"
ENV PYTHONUNBUFFERED=1 \
PYTHONIOENCODING=UTF-8
# Build stage
FROM base AS builder
# Install required dependencies and configure LLVM
ARG LLVM_VERSION=16
RUN apt-get update -y -qq \
&& apt-get install -y -qq build-essential lsb-release wget software-properties-common gnupg \
&& wget https://apt.llvm.org/llvm.sh \
&& chmod +x llvm.sh \
&& ./llvm.sh ${LLVM_VERSION} \
&& apt-get install -y -qq libc++-${LLVM_VERSION}-dev libc++abi-${LLVM_VERSION}-dev \
&& update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${LLVM_VERSION} 100 \
&& update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-${LLVM_VERSION} 100 \
&& update-alternatives --install /usr/bin/llvm-cov llvm-cov /usr/bin/llvm-cov-${LLVM_VERSION} 100 \
&& update-alternatives --install /usr/bin/ld ld /usr/bin/ld.lld-${LLVM_VERSION} 100
# Install CMake and other build tools
ARG CMAKE_VERSION=3.31.4
ARG CMAKE_SH=cmake-${CMAKE_VERSION}-linux-x86_64.sh
RUN apt-get update -y -qq \
&& apt-get install -y -qq wget git ninja-build \
&& wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_SH} \
&& chmod +x ${CMAKE_SH} \
&& ./${CMAKE_SH} --skip-license --exclude-subdir --prefix=/usr/local
# Set default compiler and target platform tag for Python wheels
ENV CC=clang \
CXX=clang++ \
AUDITWHEEL_PLAT=manylinux_2_31_x86_64
# Define working directory for the source code
WORKDIR /usr/src/endstone
# Install C++ dependencies using Conan
COPY conanfile.py conanfile.py
RUN python -m pip install --upgrade pip \
&& pip install conan \
&& conan profile detect \
&& conan install . --build=missing -s compiler.cppstd=20 -s compiler.libcxx=libc++ -c tools.cmake.cmaketoolchain:generator=Ninja
# Copy the rest of the project files
COPY . .
# Build and test the project
RUN --mount=type=secret,id=sentry-auth-token,env=SENTRY_AUTH_TOKEN \
pip install wheel auditwheel sentry-cli setuptools "patchelf>=0.14" pytest \
&& python -m pip wheel . --no-deps --wheel-dir=dist --verbose \
&& python scripts/repair_wheel.py -o endstone -p endstone -w wheelhouse dist/*.whl \
&& pip install wheelhouse/*-${AUDITWHEEL_PLAT}.whl \
&& pytest tests/endstone/python
# Final stage
FROM base AS final
# Install runtime dependencies
RUN apt-get update -y -qq \
&& apt-get install -y -qq curl \
&& apt-get clean -y -qq \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user for running the application
RUN useradd -m -s /bin/bash endstone \
&& printf "endstone:endstone" | chpasswd \
&& adduser endstone sudo \
&& printf "endstone ALL= NOPASSWD: ALL\\n" >> /etc/sudoers
# Define working directory
WORKDIR /home/endstone
# Copy the built wheel files from the builder stage
COPY --from=builder /usr/src/endstone/wheelhouse .
# Install the wheel and clean up
RUN python -m pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir ./*.whl \
&& rm ./*.whl
# Switch to non-root user
USER endstone
# Expose application ports
EXPOSE 19132/udp 19133/udp
# Define the default command to run the application
CMD ["endstone"]