diff --git a/Dockerfile.debian-build b/Dockerfile.debian-build new file mode 100644 index 0000000..25d878f --- /dev/null +++ b/Dockerfile.debian-build @@ -0,0 +1,121 @@ +FROM --platform=linux/x86_64 ubuntu:noble + +LABEL description="Flare Debian package builder" + +# Set environment variables to prevent interactive prompts +ENV DEBIAN_FRONTEND=noninteractive +ENV TZ=UTC + +# Update package manager and install build dependencies +RUN apt-get update && apt-get install -y \ + git \ + locales \ + zlib1g-dev \ + build-essential \ + autoconf \ + automake \ + libtool \ + libboost-all-dev \ + libhashkit-dev \ + libtokyocabinet-dev \ + libkyotocabinet-dev \ + uuid-dev \ + pkg-config \ + devscripts \ + debhelper \ + dh-make \ + dpkg-dev \ + fakeroot \ + lsb-release \ + && rm -rf /var/lib/apt/lists/* + +# Set locale +RUN locale-gen en_US.UTF-8 +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US:en +ENV LC_ALL en_US.UTF-8 + +# Create build directory +WORKDIR /build + +# Copy source code +COPY . /build/flare/ + +# Create build script +RUN echo '#!/bin/bash\n\ +set -e\n\ +\n\ +echo "=== Building Debian Package for kvs-flare ==="\n\ +\n\ +cd /build/flare\n\ +\n\ +# Set build variables\n\ +BUILD_TYPE=${BUILD_TYPE:-release}\n\ +MACHINE=$(uname -m)\n\ +DEB_ARCH=$(echo $MACHINE | sed -e "s/i686/i386/" -e "s/x86_64/amd64/")\n\ +DEB_TARGET=$(lsb_release -cs)\n\ +FLARE_VERSION=$(head -n 1 debian/changelog | awk "match(\\$0, /[0-9\\.\\-]+/) {print substr(\\$0, RSTART, RLENGTH)}")\n\ +FLARE_BUILD_VERSION=${FLARE_BUILD_VERSION:-1}\n\ +\n\ +echo "Build configuration:"\n\ +echo "BUILD_TYPE=$BUILD_TYPE"\n\ +echo "DEB_ARCH=$DEB_ARCH"\n\ +echo "DEB_TARGET=$DEB_TARGET"\n\ +echo "FLARE_VERSION=$FLARE_VERSION"\n\ +echo "FLARE_BUILD_VERSION=$FLARE_BUILD_VERSION"\n\ +\n\ +# Clean any existing build artifacts\n\ +if [ -f Makefile ]; then\n\ + make distclean || true\n\ +fi\n\ +\n\ +# Remove git files and build artifacts\n\ +find . -name ".git*" -exec rm -rf {} + 2>/dev/null || true\n\ +find . -name "*.o" -delete 2>/dev/null || true\n\ +find . -name "*.lo" -delete 2>/dev/null || true\n\ +find . -name ".libs" -exec rm -rf {} + 2>/dev/null || true\n\ +find . -name "autom4te.cache" -exec rm -rf {} + 2>/dev/null || true\n\ +\n\ +# Update debian/changelog with DEB_TARGET\n\ +if [ "$BUILD_TYPE" = "release" ] && [ -n "$FLARE_VERSION" ]; then\n\ + echo "Updating debian/changelog for release build..."\n\ + sed -i -e "s/${FLARE_VERSION}/${FLARE_VERSION}+${DEB_TARGET}${FLARE_BUILD_VERSION}/g" debian/changelog\n\ +fi\n\ +\n\ +# Prepare source\n\ +if [ ! -f configure ]; then\n\ + echo "Running autogen.sh..."\n\ + ./autogen.sh\n\ +fi\n\ +\n\ +# Build package with debuild\n\ +echo "Running debuild --no-tgz-check -uc -us..."\n\ +echo "y" | debuild --no-tgz-check -uc -us\n\ +\n\ +# Update distribution in changes file\n\ +cd /build\n\ +if ls flare_*.changes >/dev/null 2>&1; then\n\ + echo "Updating distribution in changes file..."\n\ + sed -i -e "s/Distribution: unstable/Distribution: ${DEB_TARGET}/g" flare_*.changes\n\ +fi\n\ +\n\ +# Show results\n\ +echo "=== Build Results ==="\n\ +cd /build\n\ +ls -la *.deb *.ddeb *.dsc *.tar.* *.changes 2>/dev/null || echo "No package files found in /build"\n\ +\n\ +# Copy to output directory from parent (where debuild creates files)\n\ +mkdir -p /output\n\ +find /build -maxdepth 1 -name "*.deb" -exec cp {} /output/ \\;\n\ +find /build -maxdepth 1 -name "*.ddeb" -exec cp {} /output/ \\;\n\ +find /build -maxdepth 1 -name "*.dsc" -exec cp {} /output/ \\;\n\ +find /build -maxdepth 1 -name "*.tar.*" -exec cp {} /output/ \\;\n\ +find /build -maxdepth 1 -name "*.changes" -exec cp {} /output/ \\;\n\ +\n\ +echo "Package files copied to /output/"\n\ +ls -la /output/\n\ +' > /usr/local/bin/build-package.sh && \ + chmod +x /usr/local/bin/build-package.sh + +# Set entrypoint +ENTRYPOINT ["/usr/local/bin/build-package.sh"] \ No newline at end of file diff --git a/README.md b/README.md index 51fe815..5b551ab 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,16 @@ $ make $ make test ``` +## Build Debian Package with Docker + +```bash +# Build Debian package +$ ./build-debian-docker.sh + +# Install the package +$ sudo dpkg -i debian-packages/kvs-flare*.deb +``` + ## Create configuration file Copy default configuration files from `etc`, and modify it. ``` diff --git a/build-debian-docker.sh b/build-debian-docker.sh new file mode 100755 index 0000000..0892b47 --- /dev/null +++ b/build-debian-docker.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# Docker-based Debian package build script for kvs-flare +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +IMAGE_NAME="flare-debian-builder" +CONTAINER_NAME="flare-build-$(date +%s)" + +echo "=== Flare Debian Package Build (Docker) ===" +echo "Script directory: $SCRIPT_DIR" +echo "Docker image: $IMAGE_NAME" +echo "Container: $CONTAINER_NAME" + +# Build the Docker image +echo "Building Docker image..." +docker build -f "$SCRIPT_DIR/Dockerfile.debian-build" -t "$IMAGE_NAME" "$SCRIPT_DIR" + +# Create output directory +mkdir -p "$SCRIPT_DIR/debian-packages" + +# Run the build container +echo "Running Debian package build in Docker..." +docker run --rm \ + --name "$CONTAINER_NAME" \ + --platform linux/x86_64 \ + -v "$SCRIPT_DIR/debian-packages:/output" \ + "$IMAGE_NAME" + +echo "" +echo "=== Build Complete ===" +echo "Debian packages are available in: $SCRIPT_DIR/debian-packages/" +ls -la "$SCRIPT_DIR/debian-packages/" + +echo "" +echo "To install the package:" +echo " sudo dpkg -i $SCRIPT_DIR/debian-packages/kvs-flare*.deb" +echo " sudo apt-get install -f # to fix any dependency issues" \ No newline at end of file diff --git a/debian/rules b/debian/rules index 25546ff..27d7e99 100755 --- a/debian/rules +++ b/debian/rules @@ -27,18 +27,21 @@ ifneq ($(ENABLE_TEST),true) CONFIGURE_OPT += --without-cutter endif -CFLAGS = -Wall -g +CFLAGS = -Wall -g -Wno-narrowing +CXXFLAGS = -Wall -g -Wno-narrowing ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) CFLAGS += -O0 + CXXFLAGS += -O0 else CFLAGS += -O2 + CXXFLAGS += -O2 endif config.status: configure dh_testdir # Add here commands to configure the package. - ./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" + ./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" #Architecture diff --git a/flake.lock b/flake.lock index 29ffd2a..1b00f59 100644 --- a/flake.lock +++ b/flake.lock @@ -1,12 +1,15 @@ { "nodes": { "flake-utils": { + "inputs": { + "systems": "systems" + }, "locked": { - "lastModified": 1644229661, - "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "owner": "numtide", "repo": "flake-utils", - "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { @@ -234,6 +237,21 @@ "flare-tools": "flare-tools_2", "nixpkgs": "nixpkgs_4" } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root",