From c846da4f9e7833252f209b2698c3b6359b20069d Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Tue, 5 Feb 2019 18:40:50 -0500 Subject: [PATCH] Update Debian package build --- deployment/debian-package-x64/Dockerfile | 39 ++++++++++----- deployment/debian-package-x64/clean.sh | 27 +++++++++- deployment/debian-package-x64/docker-build.sh | 16 ++++++ deployment/debian-package-x64/package.sh | 49 ++++++++++--------- 4 files changed, 94 insertions(+), 37 deletions(-) create mode 100755 deployment/debian-package-x64/docker-build.sh diff --git a/deployment/debian-package-x64/Dockerfile b/deployment/debian-package-x64/Dockerfile index 2afe6c1d3..787f1d182 100644 --- a/deployment/debian-package-x64/Dockerfile +++ b/deployment/debian-package-x64/Dockerfile @@ -1,23 +1,40 @@ 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 -# https://dotnet.microsoft.com/download/linux-package-manager/debian9/sdk-current +# Prepare Debian build environment RUN apt-get update \ - && apt-get install -y apt-transport-https debhelper gnupg wget devscripts \ - && wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg \ + && apt-get install -y apt-transport-https debhelper gnupg wget devscripts mmv libc6-dev libcurl4-openssl-dev libfontconfig1-dev libfreetype6-dev + +# 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/ \ && wget -q https://packages.microsoft.com/config/debian/9/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/sources.list.d/microsoft-prod.list \ - && apt-get update + && apt-get update \ + && apt-get install -y dotnet-sdk-${SDK_VERSION} -WORKDIR ${SOURCEDIR} -COPY . . -COPY ./deployment/debian-package-x64/pkg-src ./debian +# Link to docker-build script +RUN ln -sf ${PLATFORM_DIR}/docker-build.sh /docker-build.sh -RUN yes | mk-build-deps -i debian/control \ - && dpkg-buildpackage -us -uc +# Link to Debian source dir; mkdir needed or it fails, can't force dest +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"] diff --git a/deployment/debian-package-x64/clean.sh b/deployment/debian-package-x64/clean.sh index 3df2d7796..101ba1fb6 100755 --- a/deployment/debian-package-x64/clean.sh +++ b/deployment/debian-package-x64/clean.sh @@ -2,6 +2,29 @@ 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 diff --git a/deployment/debian-package-x64/docker-build.sh b/deployment/debian-package-x64/docker-build.sh new file mode 100755 index 000000000..83654b8ce --- /dev/null +++ b/deployment/debian-package-x64/docker-build.sh @@ -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/ diff --git a/deployment/debian-package-x64/package.sh b/deployment/debian-package-x64/package.sh index dec953961..11da66aaa 100755 --- a/deployment/debian-package-x64/package.sh +++ b/deployment/debian-package-x64/package.sh @@ -2,30 +2,31 @@ 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 -# Places the output .deb file in the parent directory +# Determine if sudo should be used for Docker +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" -output_dir="`pwd`/pkg-dist" -current_user="`whoami`" -image_name="jellyfin-debuild" - -cleanup() { - set +o errexit - docker image rm $image_name --force - rm -rf "$package_temporary_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" +# Set up the build environment Docker image +${docker_sudo} docker build ../.. -t "${image_name}" -f ./Dockerfile +# Build the DEBs and copy out to ${package_temporary_dir} +${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) +chown -R "${current_user}" "${package_temporary_dir}" &>/dev/null \ + || sudo chown -R "${current_user}" "${package_temporary_dir}" &>/dev/null +# Move the DEBs to the output directory +mkdir -p "${output_dir}" +mv "${package_temporary_dir}"/deb/* "${output_dir}"