Skip to content

Commit 8bd439e

Browse files
Refactor Dockerfiles to optimize build stages and reduce image sizes; update README with usage instructions and optimization details.
1 parent 22bb08b commit 8bd439e

File tree

4 files changed

+188
-27
lines changed

4 files changed

+188
-27
lines changed

Dockerfile.debian

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,47 @@
1+
# Build stage - contains all build tools and dependencies
2+
FROM debian:bookworm-slim as builder
3+
4+
# Install build dependencies in a single layer and clean up
5+
RUN apt-get update -y && \
6+
apt-get install -y --no-install-recommends \
7+
build-essential \
8+
cmake \
9+
m4 \
10+
automake \
11+
peg \
12+
libtool \
13+
autoconf \
14+
python3 \
15+
python3-pip \
16+
git \
17+
lcov \
18+
openssl \
19+
libssl-dev \
20+
curl \
21+
ca-certificates && \
22+
# Install rust
23+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
24+
# Clean up package cache to reduce image size
25+
apt-get clean && \
26+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
27+
28+
# Add rust to path
29+
ENV PATH="/root/.cargo/bin:${PATH}"
30+
31+
# Final runtime stage - smaller base with only runtime dependencies
132
FROM debian:bookworm-slim
233

3-
RUN apt-get update -y && apt-get install -y build-essential cmake m4 automake peg libtool autoconf python3 python3-pip git peg lcov openssl libssl-dev curl
34+
# Install only runtime dependencies
35+
RUN apt-get update -y && \
36+
apt-get install -y --no-install-recommends \
37+
python3 \
38+
openssl \
39+
ca-certificates && \
40+
apt-get clean && \
41+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
442

5-
# install rust
6-
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
43+
# Copy rust installation from builder stage
44+
COPY --from=builder /root/.cargo /root/.cargo
745

8-
# add rust to path
46+
# Add rust to path
947
ENV PATH="/root/.cargo/bin:${PATH}"

Dockerfile.rhel

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,72 @@
1+
# Build stage - contains all build tools and dependencies
12
FROM redhat/ubi9 as builder
23

