Skip to content

Commit f43c15b

Browse files
Add ./build-debian-docker.sh to build a debian package on docker
1 parent 495c236 commit f43c15b

File tree

5 files changed

+195
-5
lines changed

5 files changed

+195
-5
lines changed

Dockerfile.debian-build

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
FROM --platform=linux/x86_64 ubuntu:noble
2+
3+
LABEL description="Flare Debian package builder"
4+
5+
# Set environment variables to prevent interactive prompts
6+
ENV DEBIAN_FRONTEND=noninteractive
7+
ENV TZ=UTC
8+
9+
# Update package manager and install build dependencies
10+
RUN apt-get update && apt-get install -y \
11+
git \
12+
locales \
13+
zlib1g-dev \
14+
build-essential \
15+
autoconf \
16+
automake \
17+
libtool \
18+
libboost-all-dev \
19+
libhashkit-dev \
20+
libtokyocabinet-dev \
21+
libkyotocabinet-dev \
22+
uuid-dev \
23+
pkg-config \
24+
devscripts \
25+
debhelper \
26+
dh-make \
27+
dpkg-dev \
28+
fakeroot \
29+
lsb-release \
30+
&& rm -rf /var/lib/apt/lists/*
31+
32+
# Set locale
33+
RUN locale-gen en_US.UTF-8
34+
ENV LANG en_US.UTF-8
35+
ENV LANGUAGE en_US:en
36+
ENV LC_ALL en_US.UTF-8
37+
38+
# Create build directory
39+
WORKDIR /build
40+
41+
# Copy source code
42+
COPY . /build/flare/
43+
44+
# Create build script
45+
RUN echo '#!/bin/bash\n\
46+
set -e\n\
47+
\n\
48+
echo "=== Building Debian Package for kvs-flare ==="\n\
49+
\n\
50+
cd /build/flare\n\
51+
\n\
52+
# Set build variables\n\
53+
BUILD_TYPE=${BUILD_TYPE:-release}\n\
54+
MACHINE=$(uname -m)\n\
55+
DEB_ARCH=$(echo $MACHINE | sed -e "s/i686/i386/" -e "s/x86_64/amd64/")\n\
56+
DEB_TARGET=$(lsb_release -cs)\n\
57+
FLARE_VERSION=$(head -n 1 debian/changelog | awk "match(\\$0, /[0-9\\.\\-]+/) {print substr(\\$0, RSTART, RLENGTH)}")\n\
58+
FLARE_BUILD_VERSION=${FLARE_BUILD_VERSION:-1}\n\
59+
\n\
60+
echo "Build configuration:"\n\
61+
echo "BUILD_TYPE=$BUILD_TYPE"\n\
62+
echo "DEB_ARCH=$DEB_ARCH"\n\
63+
echo "DEB_TARGET=$DEB_TARGET"\n\
64+
echo "FLARE_VERSION=$FLARE_VERSION"\n\
65+
echo "FLARE_BUILD_VERSION=$FLARE_BUILD_VERSION"\n\
66+
\n\
67+
# Clean any existing build artifacts\n\
68+
if [ -f Makefile ]; then\n\
69+
make distclean || true\n\
70+
fi\n\
71+
\n\
72+
# Remove git files and build artifacts\n\
73+
find . -name ".git*" -exec rm -rf {} + 2>/dev/null || true\n\
74+
find . -name "*.o" -delete 2>/dev/null || true\n\
75+
find . -name "*.lo" -delete 2>/dev/null || true\n\
76+
find . -name ".libs" -exec rm -rf {} + 2>/dev/null || true\n\
77+
find . -name "autom4te.cache" -exec rm -rf {} + 2>/dev/null || true\n\
78+
\n\
79+
# Update debian/changelog with DEB_TARGET\n\
80+
if [ "$BUILD_TYPE" = "release" ] && [ -n "$FLARE_VERSION" ]; then\n\
81+
echo "Updating debian/changelog for release build..."\n\
82+
sed -i -e "s/${FLARE_VERSION}/${FLARE_VERSION}+${DEB_TARGET}${FLARE_BUILD_VERSION}/g" debian/changelog\n\
83+
fi\n\
84+
\n\
85+
# Prepare source\n\
86+
if [ ! -f configure ]; then\n\
87+
echo "Running autogen.sh..."\n\
88+
./autogen.sh\n\
89+
fi\n\
90+
\n\
91+
# Build package with debuild\n\
92+
echo "Running debuild --no-tgz-check -uc -us..."\n\
93+
echo "y" | debuild --no-tgz-check -uc -us\n\
94+
\n\
95+
# Update distribution in changes file\n\
96+
cd /build\n\
97+
if ls flare_*.changes >/dev/null 2>&1; then\n\
98+
echo "Updating distribution in changes file..."\n\
99+
sed -i -e "s/Distribution: unstable/Distribution: ${DEB_TARGET}/g" flare_*.changes\n\
100+
fi\n\
101+
\n\
102+
# Show results\n\
103+
echo "=== Build Results ==="\n\
104+
cd /build\n\
105+
ls -la *.deb *.ddeb *.dsc *.tar.* *.changes 2>/dev/null || echo "No package files found in /build"\n\
106+
\n\
107+
# Copy to output directory from parent (where debuild creates files)\n\
108+
mkdir -p /output\n\
109+
find /build -maxdepth 1 -name "*.deb" -exec cp {} /output/ \\;\n\
110+
find /build -maxdepth 1 -name "*.ddeb" -exec cp {} /output/ \\;\n\
111+
find /build -maxdepth 1 -name "*.dsc" -exec cp {} /output/ \\;\n\
112+
find /build -maxdepth 1 -name "*.tar.*" -exec cp {} /output/ \\;\n\
113+
find /build -maxdepth 1 -name "*.changes" -exec cp {} /output/ \\;\n\
114+
\n\
115+
echo "Package files copied to /output/"\n\
116+
ls -la /output/\n\
117+
' > /usr/local/bin/build-package.sh && \
118+
chmod +x /usr/local/bin/build-package.sh
119+
120+
# Set entrypoint
121+
ENTRYPOINT ["/usr/local/bin/build-package.sh"]

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ $ make
110110
$ make test
111111
```
112112

113+
## Build Debian Package with Docker
114+
115+
```bash
116+
# Build Debian package
117+
$ ./build-debian-docker.sh
118+
119+
# Install the package
120+
$ sudo dpkg -i debian-packages/kvs-flare*.deb
121+
```
122+
113123
## Create configuration file
114124
Copy default configuration files from `etc`, and modify it.
115125
```

build-debian-docker.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
# Docker-based Debian package build script for kvs-flare
4+
set -e
5+
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
IMAGE_NAME="flare-debian-builder"
8+
CONTAINER_NAME="flare-build-$(date +%s)"
9+
10+
echo "=== Flare Debian Package Build (Docker) ==="
11+
echo "Script directory: $SCRIPT_DIR"
12+
echo "Docker image: $IMAGE_NAME"
13+
echo "Container: $CONTAINER_NAME"
14+
15+
# Build the Docker image
16+
echo "Building Docker image..."
17+
docker build -f "$SCRIPT_DIR/Dockerfile.debian-build" -t "$IMAGE_NAME" "$SCRIPT_DIR"
18+
19+
# Create output directory
20+
mkdir -p "$SCRIPT_DIR/debian-packages"
21+
22+
# Run the build container
23+
echo "Running Debian package build in Docker..."
24+
docker run --rm \
25+
--name "$CONTAINER_NAME" \
26+
--platform linux/x86_64 \
27+
-v "$SCRIPT_DIR/debian-packages:/output" \
28+
"$IMAGE_NAME"
29+
30+
echo ""
31+
echo "=== Build Complete ==="
32+
echo "Debian packages are available in: $SCRIPT_DIR/debian-packages/"
33+
ls -la "$SCRIPT_DIR/debian-packages/"
34+
35+
echo ""
36+
echo "To install the package:"
37+
echo " sudo dpkg -i $SCRIPT_DIR/debian-packages/kvs-flare*.deb"
38+
echo " sudo apt-get install -f # to fix any dependency issues"

debian/rules

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,21 @@ ifneq ($(ENABLE_TEST),true)
2727
CONFIGURE_OPT += --without-cutter
2828
endif
2929

30-
CFLAGS = -Wall -g
30+
CFLAGS = -Wall -g -Wno-narrowing
31+
CXXFLAGS = -Wall -g -Wno-narrowing
3132

3233
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
3334
CFLAGS += -O0
35+
CXXFLAGS += -O0
3436
else
3537
CFLAGS += -O2
38+
CXXFLAGS += -O2
3639
endif
3740

3841
config.status: configure
3942
dh_testdir
4043
# Add here commands to configure the package.
41-
./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info $(CONFIGURE_OPT) CFLAGS="$(CFLAGS)" LDFLAGS="-Wl,-z,defs"
44+
./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info $(CONFIGURE_OPT) CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="-Wl,-z,defs"
4245

4346

4447
#Architecture

flake.lock

Lines changed: 21 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)