diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7f68694 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/Makefile b/Makefile index 613b445..706b911 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -.PHONY : default debug clean test lint cppcheck +.PHONY : default debug clean test test-docker lint cppcheck docker-buildx make = make plt = $(shell uname) @@ -9,6 +9,13 @@ else ifeq ($(plt), OpenBSD) make = gmake endif +IMAGE ?= predixy +TAG ?= latest +IMAGE_TAG = $(IMAGE):$(TAG) +BUILD_PLATFORMS ?= linux/amd64,linux/arm64 +DOCKERFILE ?= Dockerfile +DOCKER_CONTEXT ?= . + default: @$(make) -C src -f Makefile @@ -21,8 +28,15 @@ clean: test: default @./test/run.sh +test-docker: + docker build -f $(DOCKERFILE) --target test $(DOCKER_CONTEXT) + lint: @$(make) -C src -f Makefile lint cppcheck: @$(make) -C src -f Makefile cppcheck + +docker-buildx: + docker buildx build --platform $(BUILD_PLATFORMS) \ + -t $(IMAGE_TAG) -f $(DOCKERFILE) $(DOCKER_CONTEXT) diff --git a/src/String.h b/src/String.h index 684c49c..76b0522 100644 --- a/src/String.h +++ b/src/String.h @@ -12,6 +12,8 @@ #include #include #include +#include +#include class String { @@ -246,7 +248,7 @@ public: bool strftime(const char* fmt, time_t t) { struct tm m; - localtime_r(&t, &m); + ::localtime_r(&t, &m); int ret = ::strftime(mBuf, Size, fmt, &m); return ret > 0 && ret < Size; } diff --git a/test/handler_stop_atomic.py b/test/handler_stop_atomic.py index aae8028..7c5712f 100644 --- a/test/handler_stop_atomic.py +++ b/test/handler_stop_atomic.py @@ -18,18 +18,18 @@ def run_test(project_root): with tempfile.TemporaryDirectory() as tmp: exe = os.path.join(tmp, "handler_stop_atomic") - cmd = [ + cmd = [ "g++", "-std=c++11", src, "-o", exe, ] - sysname = platform.system() - if sysname == "Darwin": - cmd.insert(1, "-D_KQUEUE_") - elif sysname == "Linux": - cmd.insert(1, "-D_EPOLL_") + sysname = platform.system() + if sysname == "Darwin": + cmd.insert(1, "-D_KQUEUE_") + elif sysname == "Linux": + cmd.insert(1, "-D_EPOLL_") try: subprocess.check_call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) except Exception as exc: diff --git a/test/run.sh b/test/run.sh index bf458be..f94ae4a 100755 --- a/test/run.sh +++ b/test/run.sh @@ -52,6 +52,14 @@ cleanup() { 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 trap cleanup EXIT INT TERM @@ -99,11 +107,13 @@ EOF # Start fresh Predixy instance 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 if ! kill -0 $PREDIXY_PID 2>/dev/null; then echo "Error: predixy process died" + dump_predixy_log exit 1 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 if ! kill -0 $PREDIXY_PID 2>/dev/null; then echo "Error: predixy process died" + dump_predixy_log fi exit 1 fi