Add Docker build support

This commit is contained in:
Julien Letessier 2026-01-19 14:39:01 +01:00
parent ce5c3419c3
commit df2431bff3
5 changed files with 82 additions and 9 deletions

46
Dockerfile Normal file
View File

@ -0,0 +1,46 @@
#-----------------------------------------------------------
FROM --platform=$BUILDPLATFORM debian:trixie-slim AS build
WORKDIR /src/predixy
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*
#-----------------------------------------------------------
FROM build AS bin
COPY src src
COPY Makefile .
RUN make clean && make
#-----------------------------------------------------------
FROM build AS test
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
python3 \
python3-venv \
pipx \
redis-server \
&& rm -rf /var/lib/apt/lists/*
RUN pipx install uv \
&& ln -s /root/.local/bin/uv /usr/local/bin/uv
COPY src src
COPY test test
COPY conf conf
COPY pyproject.toml uv.lock Makefile .
RUN make clean && make -j8
RUN make test
#-----------------------------------------------------------
FROM debian:trixie-slim
RUN useradd -r -s /usr/sbin/nologin predixy
WORKDIR /etc/predixy
COPY --from=bin /src/predixy/src/predixy /usr/local/bin/predixy
COPY --from=bin /src/predixy/conf/ /etc/predixy/
EXPOSE 7617
USER predixy
ENTRYPOINT ["/usr/local/bin/predixy", "/etc/predixy/predixy.conf"]

View File

@ -1,5 +1,5 @@
.PHONY : default debug clean test lint cppcheck .PHONY : default debug clean test test-docker lint cppcheck docker-buildx
make = make make = make
plt = $(shell uname) plt = $(shell uname)
@ -9,6 +9,13 @@ else ifeq ($(plt), OpenBSD)
make = gmake make = gmake
endif endif
IMAGE ?= predixy
TAG ?= latest
IMAGE_TAG = $(IMAGE):$(TAG)
BUILD_PLATFORMS ?= linux/amd64,linux/arm64
DOCKERFILE ?= Dockerfile
DOCKER_CONTEXT ?= .
default: default:
@$(make) -C src -f Makefile @$(make) -C src -f Makefile
@ -21,8 +28,15 @@ clean:
test: default test: default
@./test/run.sh @./test/run.sh
test-docker:
docker build -f $(DOCKERFILE) --target test $(DOCKER_CONTEXT)
lint: lint:
@$(make) -C src -f Makefile lint @$(make) -C src -f Makefile lint
cppcheck: cppcheck:
@$(make) -C src -f Makefile cppcheck @$(make) -C src -f Makefile cppcheck
docker-buildx:
docker buildx build --platform $(BUILD_PLATFORMS) \
-t $(IMAGE_TAG) -f $(DOCKERFILE) $(DOCKER_CONTEXT)

View File

@ -12,6 +12,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <string> #include <string>
#include <ctime>
#include <time.h>
class String class String
{ {
@ -246,7 +248,7 @@ public:
bool strftime(const char* fmt, time_t t) bool strftime(const char* fmt, time_t t)
{ {
struct tm m; struct tm m;
localtime_r(&t, &m); ::localtime_r(&t, &m);
int ret = ::strftime(mBuf, Size, fmt, &m); int ret = ::strftime(mBuf, Size, fmt, &m);
return ret > 0 && ret < Size; return ret > 0 && ret < Size;
} }

View File

@ -18,18 +18,18 @@ def run_test(project_root):
with tempfile.TemporaryDirectory() as tmp: with tempfile.TemporaryDirectory() as tmp:
exe = os.path.join(tmp, "handler_stop_atomic") exe = os.path.join(tmp, "handler_stop_atomic")
cmd = [ cmd = [
"g++", "g++",
"-std=c++11", "-std=c++11",
src, src,
"-o", "-o",
exe, exe,
] ]
sysname = platform.system() sysname = platform.system()
if sysname == "Darwin": if sysname == "Darwin":
cmd.insert(1, "-D_KQUEUE_") cmd.insert(1, "-D_KQUEUE_")
elif sysname == "Linux": elif sysname == "Linux":
cmd.insert(1, "-D_EPOLL_") cmd.insert(1, "-D_EPOLL_")
try: try:
subprocess.check_call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) subprocess.check_call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
except Exception as exc: except Exception as exc:

View File

@ -52,6 +52,14 @@ cleanup() {
rm -rf "$TMP_DIR" rm -rf "$TMP_DIR"
} }
# Provide context when predixy fails to start.
dump_predixy_log() {
if [ -n "$PREDIXY_LOG" ] && [ -f "$PREDIXY_LOG" ]; then
echo "Predixy log output:"
tail -n 200 "$PREDIXY_LOG"
fi
}
# Set up trap to ensure cleanup on exit # Set up trap to ensure cleanup on exit
trap cleanup EXIT INT TERM trap cleanup EXIT INT TERM
@ -99,11 +107,13 @@ EOF
# Start fresh Predixy instance # Start fresh Predixy instance
echo "Starting fresh Predixy on port $TEST_PREDIXY_PORT..." echo "Starting fresh Predixy on port $TEST_PREDIXY_PORT..."
PREDIXY_PID=$("$PREDIXY_BIN" "$TEST_PREDIXY_CONFIG" > /dev/null 2>&1 & echo $!) PREDIXY_LOG="$TMP_DIR/predixy_test.log"
PREDIXY_PID=$("$PREDIXY_BIN" "$TEST_PREDIXY_CONFIG" > "$PREDIXY_LOG" 2>&1 & echo $!)
# Check if process died before waiting for port # Check if process died before waiting for port
if ! kill -0 $PREDIXY_PID 2>/dev/null; then if ! kill -0 $PREDIXY_PID 2>/dev/null; then
echo "Error: predixy process died" echo "Error: predixy process died"
dump_predixy_log
exit 1 exit 1
fi fi
@ -113,6 +123,7 @@ if ! uv run python3 "$SCRIPT_DIR/wait_for_port.py" localhost $TEST_PREDIXY_PORT
# Check if process died during wait # Check if process died during wait
if ! kill -0 $PREDIXY_PID 2>/dev/null; then if ! kill -0 $PREDIXY_PID 2>/dev/null; then
echo "Error: predixy process died" echo "Error: predixy process died"
dump_predixy_log
fi fi
exit 1 exit 1
fi fi