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
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)

View File

@ -12,6 +12,8 @@
#include <stdio.h>
#include <stdarg.h>
#include <string>
#include <ctime>
#include <time.h>
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;
}

View File

@ -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