Skip to content

Commit

Permalink
Build scripts and build system consolidation.
Browse files Browse the repository at this point in the history
Squashed commit.
  • Loading branch information
EraYaN committed Jan 10, 2019
1 parent 3d867c2 commit 399a079
Show file tree
Hide file tree
Showing 66 changed files with 605 additions and 217 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
Dockerfile
CONTRIBUTORS.md
README.md
deployment/*/dist
deployment/*/pkg-dist
deployment/collect-dist/
2 changes: 1 addition & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ steps:
- name: build
image: microsoft/dotnet:2-sdk
commands:
- dotnet publish --configuration release --output /release
- dotnet publish --configuration release --output /release Jellyfin.Server
34 changes: 21 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
!*

.directory

#################
Expand Down Expand Up @@ -49,6 +47,8 @@ ProgramData-UI*/
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

.vs/

# User-specific files
*.suo
*.user
Expand Down Expand Up @@ -204,7 +204,6 @@ $RECYCLE.BIN/
# Mac crap
.DS_Store


#############
## Python
#############
Expand Down Expand Up @@ -234,23 +233,32 @@ pip-log.txt

#Mr Developer
.mr.developer.cfg
/.vs

##########
# Rider
##########
.idea/

##########
# Visual Studio Code
##########
.vscode/

#########################
# Debian build artifacts
# Build artifacts
#########################

debian/.debhelper/
debian/*.debhelper
debian/debhelper-build-stamp
debian/files
debian/jellyfin.substvars
debian/jellyfin/

# Artifacts for debian-x64
deployment/debian-x64/pkg-src/.debhelper/
deployment/debian-x64/pkg-src/*.debhelper
deployment/debian-x64/pkg-src/debhelper-build-stamp
deployment/debian-x64/pkg-src/files
deployment/debian-x64/pkg-src/jellyfin.substvars
deployment/debian-x64/pkg-src/jellyfin/
# Don't ignore the debian/bin folder
!debian/bin/
!deployment/debian-x64/pkg-src/bin/

deployment/**/dist/
deployment/**/pkg-dist/
deployment/collect-dist/

24 changes: 0 additions & 24 deletions build-deb.sh

This file was deleted.

37 changes: 0 additions & 37 deletions debian/bin/jellyfin-sudoers

This file was deleted.

18 changes: 0 additions & 18 deletions debian/bin/restart.sh

This file was deleted.

1 change: 0 additions & 1 deletion debian/source/options

This file was deleted.

8 changes: 8 additions & 0 deletions deployment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Build scripts

All `build.sh` and `package.sh` scripts are for *nix platforms (or WSL on Windows 10).

After running both, check the `*/pkg-dist/` folders for the archives and packages.

`build_all.sh` will invoke every build and package script.
Use `collect_all.sh` to copy all artifact to one directory for easy uploading.
23 changes: 23 additions & 0 deletions deployment/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

# Execute all build.sh and package.sh and sign.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
echo ./build.sh
fi
if [ -f package.sh ]; then
echo ./package.sh
fi
if [ -f sign.sh ]; then
echo ./sign.sh
fi
popd
else
echo "Skipping $platform."
fi
done
21 changes: 21 additions & 0 deletions deployment/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/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
20 changes: 20 additions & 0 deletions deployment/collect_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/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}"
108 changes: 108 additions & 0 deletions deployment/common.build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset

RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color

DEFAULT_BUILD_CONTEXT="../.."
DEFAULT_ROOT="."
DEFAULT_DOTNETRUNTIME="framework"
DEFAULT_CONFIG="Release"
DEFAULT_OUTPUT_DIR="dist/jellyfin-git"
DEFAULT_PKG_DIR="pkg-dist"
DEFAULT_DOCKERFILE="Dockerfile"
DEFAULT_IMAGE_TAG="jellyfin:"`git rev-parse --abbrev-ref HEAD`

# Run a build
build_jellyfin()
(
ROOT=${1-$DEFAULT_ROOT}
CONFIG=${2-$DEFAULT_CONFIG}
DOTNETRUNTIME=${3-$DEFAULT_DOTNETRUNTIME}
OUTPUT_DIR=${4-$DEFAULT_OUTPUT_DIR}

echo -e "${CYAN}Building jellyfin in '${ROOT}' for ${DOTNETRUNTIME} with configuration ${CONFIG} and output directory '${OUTPUT_DIR}'.${NC}"
if [[ $DOTNETRUNTIME == 'framework' ]]; then
dotnet publish "${ROOT}" --configuration "${CONFIG}" --output="${OUTPUT_DIR}"
else
dotnet publish "${ROOT}" --configuration "${CONFIG}" --output="${OUTPUT_DIR}" --self-contained --runtime ${DOTNETRUNTIME}
fi
EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
echo -e "${GREEN}[DONE] Build jellyfin in '${ROOT}' for ${DOTNETRUNTIME} with configuration ${CONFIG} and output directory '${OUTPUT_DIR}' complete.${NC}"
else
echo -e "${RED}[FAIL] Build jellyfin in '${ROOT}' for ${DOTNETRUNTIME} with configuration ${CONFIG} and output directory '${OUTPUT_DIR}' FAILED.${NC}"
fi
)

