Update Debian package build

This commit is contained in:
Joshua Boniface 2019-02-05 18:40:50 -05:00
parent 546f4cd46f
commit c846da4f9e
4 changed files with 94 additions and 37 deletions

View File

@ -1,23 +1,40 @@
FROM debian:9 FROM debian:9
ARG SOURCEDIR=/repo # Docker build arguments
ARG SOURCE_DIR=/jellyfin
ARG PLATFORM_DIR=/jellyfin/deployment/debian-package-x64
ARG ARTIFACT_DIR=/dist
ARG SDK_VERSION=2.2
# Docker run environment
ENV SOURCE_DIR=/jellyfin
ENV ARTIFACT_DIR=/dist
ENV DEB_BUILD_OPTIONS=noddebs ENV DEB_BUILD_OPTIONS=noddebs
# https://dotnet.microsoft.com/download/linux-package-manager/debian9/sdk-current # Prepare Debian build environment
RUN apt-get update \ RUN apt-get update \
&& apt-get install -y apt-transport-https debhelper gnupg wget devscripts \ && apt-get install -y apt-transport-https debhelper gnupg wget devscripts mmv libc6-dev libcurl4-openssl-dev libfontconfig1-dev libfreetype6-dev
&& wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg \
# Install dotnet repository
# https://dotnet.microsoft.com/download/linux-package-manager/debian9/sdk-current
RUN wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg \
&& mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/ \ && mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/ \
&& wget -q https://packages.microsoft.com/config/debian/9/prod.list \ && wget -q https://packages.microsoft.com/config/debian/9/prod.list \
&& mv prod.list /etc/apt/sources.list.d/microsoft-prod.list \ && mv prod.list /etc/apt/sources.list.d/microsoft-prod.list \
&& chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg \ && chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg \
&& chown root:root /etc/apt/sources.list.d/microsoft-prod.list \ && chown root:root /etc/apt/sources.list.d/microsoft-prod.list \
&& apt-get update && apt-get update \
&& apt-get install -y dotnet-sdk-${SDK_VERSION}
WORKDIR ${SOURCEDIR} # Link to docker-build script
COPY . . RUN ln -sf ${PLATFORM_DIR}/docker-build.sh /docker-build.sh
COPY ./deployment/debian-package-x64/pkg-src ./debian
RUN yes | mk-build-deps -i debian/control \ # Link to Debian source dir; mkdir needed or it fails, can't force dest
&& dpkg-buildpackage -us -uc RUN mkdir -p ${SOURCE_DIR} && ln -sf ${PLATFORM_DIR}/pkg-src ${SOURCE_DIR}/debian
WORKDIR / # Prepare artifact volume
VOLUME ${ARTIFACT_DIR}/
# Copy repository
COPY . ${SOURCE_DIR}/
# Set docker-build entrypoint
ENTRYPOINT ["/docker-build.sh"]

View File

@ -2,6 +2,29 @@
source ../common.build.sh source ../common.build.sh
VERSION=`get_version ../..` keep_artifacts="${1}"
clean_jellyfin ../.. Release `pwd`/dist/jellyfin_${VERSION} WORKDIR="$( pwd )"
VERSION="$( grep '^jellyfin' ${WORKDIR}/pkg-src/changelog | head -1 | awk -F '[()]' '{ print $2 }' )"
package_temporary_dir="${WORKDIR}/pkg-dist-tmp"
output_dir="${WORKDIR}/pkg-dist"
current_user="$( whoami )"
image_name="jellyfin-debian-build"
rm -rf "${package_temporary_dir}" &>/dev/null \
|| sudo rm -rf "${package_temporary_dir}" &>/dev/null
rm -rf "${output_dir}" &>/dev/null \
|| sudo rm -rf "${output_dir}" &>/dev/null
if [[ ${keep_artifacts} == 'n' ]]; then
docker_sudo=""
if [[ ! -z $(id -Gn | grep -q 'docker') ]] \
&& [[ ! ${EUID:-1000} -eq 0 ]] \
&& [[ ! ${USER} == "root" ]] \
&& [[ ! -z $( echo "${OSTYPE}" | grep -q "darwin" ) ]]; then
docker_sudo=sudo
fi
${docker_sudo} docker image rm ${image_name} --force
fi

View File

@ -0,0 +1,16 @@
#!/bin/bash
# Builds the DEB inside the Docker container
set -o errexit
set -o xtrace
# Move to source directory
pushd ${SOURCE_DIR}
# Build DEB
dpkg-buildpackage -us -uc
# Move the artifacts out
mkdir -p ${ARTIFACT_DIR}/deb
mv /jellyfin_* ${ARTIFACT_DIR}/deb/

View File

@ -2,30 +2,31 @@
source ../common.build.sh source ../common.build.sh
VERSION=`get_version ../..` WORKDIR="$( pwd )"
VERSION="$( grep '^jellyfin' ${WORKDIR}/pkg-src/changelog | head -1 | awk -F '[()]' '{ print $2 }' )"
# TODO get the version in the package automatically. And using the changelog to decide the debian package suffix version. package_temporary_dir="${WORKDIR}/pkg-dist-tmp"
output_dir="${WORKDIR}/pkg-dist"
current_user="$( whoami )"
image_name="jellyfin-debian-build"
# Build a Jellyfin .deb file with Docker on Linux # Determine if sudo should be used for Docker
# Places the output .deb file in the parent directory if [[ ! -z $(id -Gn | grep -q 'docker') ]] \
&& [[ ! ${EUID:-1000} -eq 0 ]] \
&& [[ ! ${USER} == "root" ]] \
&& [[ ! -z $( echo "${OSTYPE}" | grep -q "darwin" ) ]]; then
docker_sudo="sudo"
else
docker_sudo=""
fi
package_temporary_dir="`pwd`/pkg-dist-tmp" # Set up the build environment Docker image
output_dir="`pwd`/pkg-dist" ${docker_sudo} docker build ../.. -t "${image_name}" -f ./Dockerfile
current_user="`whoami`" # Build the DEBs and copy out to ${package_temporary_dir}
image_name="jellyfin-debuild" ${docker_sudo} docker run --rm -v "${package_temporary_dir}:/dist" "${image_name}"
# Correct ownership on the DEBs (as current user, then as root if that fails)
cleanup() { chown -R "${current_user}" "${package_temporary_dir}" &>/dev/null \
set +o errexit || sudo chown -R "${current_user}" "${package_temporary_dir}" &>/dev/null
docker image rm $image_name --force # Move the DEBs to the output directory
rm -rf "$package_temporary_dir" mkdir -p "${output_dir}"
} mv "${package_temporary_dir}"/deb/* "${output_dir}"
trap cleanup EXIT INT
docker build ../.. -t "$image_name" -f ./Dockerfile --build-arg SOURCEDIR="/jellyfin-${VERSION}"
mkdir -p "$package_temporary_dir"
mkdir -p "$output_dir"
docker run --rm -v "$package_temporary_dir:/temp" "$image_name" sh -c 'find / -maxdepth 1 -type f -name "jellyfin*" -exec mv {} /temp \;'
chown -R "$current_user" "$package_temporary_dir" \
|| sudo chown -R "$current_user" "$package_temporary_dir"
mv "$package_temporary_dir"/* "$output_dir"