4+
# Install build dependencies and tools in optimized layers
35
RUN yum update -y && \
4-
yum install -y wget autoconf automake python3.11 python3.11-pip libtool git make openssl-devel gcc gcc-c++ libstdc++-static diffutils cmake3 && \
5-
alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 && \
6-
alternatives --auto python3
6+
yum install -y \
7+
wget \
8+
autoconf \
9+
automake \
10+
python3.11 \
11+
python3.11-pip \
12+
libtool \
13+
git \
14+
make \
15+
openssl-devel \
16+
gcc \
17+
gcc-c++ \
18+
libstdc++-static \
19+
diffutils \
20+
cmake3 \
21+
curl && \
22+
alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 && \
23+
alternatives --auto python3 && \
24+
# Install rust
25+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
26+
# Clean up package cache
27+
yum clean all && \
28+
rm -rf /var/cache/yum /tmp/* /var/tmp/*
729

8-
# install rust
9-
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
10-
11-
# add rust to path
30+
# Add rust to path
1231
ENV PATH="/root/.cargo/bin:${PATH}"
1332

14-
# install leg/geg
33+
# Install peg in a separate layer to enable better caching
1534
RUN wget https://www.piumarta.com/software/peg/peg-0.1.19.tar.gz && \
16-
tar -xzvf peg-0.1.19.tar.gz && \
17-
cd peg-0.1.19 && \
18-
make && \
19-
make install && \
20-
cd ..
35+
tar -xzvf peg-0.1.19.tar.gz && \
36+
cd peg-0.1.19 && \
37+
make && \
38+
make install && \
39+
cd .. && \
40+
rm -rf peg-0.1.19*
2141

22-
# install redis
42+
# Install redis in a separate layer to enable better caching
2343
RUN wget https://download.redis.io/redis-stable.tar.gz && \
24-
tar -xzvf redis-stable.tar.gz && \
25-
cd redis-stable && \
26-
make && \
27-
make install && \
28-
cd ..
44+
tar -xzvf redis-stable.tar.gz && \
45+
cd redis-stable && \
46+
make && \
47+
make install && \
48+
cd .. && \
49+
rm -rf redis-stable*
50+
51+
# Final runtime stage - smaller base with only runtime dependencies
52+
FROM redhat/ubi9
53+
54+
# Install only runtime dependencies
55+
RUN yum update -y && \
56+
yum install -y \
57+
python3.11 \
58+
openssl && \
59+
alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 && \
60+
alternatives --auto python3 && \
61+
yum clean all && \
62+
rm -rf /var/cache/yum /tmp/* /var/tmp/*
63+
64+
# Copy rust installation from builder stage
65+
COPY --from=builder /root/.cargo /root/.cargo
66+
67+
# Copy installed binaries from builder stage
68+
COPY --from=builder /usr/local/bin/peg /usr/local/bin/
69+
COPY --from=builder /usr/local/bin/redis-* /usr/local/bin/
70+
71+
# Add rust to path
72+
ENV PATH="/root/.cargo/bin:${PATH}"

Dockerfile.ubuntu

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,53 @@
1+
# Build stage - contains all build tools and dependencies
12
FROM ubuntu:22.04 as builder
23

3-
RUN apt-get update -y && apt-get install -y curl build-essential cmake m4 automake peg libtool autoconf python3 python3-pip git lcov openssl libssl-dev
4+
# Prevent interactive prompts during package installation
5+
ENV DEBIAN_FRONTEND=noninteractive
46

5-
# install rust
6-
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
7+
# Install build dependencies in a single layer and clean up
8+
RUN apt-get update -y && \
9+
apt-get install -y --no-install-recommends \
10+
curl \
11+
build-essential \
12+
cmake \
13+
m4 \
14+
automake \
15+
peg \
16+
libtool \
17+
autoconf \
18+
python3 \
19+
python3-pip \
20+
git \
21+
lcov \
22+
openssl \
23+
libssl-dev \
24+
ca-certificates && \
25+
# Install rust
26+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
27+
# Clean up package cache to reduce image size
28+
apt-get clean && \
29+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
730

8-
# add rust to path
31+
# Add rust to path
32+
ENV PATH="/root/.cargo/bin:${PATH}"
33+
34+
# Final runtime stage - smaller base with only runtime dependencies
35+
FROM ubuntu:22.04
36+
37+
# Prevent interactive prompts during package installation
38+
ENV DEBIAN_FRONTEND=noninteractive
39+
40+
# Install only runtime dependencies
41+
RUN apt-get update -y && \
42+
apt-get install -y --no-install-recommends \
43+
python3 \
44+
openssl \
45+
ca-certificates && \
46+
apt-get clean && \
47+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
48+
49+
# Copy rust installation from builder stage
50+
COPY --from=builder /root/.cargo /root/.cargo
51+
52+
# Add rust to path
953
ENV PATH="/root/.cargo/bin:${PATH}"

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,37 @@
11
# build-image
22
FalkorDB Docker build image
3+
4+
## Overview
5+
This repository contains optimized Docker build images for FalkorDB development across different Linux distributions.
6+
7+
## Available Images
8+
- **Debian** (`Dockerfile.debian`) - Based on Debian Bookworm Slim
9+
- **Ubuntu** (`Dockerfile.ubuntu`) - Based on Ubuntu 22.04
10+
- **RHEL** (`Dockerfile.rhel`) - Based on Red Hat UBI 9
11+
12+
## Optimizations
13+
All Dockerfiles use multi-stage builds to significantly reduce final image size:
14+
15+
1. **Build Stage**: Contains all development tools, compilers, and build dependencies
16+
2. **Runtime Stage**: Contains only essential runtime dependencies and compiled artifacts
17+
18+
### Key optimization features:
19+
- Multi-stage builds to separate build and runtime dependencies
20+
- Consolidated RUN commands to reduce layers
21+
- Package cache cleanup to minimize image size
22+
- `--no-install-recommends` flag to avoid unnecessary packages
23+
- Proper copying of only required binaries and installations from build stage
24+
25+
## Usage
26+
Build an image for your target distribution:
27+
28+
```bash
29+
# Debian
30+
docker build -f Dockerfile.debian -t falkordb-build:debian .
31+
32+
# Ubuntu
33+
docker build -f Dockerfile.ubuntu -t falkordb-build:ubuntu .
34+
35+
# RHEL
36+
docker build -f Dockerfile.rhel -t falkordb-build:rhel .
37+
```

0 commit comments

Comments
 (0)