Skip to content

Commit

Permalink
Dockerfile to build DEB packages regardless of host OS
Browse files Browse the repository at this point in the history
  • Loading branch information
ayurchen committed May 2, 2024
1 parent d5e7d23 commit cd7fcea
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 5 deletions.
16 changes: 16 additions & 0 deletions packaging/deb/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Use a base image with a Linux distribution of your choice
# that supports RPM package building, e.g., CentOS or Fedora.

ARG base=debian:stable
FROM ${base}

# Install necessary packages to build DEB
RUN apt-get update && \
apt-get install -y git dpkg-dev && \
apt-get install -y autoconf automake debhelper libtool && \
rm -rf /var/lib/apt/lists/*

# Set up the build script to be executed on docker run
COPY entrypoint.sh /root
WORKDIR /root
ENTRYPOINT /root/entrypoint.sh
16 changes: 16 additions & 0 deletions packaging/deb/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh -eu

# This script only relies on access to GitHub and can be run from anywhere.
# Resulting packages will be placed in the current working directory.
# Environment variables:
# GIT_BRANCH - which branch to build
# BASE - which distribution to use for packaging

GIT_BRANCH=${GIT_BRANCH:='master'}
BASE=${BASE:='debian:stable'}

docker buildx build -t glb-builder-${BASE} --build-arg base=${BASE} \
https://github.com/codership/glb.git\#${GIT_BRANCH}:packaging/deb/
mkdir ${BASE} # output dir for packages
docker run -v ${PWD}:/output --env GIT_BRANCH=${GIT_BRANCH} \
--env BASE=${BASE} glb-builder-${BASE}
21 changes: 21 additions & 0 deletions packaging/deb/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash -eu

# Clone the GitHub repository using the specified branch
git clone --depth 1 --branch ${GIT_BRANCH:='master'} https://github.com/codership/glb /root/glb
cd glb

# Build the DEB package
dpkg-buildpackage -uc -us

# Verify if the DEB build was successful
if [ $? -eq 0 ]; then
echo "DEB package built successfully."
else
echo "Error: DEB package build failed."
exit 1
fi

# Move the DEB package to the mounted volume
OUTPUT=/output/${BASE}/
mv /root/*.deb ${OUTPUT}
echo "DEB package moved to: ${OUTPUT}"
8 changes: 5 additions & 3 deletions packaging/rpm/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
# GIT_BRANCH - which branch to build
# BASE - which distribution to use for packaging

export GIT_BRANCH=${GIT_BRANCH:='master'}
export BASE=${BASE:='rockylinux:8'}
GIT_BRANCH=${GIT_BRANCH:='master'}
BASE=${BASE:='rockylinux:8'}

docker buildx build -t glb-builder-${BASE} --build-arg base=${BASE} \
https://github.com/codership/glb.git\#${GIT_BRANCH}:packaging/rpm/
docker run -v ${PWD}:/output --env GIT_BRANCH=${GIT_BRANCH} glb-builder-${BASE}
mkdir ${BASE} # output dir for packages
docker run -v ${PWD}:/output --env GIT_BRANCH=${GIT_BRANCH} \
--env BASE=${BASE} glb-builder-${BASE}
5 changes: 3 additions & 2 deletions packaging/rpm/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ else
fi

# Move the RPM package to the mounted volume
mv "${RPMBUILD_DIR}/RPMS/x86_64/"*.rpm "/output/"
echo "RPM package moved to: /output/"
OUTPUT="/output/${BASE}"
mv "${RPMBUILD_DIR}/RPMS/x86_64/"*.rpm "${OUTPUT}"
echo "RPM package moved to: ${OUTPUT}"

0 comments on commit cd7fcea

Please sign in to comment.