Skip to content

Commit 21158fb

Browse files
committed
U
1 parent 7fd15ad commit 21158fb

21 files changed

+1662
-210
lines changed

Dockerfile

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# Multi-stage Dockerfile for KeyDB with Redis 8.2.3 Protocol Support
2+
# Optimized for production use with TLS support
3+
4+
# ============================================================================
5+
# Stage 1: Builder
6+
# ============================================================================
7+
FROM ubuntu:22.04 AS builder
8+
9+
# Prevent interactive prompts
10+
ENV DEBIAN_FRONTEND=noninteractive
11+
12+
# Install build dependencies
13+
RUN apt-get update && apt-get install -y \
14+
build-essential \
15+
$(dpkg --print-architecture | grep -q "amd64\|x86_64" && echo "nasm" || true) \
16+
autotools-dev \
17+
autoconf \
18+
libjemalloc-dev \
19+
tcl \
20+
tcl-dev \
21+
uuid-dev \
22+
libcurl4-openssl-dev \
23+
libbz2-dev \
24+
libzstd-dev \
25+
liblz4-dev \
26+
libsnappy-dev \
27+
libssl-dev \
28+
pkg-config \
29+
&& rm -rf /var/lib/apt/lists/*
30+
31+
# Set working directory
32+
WORKDIR /keydb
33+
34+
# Copy source code
35+
COPY . .
36+
37+
# Clean any previous builds and build dependencies
38+
# ARM64 builds use -O0 (no optimization) to avoid GCC crashes in emulation
39+
# AMD64 also uses -O2 instead of -O3 for jemalloc to avoid potential issues
40+
# We need to clean dependencies and override CFLAGS before configure/build runs
41+
RUN make clean || true && \
42+
if [ "$(uname -m)" = "aarch64" ]; then \
43+
cd deps && \
44+
CFLAGS="" make hiredis && \
45+
(cd jemalloc && [ -f Makefile ] && make distclean || true) && \
46+
CFLAGS="" make jemalloc JEMALLOC_CFLAGS="-std=gnu99 -Wall -pipe -g -O0" && \
47+
(cd lua && make clean || true) && \
48+
CFLAGS="" cd lua/src && make all CFLAGS="-O0 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -DLUA_USE_MKSTEMP" MYLDFLAGS="" AR="ar rc" && cd ../.. && \
49+
CFLAGS="" make hdr_histogram && \
50+
cd ..; \
51+
else \
52+
cd deps && \
53+
make hiredis && \
54+
(cd jemalloc && [ -f Makefile ] && make distclean || true) && \
55+
make jemalloc JEMALLOC_CFLAGS="-std=gnu99 -Wall -pipe -g -O2" && \
56+
make lua hdr_histogram -j$(nproc) && \
57+
cd ..; \
58+
fi
59+
60+
# Build KeyDB with TLS support
61+
# ARM64: use -O0 (no optimization) and single-threaded build to avoid GCC crashes
62+
RUN if [ "$(uname -m)" = "aarch64" ]; then \
63+
make BUILD_TLS=yes OPTIMIZATION=-O0 -j1; \
64+
else \
65+
make BUILD_TLS=yes -j$(nproc); \
66+
fi
67+
68+
# ============================================================================
69+
# Stage 2: Runtime
70+
# ============================================================================
71+
FROM ubuntu:22.04
72+
73+
# Prevent interactive prompts
74+
ENV DEBIAN_FRONTEND=noninteractive
75+
76+
# Install gosu and runtime dependencies
77+
ENV GOSU_VERSION=1.17
78+
RUN set -eux; \
79+
apt-get update; \
80+
apt-get install -y --no-install-recommends \
81+
ca-certificates \
82+
wget; \
83+
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
84+
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
85+
chmod +x /usr/local/bin/gosu; \
86+
gosu --version; \
87+
gosu nobody true; \
88+
apt-get install -y --no-install-recommends \
89+
libjemalloc2 \
90+
libcurl4 \
91+
libbz2-1.0 \
92+
libzstd1 \
93+
liblz4-1 \
94+
libsnappy1v5 \
95+
libssl3 \
96+
libuuid1 \
97+
tcl8.6; \
98+
apt-get purge -y --auto-remove wget; \
99+
rm -rf /var/lib/apt/lists/*
100+
101+
# Create keydb user and group
102+
RUN groupadd -r -g 999 keydb && \
103+
useradd -r -g keydb -u 999 keydb
104+
105+
# Copy binaries from builder
106+
COPY --from=builder /keydb/src/keydb-server /usr/local/bin/
107+
COPY --from=builder /keydb/src/keydb-cli /usr/local/bin/
108+
COPY --from=builder /keydb/src/keydb-benchmark /usr/local/bin/
109+
COPY --from=builder /keydb/src/keydb-check-rdb /usr/local/bin/
110+
COPY --from=builder /keydb/src/keydb-check-aof /usr/local/bin/
111+
COPY --from=builder /keydb/src/keydb-sentinel /usr/local/bin/
112+
113+
# Create symlinks for redis compatibility
114+
RUN ln -s /usr/local/bin/keydb-server /usr/local/bin/redis-server && \
115+
ln -s /usr/local/bin/keydb-cli /usr/local/bin/redis-cli && \
116+
ln -s /usr/local/bin/keydb-benchmark /usr/local/bin/redis-benchmark && \
117+
ln -s /usr/local/bin/keydb-check-rdb /usr/local/bin/redis-check-rdb && \
118+
ln -s /usr/local/bin/keydb-check-aof /usr/local/bin/redis-check-aof && \
119+
ln -s /usr/local/bin/keydb-sentinel /usr/local/bin/redis-sentinel
120+
121+
# Create directories
122+
RUN mkdir -p /data /etc/keydb && \
123+
chown -R keydb:keydb /data /etc/keydb
124+
125+
# Copy default config
126+
COPY keydb.conf /etc/keydb/keydb.conf
127+
RUN chown keydb:keydb /etc/keydb/keydb.conf
128+
129+
# Create entrypoint script inline
130+
RUN set -eux; \
131+
echo '#!/bin/sh' > /usr/local/bin/docker-entrypoint.sh; \
132+
echo 'set -e' >> /usr/local/bin/docker-entrypoint.sh; \
133+
echo '' >> /usr/local/bin/docker-entrypoint.sh; \
134+
echo '# Allow the container to be started with `--user`' >> /usr/local/bin/docker-entrypoint.sh; \
135+
echo 'if [ "$1" = "keydb-server" -a "$(id -u)" = "0" ]; then' >> /usr/local/bin/docker-entrypoint.sh; \
136+
echo ' find . \! -user keydb -exec chown keydb:keydb {} \;' >> /usr/local/bin/docker-entrypoint.sh; \
137+
echo ' exec gosu keydb "$0" "$@"' >> /usr/local/bin/docker-entrypoint.sh; \
138+
echo 'fi' >> /usr/local/bin/docker-entrypoint.sh; \
139+
echo '' >> /usr/local/bin/docker-entrypoint.sh; \
140+
echo '# Set password if KEYDB_PASSWORD is provided' >> /usr/local/bin/docker-entrypoint.sh; \
141+
echo 'if [ ! -z "${KEYDB_PASSWORD:-}" ]; then' >> /usr/local/bin/docker-entrypoint.sh; \
142+
echo ' echo "requirepass $KEYDB_PASSWORD" >> /etc/keydb/keydb.conf' >> /usr/local/bin/docker-entrypoint.sh; \
143+
echo 'fi' >> /usr/local/bin/docker-entrypoint.sh; \
144+
echo '' >> /usr/local/bin/docker-entrypoint.sh; \
145+
echo 'exec "$@"' >> /usr/local/bin/docker-entrypoint.sh; \
146+
chmod +x /usr/local/bin/docker-entrypoint.sh
147+
148+
# Set working directory
149+
WORKDIR /data
150+
151+
# Expose ports
152+
EXPOSE 6379
153+
154+
# Set volume
155+
VOLUME ["/data"]
156+
157+
# Entrypoint (runs as root initially, then drops to keydb user via gosu)
158+
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
159+
160+
# Default command
161+
CMD ["keydb-server", "/etc/keydb/keydb.conf"]
162+
163+
# Metadata
164+
LABEL maintainer="Valerii Vainkop <[email protected]>" \
165+
description="KeyDB with Redis 8.2.3 Protocol Support - Multi-master, Multithreaded, Kubernetes-ready" \
166+
version="8.2.3" \
167+
redis-protocol="8.2.3"
168+

build_push.sh

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/bin/bash
2+
#
3+
# build_push.sh - Build and push KeyDB Redis 8 multi-arch image to Docker Hub
4+
#
5+
# Usage:
6+
# ./build_push.sh [tag] [platforms]
7+
#
8+
# Examples:
9+
# ./build_push.sh # Pushes as 'latest' (amd64 + arm64)
10+
# ./build_push.sh 8.2.3 # Pushes as '8.2.3' and 'latest' (amd64 + arm64)
11+
# ./build_push.sh 8.2.3 linux/amd64 # Single platform build
12+
#
13+
14+
set -e
15+
16+
REPO="vainkop/keydb8"
17+
TAG="${1:-latest}"
18+
PLATFORMS="${2:-linux/amd64,linux/arm64}"
19+
20+
echo "╔══════════════════════════════════════════════════════════════════════╗"
21+
echo "║ Building KeyDB Redis 8 Multi-Arch Docker Image ║"
22+
echo "╚══════════════════════════════════════════════════════════════════════╝"
23+
echo ""
24+
echo "Repository: ${REPO}"
25+
echo "Tag: ${TAG}"
26+
echo "Platforms: ${PLATFORMS}"
27+
echo ""
28+
29+
# Check if Dockerfile exists
30+
if [ ! -f "Dockerfile" ]; then
31+
echo "❌ Error: Dockerfile not found in current directory"
32+
exit 1
33+
fi
34+
35+
# Check if buildx is available
36+
if ! docker buildx version > /dev/null 2>&1; then
37+
echo "❌ Error: docker buildx is required for multi-arch builds"
38+
echo "Install it with: docker buildx install"
39+
exit 1
40+
fi
41+
42+
# Check if logged in to Docker Hub
43+
if ! docker info 2>/dev/null | grep -q "Username:"; then
44+
echo "⚠️ Not logged in to Docker Hub"
45+
echo "Please run: docker login"
46+
exit 1
47+
fi
48+
49+
# Create builder instance if it doesn't exist
50+
BUILDER_NAME="keydb-multiarch"
51+
if ! docker buildx ls | grep -q "$BUILDER_NAME"; then
52+
echo "📦 Creating buildx builder: $BUILDER_NAME"
53+
docker buildx create --name "$BUILDER_NAME" --driver docker-container --use
54+
docker buildx inspect --bootstrap
55+
else
56+
echo "📦 Using existing builder: $BUILDER_NAME"
57+
docker buildx use "$BUILDER_NAME"
58+
fi
59+
60+
# Build and push multi-arch image
61+
echo ""
62+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
63+
echo "Building multi-arch image (this may take 20-40 minutes)..."
64+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
65+
echo ""
66+
67+
docker buildx build \
68+
--platform "${PLATFORMS}" \
69+
--tag "${REPO}:${TAG}" \
70+
--push \
71+
--progress=plain \
72+
.
73+
74+
# Tag as latest if specific version was provided
75+
if [ "${TAG}" != "latest" ]; then
76+
echo ""
77+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
78+
echo "Tagging as latest..."
79+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
80+
echo ""
81+
82+
docker buildx build \
83+
--platform "${PLATFORMS}" \
84+
--tag "${REPO}:latest" \
85+
--push \
86+
--progress=plain \
87+
.
88+
fi
89+
90+
echo ""
91+
echo "╔══════════════════════════════════════════════════════════════════════╗"
92+
echo "║ ✅ BUILD COMPLETE! ║"
93+
echo "╚══════════════════════════════════════════════════════════════════════╝"
94+
echo ""
95+
echo "Multi-arch images pushed:"
96+
echo "${REPO}:${TAG} (${PLATFORMS})"
97+
if [ "${TAG}" != "latest" ]; then
98+
echo "${REPO}:latest (${PLATFORMS})"
99+
fi
100+
echo ""
101+
echo "Verify with:"
102+
echo " docker manifest inspect ${REPO}:${TAG}"
103+
echo ""
104+
echo "Pull with:"
105+
echo " docker pull ${REPO}:${TAG}"
106+
echo ""
107+
echo "Docker will automatically select the correct architecture!"
108+
echo ""
109+
echo "Deploy to Kubernetes:"
110+
echo " helm install keydb ./pkg/helm"
111+
echo ""

0 commit comments

Comments
 (0)