|
1 | 1 | # --- C Build Stage --- |
2 | 2 | FROM alpine:latest AS c_builder |
3 | 3 |
|
4 | | -# Install build dependencies. |
5 | | -# Using edge community repository to ensure latest versions of libraries. |
6 | | -RUN apk add --no-cache \ |
7 | | - gcc musl-dev make sqlite-dev openssl-dev cjson-dev uriparser-dev libc-utils linux-headers git \ |
| 4 | +# Install build dependencies from edge community for latest library support |
| 5 | +RUN apk update && apk add --no-cache \ |
| 6 | + tcc clang lld musl-dev make sqlite-dev openssl-dev cjson-dev uriparser-dev git libc-utils linux-headers cmake \ |
8 | 7 | --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community |
9 | 8 |
|
10 | 9 | WORKDIR /app |
11 | 10 |
|
12 | | -# Copy the entire project context. |
13 | | -COPY . . |
| 11 | +# Build libttak (external dependency) |
| 12 | +ARG LIBTTAK_REPO="https://github.com/religiya-serdtsa/libttak.git" |
| 13 | +ARG LIBTTAK_REF="main" |
| 14 | +RUN git clone --depth 1 --branch "${LIBTTAK_REF}" "${LIBTTAK_REPO}" /app/libttak |
| 15 | +WORKDIR /app/libttak |
| 16 | +RUN make clean && LDFLAGS="${LDFLAGS} -Wl,--no-eh-frame-hdr -fuse-ld=lld" make -j$(nproc) && \ |
| 17 | + make install |
14 | 18 |
|
15 | | -# Clone cwist at build time (version-pinned via CWIST_REF). |
16 | | -# This avoids shipping cwist source in the build context and keeps dependencies reproducible. |
17 | | -ARG CWIST_REPO="https://github.com/gg582/cwist.git" |
| 19 | +# Build cwist (core framework) |
| 20 | +ARG CWIST_REPO="https://github.com/religiya-serdtsa/cwist.git" |
18 | 21 | ARG CWIST_REF="main" |
19 | 22 | RUN git clone --depth 1 --branch "${CWIST_REF}" "${CWIST_REPO}" /app/cwist |
| 23 | +RUN git -C /app/cwist submodule update --init --recursive |
20 | 24 |
|
21 | | -# 1. Install Headers (Include) manually to system paths. |
22 | | -# This resolves compilation issues where Makefiles use relative paths (e.g., -I../include) |
23 | | -# by making headers available globally in /usr/local/include. |
24 | | -RUN cp -r /app/cwist/include/* /usr/local/include/ && \ |
25 | | - cp -r /app/libs/include/* /usr/local/include/ 2>/dev/null || true |
26 | | - |
27 | | -# 2. Build Library & Install (Link). |
28 | | -# Build libcwist.a and copy it to /usr/lib so the linker finds it automatically |
29 | | -# without needing specific -L flags. |
30 | 25 | WORKDIR /app/cwist |
31 | | -RUN make clean 2>/dev/null || true; \ |
32 | | - make && \ |
33 | | - cp libcwist.a /usr/lib/ |
34 | 26 |
|
35 | | -# 3. Build Main Server. |
36 | | -# Navigate back to root to build the backend server binary. |
37 | | -WORKDIR /app |
38 | | -RUN make clean 2>/dev/null || true; \ |
39 | | - make |
| 27 | +# Define a compiler wrapper to enforce gnu17 standard during library build |
| 28 | +RUN printf '#!/bin/sh\n/usr/bin/gcc -std=gnu17 "$@"' > /usr/local/bin/gcc-std && \ |
| 29 | + chmod +x /usr/local/bin/gcc-std |
40 | 30 |
|
| 31 | +# Build cwist with linked libttak |
| 32 | +RUN rm -rf lib/libttak && mkdir -p lib && \ |
| 33 | + cp -r /app/libttak lib/libttak && \ |
| 34 | + env LDFLAGS="${LDFLAGS} -fuse-ld=lld -Wl,--no-eh-frame-hdr" CC=/usr/local/bin/gcc-std make -j$(nproc) && \ |
| 35 | + env CC=/usr/local/bin/gcc-std make install |
41 | 36 |
|
42 | | -# --- Go Build Stage --- |
43 | | -FROM golang:1.25-alpine AS go_builder |
| 37 | +# Build Main Server |
44 | 38 | WORKDIR /app |
45 | | - |
46 | | -COPY go.mod go.sum ./ |
47 | | -RUN go mod download |
48 | | - |
49 | | -COPY main.go ./ |
50 | | -# Build the Go relay with CGO disabled for static linking. |
51 | | -RUN CGO_ENABLED=0 go build -o ceversi_relay . |
| 39 | +COPY . . |
| 40 | +RUN make clean && make -j$(nproc) |
52 | 41 |
|
53 | 42 |
|
54 | 43 | # --- Final Run Stage --- |
55 | 44 | FROM alpine:latest |
56 | 45 |
|
57 | | -# Install runtime dependencies required for the C server. |
| 46 | +# Install runtime shared libraries |
58 | 47 | RUN apk add --no-cache \ |
59 | 48 | sqlite-libs openssl cjson uriparser libgcc \ |
60 | 49 | --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community |
61 | 50 |
|
62 | 51 | WORKDIR /app |
63 | 52 |
|
64 | | -# Copy the compiled C backend binary. |
65 | | -COPY --from=c_builder /app/server ./ceversi-backend |
66 | | - |
67 | | -# Copy the compiled Go relay binary. |
68 | | -COPY --from=go_builder /app/ceversi_relay ./ceversi-relay |
69 | | - |
| 53 | +# Copy binary and assets from builder |
| 54 | +COPY --from=c_builder /app/server ./ceversi |
70 | 55 | COPY public/ ./public/ |
71 | | - |
72 | | -# Copy root-level templates and fallback assets. |
73 | 56 | COPY index.html.tmpl . |
74 | 57 | COPY style.css . |
75 | 58 | COPY script.js . |
76 | | -COPY othello.db . |
77 | 59 |
|
78 | | -EXPOSE 31744 |
79 | | - |
80 | | -# Default environment variable for the relay URL. |
81 | | -ENV RELAY_URL="wss://portal.gosuda.org/relay" |
| 60 | +# Ensure database file existence for initialization |
| 61 | +RUN touch othello.db |
82 | 62 |
|
83 | | -# Start the relay server. |
84 | | -# We hardcode the server-url in CMD to ensure it connects correctly without shell expansion issues. |
85 | | -ENTRYPOINT ["./ceversi-relay"] |
86 | | -CMD ["--name", "ceversi", \ |
87 | | - "--port", "31744", \ |
88 | | - "--backend-port", "31745", \ |
89 | | - "--c-server", "./ceversi-backend", \ |
90 | | - "--server-url", "wss://portal.gosuda.org/relay"] |
| 63 | +EXPOSE 31744 |
91 | 64 |
|
| 65 | +ENTRYPOINT ["./ceversi", "--no-certs"] |
0 commit comments