# Run a docker
build_jellyfin_docker()
(
BUILD_CONTEXT=${1-$DEFAULT_BUILD_CONTEXT}
DOCKERFILE=${2-$DEFAULT_DOCKERFILE}
IMAGE_TAG=${3-$DEFAULT_IMAGE_TAG}

echo -e "${CYAN}Building jellyfin docker image in '${ROOT}' with Dockerfile ${CONFIG} and tag '${IMAGE_TAG}'.${NC}"
docker build -t ${IMAGE_TAG} -f ${DOCKERFILE} ${ROOT}
EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
echo -e "${GREEN}[DONE] Building jellyfin docker image in '${ROOT}' with Dockerfile ${CONFIG} and tag '${IMAGE_TAG}' complete.${NC}"
else
echo -e "${RED}[FAIL] Building jellyfin docker image in '${ROOT}' with Dockerfile ${CONFIG} and tag '${IMAGE_TAG}' FAILED.${NC}"
fi
)

# Clean a build
clean_jellyfin()
(
local ROOT=${1-$DEFAULT_ROOT}
local CONFIG=${2-$DEFAULT_CONFIG}
local OUTPUT_DIR=${3-$DEFAULT_OUTPUT_DIR}
local PKG_DIR=${4-$DEFAULT_PKG_DIR}
echo -e "${CYAN}Cleaning jellyfin in '${ROOT}'' with configuration ${CONFIG} and output directory '${OUTPUT_DIR}'.${NC}"
echo -e "${CYAN}Deleting '${OUTPUT_DIR}'${NC}"
rm -rf "$OUTPUT_DIR"
echo -e "${CYAN}Deleting '${PKG_DIR}'${NC}"
rm -rf "$PKG_DIR"
dotnet clean "${ROOT}" -maxcpucount:1 --configuration ${CONFIG}
local EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
echo -e "${GREEN}[DONE] Clean jellyfin in '${ROOT}' with configuration ${CONFIG} and output directory '${OUTPUT_DIR}' complete.${NC}"
else
echo -e "${RED}[FAIL] Clean jellyfin in '${ROOT}' with configuration ${CONFIG} and output directory '${OUTPUT_DIR}' failed.${NC}"
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.
package_portable()
(
local ROOT=${1-$DEFAULT_ROOT}
local OUTPUT_DIR=${2-$DEFAULT_OUTPUT_DIR}
local PKG_DIR=${3-$DEFAULT_PKG_DIR}
# Package portable build result
if [ -d ${OUTPUT_DIR} ]; then
echo -e "${CYAN}Packaging build in '${OUTPUT_DIR}' for `basename "${OUTPUT_DIR}"` to '${PKG_DIR}' with root '${ROOT}'.${NC}"
mkdir -p ${PKG_DIR}
tar -zcvf "${PKG_DIR}/`basename "${OUTPUT_DIR}"`.portable.tar.gz" -C "`dirname "${OUTPUT_DIR}"`" "`basename "${OUTPUT_DIR}"`"
local EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
echo -e "${GREEN}[DONE] Packaging build in '${OUTPUT_DIR}' for `basename "${OUTPUT_DIR}"` to '${PKG_DIR}' with root '${ROOT}' complete.${NC}"
else
echo -e "${RED}[FAIL] Packaging build in '${OUTPUT_DIR}' for `basename "${OUTPUT_DIR}"` to '${PKG_DIR}' with root '${ROOT}' FAILED.${NC}"
fi
else
echo -e "${RED}[FAIL] Build artifacts do not exist for ${OUTPUT_DIR}. Run build.sh first.${NC}"
fi
)

Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM debian:9
ARG SOURCEDIR=/repo
ENV DEB_BUILD_OPTIONS=noddebs

# https://dotnet.microsoft.com/download/linux-package-manager/debian9/sdk-current
RUN apt-get update \
Expand All @@ -11,12 +13,11 @@ RUN apt-get update \
&& chown root:root /etc/apt/sources.list.d/microsoft-prod.list \
&& apt-get update

WORKDIR /repo
WORKDIR ${SOURCEDIR}
COPY . .
COPY ./deployment/debian-x64/pkg-src ./debian

RUN yes|mk-build-deps -i \
&& dpkg-buildpackage -us -uc \
&& mkdir /dist \
&& mv /jellyfin*deb /dist
RUN yes | mk-build-deps -i debian/control \
&& dpkg-buildpackage -us -uc

WORKDIR /dist
WORKDIR /
7 changes: 7 additions & 0 deletions deployment/debian-package-x64/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

source ../common.build.sh

VERSION=`get_version ../..`

clean_jellyfin ../.. Release `pwd`/dist/jellyfin_${VERSION}
Loading

0 comments on commit 399a079

Please sign in to comment.