Bläddra i källkod

Add new centralized build script and README

Joshua Boniface 6 år sedan
förälder
incheckning
f952988fb3
6 ändrade filer med 312 tillägg och 87 borttagningar
  1. 199 0
      build
  2. 102 5
      deployment/README.md
  3. 0 21
      deployment/clean.sh
  4. 0 20
      deployment/collect_all.sh
  5. 11 7
      deployment/common.build.sh
  6. 0 34
      deployment/make.sh

+ 199 - 0
build

@@ -0,0 +1,199 @@
+#!/usr/bin/env bash
+
+# build - build Jellyfin binaries or packages
+
+set -o errexit
+set -o pipefail
+
+# The list of possible package actions (except 'clean')
+declare -a actions=( 'build' 'package' 'sign' 'publish' )
+
+# The list of possible platforms, based on directories under 'deployment/'
+declare -a platforms=( $(
+    find deployment/ -maxdepth 1 -mindepth 1 -type d | sed 's/deployment\///' | sort
+) )
+
+# The list of standard dependencies required by all build scripts; individual
+# action scripts may specify their own dependencies
+declare -a dependencies
+dependencies=( 'tar' 'zip' 'dotnet' )
+
+usage() {
+    echo -e "build - build Jellyfin binaries or packages"
+    echo -e ""
+    echo -e "Usage:"
+    echo -e " $ build --list-platforms"
+    echo -e " $ build --list-actions <platform>"
+    echo -e " $ build [-b/--web-branch <web_branch>] <platform> <action>"
+    echo -e ""
+    echo -e "The web_branch defaults to 'master'."
+    echo -e "To build all platforms, use 'all'."
+    echo -e "To perform all build actions, use 'all'."
+    echo -e "Build output files are collected at '../jellyfin-build/<platform>'."
+}
+
+if [[ -z $1 ]]; then
+    usage
+    exit 0
+fi
+
+# List all available platforms then exit
+if [[ $1 == '--list-platforms' ]]; then
+    echo -e "Available platforms:"
+    for platform in ${platforms[@]}; do
+        echo -e "  ${platform}"
+    done
+    exit 0
+fi
+
+# List all available actions for a given platform then exit
+if [[ $1 == '--list-actions' ]]; then
+    platform="$2"
+    if [[ ! " ${platforms[@]} " =~ " ${platform} " ]]; then
+        echo "ERROR: Platform $platform does not exist."
+        exit 1
+    fi
+    echo -e "Available actions for platform ${platform}:"
+    for action in ${actions[@]}; do
+        if [[ -f deployment/${platform}/${action}.sh ]]; then
+            echo -e "  ${action}"
+        fi
+    done
+    exit 0
+fi
+
+# Parse branch option
+if [[ $1 == '-b' || $1 == '--web-branch' ]]; then
+	web_branch="$2"
+	shift 2
+else
+    web_branch="master"
+fi
+
+# Parse platform option
+if [[ -n $1 ]]; then
+    cli_platform="$1"
+    shift
+else
+    echo "ERROR: A platform must be specified. Use 'all' to specify all platforms."
+    exit 1
+fi
+if [[ $cli_platform == 'all' ]]; then
+    declare -a platform=( ${platforms[@]} )
+else
+    if [[ ! " ${platforms[@]} " =~ " ${cli_platform} " ]]; then
+        echo "ERROR: Platform $cli_platform is invalid. Use the '--list-platforms' option to list available platforms."
+        exit 1
+    else
+        declare -a platform=( "${cli_platform}" )
+    fi
+fi
+
+# Parse action option
+if [[ -n $1 ]]; then
+    cli_action="$1"
+    shift
+else
+    echo "ERROR: An action must be specified. Use 'all' to specify all actions."
+    exit 1
+fi
+if [[ $cli_action == 'all' ]]; then
+    declare -a action=( ${actions[@]} )
+else
+    if [[ ! " ${actions[@]} " =~ " ${cli_action} " ]]; then
+        echo "ERROR: Action $cli_action is invalid. Use the '--list-actions <platform>' option to list available actions."
+        exit 1
+    else
+        declare -a action=( "${cli_action}" )
+    fi
+fi
+
+# Verify required utilities are installed
+missing_deps=()
+for utility in ${dependencies[@]}; do
+    if ! which ${utility} &>/dev/null; then
+        missing_deps+=( ${utility} )
+    fi
+done
+
+# Error if we're missing anything
+if [[ ${#missing_deps[@]} -gt 0 ]]; then
+    echo -e "ERROR: This script requires the following missing utilities:"
+    for utility in ${missing_deps[@]}; do
+        echo -e "  ${utility}"
+    done
+    exit 1
+fi
+
+# Parse platform-specific dependencies
+for target_platform in ${platform[@]}; do
+    # Read platform-specific dependencies
+    if [[ -f deployment/${target_platform}/dependencies.txt ]]; then
+        platform_dependencies="$( grep -v '^#' deployment/${target_platform}/dependencies.txt )"
+
+        # Verify required utilities are installed
+        missing_deps=()
+        for utility in ${platform_dependencies[@]}; do
+            if ! which ${utility} &>/dev/null; then
+                missing_deps+=( ${utility} )
+            fi
+        done
+
+        # Error if we're missing anything
+        if [[ ${#missing_deps[@]} -gt 0 ]]; then
+            echo -e "ERROR: The ${target_platform} platform requires the following utilities:"
+            for utility in ${missing_deps[@]}; do
+                echo -e "  ${utility}"
+            done
+            exit 1
+        fi
+    fi
+done
+
+# Initialize submodules
+git submodule update --init --recursive
+
+# configure branch
+pushd MediaBrowser.WebDashboard/jellyfin-web
+
+if ! git diff-index --quiet HEAD --; then
+    popd
+    echo
+    echo "ERROR: Your 'jellyfin-web' submodule working directory is not clean!"
+    echo "This script will overwrite your unstaged and unpushed changes."
+    echo "Please do development on 'jellyfin-web' outside of the submodule."
+    exit 1
+fi
+
+git fetch --all
+git checkout origin/${web_branch} || {
+    echo "Error: 'jellyfin-web' branch ${web_branch} is invalid."
+    exit 1
+}
+popd
+
+# Execute each platform and action in order, if said action is enabled
+pushd deployment/
+for target_platform in ${platform[@]}; do
+    echo -e "> Processing platform ${target_platform}"
+    pushd ${target_platform}
+    for target_action in ${action[@]}; do
+        echo -e ">> Processing action ${target_action}"
+        if [[ -f ${target_action}.sh && -x ${target_action}.sh ]]; then
+            ./${target_action}.sh
+        fi
+    done
+    if [[ -d pkg-dist/ ]]; then
+        echo -e ">> Collecting build artifacts"
+        target_dir="../../../jellyfin-build/${target_platform}"
+        mkdir -p ${target_dir}
+        mv pkg-dist/* ${target_dir}/
+
+        echo -e ">> Processing action clean"
+        if [[ -f clean.sh && -x clean.sh ]]; then
+            ./clean.sh 
+        fi
+    fi
+    popd
+done
+popd

+ 102 - 5
deployment/README.md

@@ -1,8 +1,105 @@
-# Build scripts
+# Jellyfin Packaging
 
 
-All `build.sh` and `package.sh` scripts are for *nix platforms (or WSL on Windows 10).
+This directory contains the packaging configuration of Jellyfin for multiple platforms. The specification is below; all package platforms must follow the specification to be compatable with the central `build` script.
 
 
-After running both, check the `*/pkg-dist/` folders for the archives and packages.
+## Package List
+
+### Operating System Packages
+
+* `debian-package-x64`: Package for Debian and Ubuntu amd64 systems.
+* `fedora-package-x64`: Package for Fedora, CentOS, and Red Hat Enterprise Linux amd64 systems.
+
+### Portable Builds (archives)
+
+* `debian-x64`: Portable binary archive for Debian amd64 systems.
+* `ubuntu-x64`: Portable binary archive for Ubuntu amd64 systems.
+* `linux-x64`: Portable binary archive for generic Linux amd64 systems.
+* `osx-x64`: Portable binary archive for MacOS amd64 systems.
+* `win-x64`: Portable binary archive for Windows amd64 systems.
+* `win-x86`: Portable binary archive for Windows i386 systems.
+
+### Other Builds
+
+These builds are not necessarily run from the `build` script, but are present for other platforms.
+
+* `framework`: Compiled `.dll` for use with .NET Core runtime on any system.
+* `docker`: Docker manifests for auto-publishing.
+* `unraid`: unRaid Docker template; not built by `build` but imported into unRaid directly.
+* `win-generic`: Portable binary for generic Windows systems.
+
+## Package Specification
+
+### Action Scripts
+
+* Actions are defined in BASH scripts with the name `<action>.sh` within the framework directory.
+
+* The list of valid actions are:
+
+    1. `build`: Builds a set of binaries.
+    2. `package`: Assembles the compiled binaries into a package.
+    3. `sign`: Performs signing actions on a package.
+    4. `publish`: Performs a publishing action for a package.
+    5. `clean`: Cleans up any artifacts from the previous actions.
+
+* All package actions are optional, however at least one should generate output files, and any that do should contain a `clean` action.
+
+* Actions are executed in the order specified above, and later actions may depend on former actions.
+
+* Actions except for `clean` should `set -o errexit` to terminate on failed actions.
+
+* The `clean` action should always `exit 0` even if no work is done or it fails.
+
+### Output Files
+
+* Upon completion of the defined actions, at least one output file must be created in the `<platform>/pkg-dist` directory.
+
+* Output files will be moved to the directory `jellyfin-build/<platform>` one directory above the repository root upon completion.
+
+### Common Functions
+
+* A number of common functions are defined in `deployment/common.build.sh` for use by platform scripts.
+
+* Each action script should import the common functions to define a number of standard variables.
+
+* The common variables are:
+
+    * `ROOT`: The Jellyfin repostiory root, usually `../..`.
+    * `CONFIG`: The .NET config, usually `Release`.
+    * `DOTNETRUNTIME`: The .NET `--runtime` value, platform-dependent.
+    * `OUTPUT_DIR`: The intermediate output dir, usually `./dist/jellyfin_${VERSION}`.
+    * `BUILD_CONTEXT`: The Docker build context, usually `../..`.
+    * `DOCKERFILE`: The Dockerfile, usually `Dockerfile` in the platform directory.
+    * `IMAGE_TAG`: A tag for the built Docker image.
+    * `PKG_DIR`: The final binary output directory for collection, invariably `pkg-dist`.
+    * `ARCHIVE_CMD`: The compression/archive command for release archives, usually `tar -xvzf` or `zip`.
+
+#### `get_version`
+
+Reads the version information from `SharedVersion.cs`.
+
+**Arguments:** `ROOT`
+
+#### `build_jellyfin`
+
+Build a standard self-contained binary in the current OS context.
+
+**Arguments:** `ROOT` `CONFIG` `DOTNETRUNTIME` `OUTPUT_DIR`
+
+#### `build_jellyfin_docker`
+
+Build a standard self-contained binary in a Docker image.
+
+**Arguments:** `BUILD_CONTEXT` `DOCKERFILE` `IMAGE_TAG`
+
+#### `clean_jellyfin`
+
+Clean up a build for housekeeping.
+
+**Arguments:** `ROOT` `CONFIG` `OUTPUT_DIR` `PKG_DIR`
+
+#### `package_portable`
+
+Produce a compressed archive.
+
+**Arguments:** `ROOT` `OUTPUT_DIR` `PKG_DIR` `ARCHIVE_CMD`
 
 
-`build_all.sh` will invoke every build and package script.
-Use `collect_all.sh` to copy all artifact to one directory for easy uploading.

+ 0 - 21
deployment/clean.sh

@@ -1,21 +0,0 @@
-#!/usr/bin/env bash
-
-set -e
-
-# Execute every clean.sh scripts in every folder.
-echo "Running for platforms '$@'."
-for directory in */ ; do
-    platform=`basename "${directory}"`
-    if [[ $@ == *"$platform"* || $@ = *"all"* ]]; then
-        echo "Processing ${platform}"
-        pushd "$platform"
-        if [ -f clean.sh ]; then
-            echo ./clean.sh 
-        fi
-        popd
-    else
-        echo "Skipping $platform."
-    fi
-done
-
-rm -rf ./collect-dist

+ 0 - 20
deployment/collect_all.sh

@@ -1,20 +0,0 @@
-#!/usr/bin/env bash
-
-source common.build.sh
-
-VERSION=`get_version ..`
-
-COLLECT_DIR="./collect-dist"
-
-mkdir -p ./collect-dist
-
-DIRS=`find . -type d -name "pkg-dist"`
-
-while read directory
-do
-    echo "Collecting everything from '$directory'.."
-    PLATFORM=$(basename "$(dirname "$directory")")
-    # Copy all artifacts with extensions tar.gz, deb, exe, zip, rpm and add the platform name to resolve any duplicates.
-    find $directory \( -name "jellyfin*.tar.gz" -o -name "jellyfin*.deb" -o -name "jellyfin*.rpm" -o -name "jellyfin*.zip" -o -name "jellyfin*.exe" \) -exec sh -c 'cp "$1" "'${COLLECT_DIR}'/jellyfin_'${PLATFORM}'_${1#*jellyfin}"' _ {} \;
-
-done <<< "${DIRS}"

+ 11 - 7
deployment/common.build.sh

@@ -16,6 +16,16 @@ DEFAULT_OUTPUT_DIR="dist/jellyfin-git"
 DEFAULT_PKG_DIR="pkg-dist"
 DEFAULT_PKG_DIR="pkg-dist"
 DEFAULT_DOCKERFILE="Dockerfile"
 DEFAULT_DOCKERFILE="Dockerfile"
 DEFAULT_IMAGE_TAG="jellyfin:"`git rev-parse --abbrev-ref HEAD`
 DEFAULT_IMAGE_TAG="jellyfin:"`git rev-parse --abbrev-ref HEAD`
+DEFAULT_ARCHIVE_CMD="tar -xvzf"
+
+# Parse the version from the AssemblyVersion
+get_version()
+(
+    local ROOT=${1-$DEFAULT_ROOT}
+    grep "AssemblyVersion" ${ROOT}/SharedVersion.cs \
+        | sed -E 's/\[assembly: ?AssemblyVersion\("([0-9\.]+)"\)\]/\1/' \
+        | sed -E 's/.0$//'
+)
 
 
 # Run a build
 # Run a build
 build_jellyfin()
 build_jellyfin()
@@ -77,19 +87,13 @@ clean_jellyfin()
     fi
     fi
 )
 )
 
 
-# Parse the version from the AssemblyVersion
-get_version()
-(
-    local ROOT=${1-$DEFAULT_ROOT}
-    grep "AssemblyVersion" ${ROOT}/SharedVersion.cs | sed -E 's/\[assembly: ?AssemblyVersion\("([0-9\.]+)"\)\]/\1/'  | sed -E 's/.0$//'
-)
-
 # Packages the output folder into an archive.
 # Packages the output folder into an archive.
 package_portable()
 package_portable()
 (
 (
     local ROOT=${1-$DEFAULT_ROOT}
     local ROOT=${1-$DEFAULT_ROOT}
     local OUTPUT_DIR=${2-$DEFAULT_OUTPUT_DIR}
     local OUTPUT_DIR=${2-$DEFAULT_OUTPUT_DIR}
     local PKG_DIR=${3-$DEFAULT_PKG_DIR}
     local PKG_DIR=${3-$DEFAULT_PKG_DIR}
+    local ARCHIVE_CMD=${4-$DEFAULT_ARCHIVE_CMD}
     # Package portable build result
     # Package portable build result
     if [ -d ${OUTPUT_DIR} ]; then        
     if [ -d ${OUTPUT_DIR} ]; then        
         echo -e "${CYAN}Packaging build in '${OUTPUT_DIR}' for `basename "${OUTPUT_DIR}"` to '${PKG_DIR}' with root '${ROOT}'.${NC}"
         echo -e "${CYAN}Packaging build in '${OUTPUT_DIR}' for `basename "${OUTPUT_DIR}"` to '${PKG_DIR}' with root '${ROOT}'.${NC}"

+ 0 - 34
deployment/make.sh

@@ -1,34 +0,0 @@
-#!/usr/bin/env bash
-
-git submodule update --init --recursive
-
-pushd ../Jellyfin.Versioning
-./update-version
-popd
-
-#TODO enabled proper flag parsing for enabling and disabling building, signing, packaging and publishing
-
-# Execute all build.sh, package.sh, sign.sh and publish.sh scripts in every folder. In that order. Script should check for artifacts themselves.
-echo "Running for platforms '$@'."
-for directory in */ ; do
-    platform=`basename "${directory}"`
-    if [[ $@ == *"$platform"* || $@ = *"all"* ]]; then
-        echo "Processing ${platform}"
-        pushd "$platform"
-        if [ -f build.sh ]; then
-            ./build.sh 
-        fi  
-        if [ -f package.sh ]; then
-            ./package.sh
-        fi
-        if [ -f sign.sh ]; then
-            ./sign.sh
-        fi
-        if [ -f publish.sh ]; then
-            ./publish.sh
-        fi
-        popd
-    else
-        echo "Skipping $platform."
-    fi
-done