mirror of
https://github.com/joyieldInc/predixy.git
synced 2026-02-05 01:42:24 +08:00
Add Docker build support
This commit is contained in:
parent
ce5c3419c3
commit
df2431bff3
46
Dockerfile
Normal file
46
Dockerfile
Normal 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"]
|
||||
16
Makefile
16
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)
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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:
|
||||
|
||||
13
test/run.sh
13
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user