2020-06-17 03:27:55 +03:00
#!/bin/sh
# Human readable names of binary distributions
2020-12-18 11:21:49 +03:00
DISTRO = ( macOS-64bit linux-64bit linux-32bit linux-arm7)
2020-06-17 03:27:55 +03:00
# Operating systems for the respective distributions
2020-12-18 11:21:49 +03:00
OS = ( darwin linux linux linux)
2020-06-17 03:27:55 +03:00
# Architectures for the respective distributions
2020-12-18 11:21:49 +03:00
ARCH = ( amd64 amd64 386 arm-7)
2020-06-17 03:27:55 +03:00
# Version
VERSION = $1
2020-08-30 22:03:28 +03:00
SHOULD_RELEASE = $2
2020-06-18 09:54:55 +03:00
2021-01-12 06:38:44 +03:00
# Build info
GIT_COMMIT = $( git rev-list -1 HEAD)
GIT_BRANCH = $( git rev-parse --abbrev-ref HEAD)
2020-06-18 09:54:55 +03:00
if [ [ -z " ${ VERSION } " ] ] ; then
echo "Version must be specified when running build"
2020-06-22 19:53:26 +03:00
exit
2020-06-18 09:54:55 +03:00
fi
2021-01-12 06:38:44 +03:00
BUILD_TEMP_DIRECTORY = " $( mktemp -d) "
cd $BUILD_TEMP_DIRECTORY
echo " Cloning owncast into $BUILD_TEMP_DIRECTORY ... "
2021-02-19 10:05:52 +03:00
git clone https://github.com/owncast/owncast 2> /dev/null
2021-01-12 06:38:44 +03:00
cd owncast
echo " Changing to branch: $GIT_BRANCH "
git checkout $GIT_BRANCH
2020-06-17 03:27:55 +03:00
[ [ -z " ${ VERSION } " ] ] && VERSION = 'unknownver' || VERSION = " ${ VERSION } "
2021-01-12 06:38:44 +03:00
2020-06-17 03:27:55 +03:00
# Change to the root directory of the repository
cd $( git rev-parse --show-toplevel)
echo "Cleaning working directories..."
2020-06-19 03:47:44 +03:00
rm -rf ./webroot/hls/* ./hls/* ./webroot/thumbnail.jpg
2020-06-17 03:27:55 +03:00
echo " Creating version ${ VERSION } from commit ${ GIT_COMMIT } "
2020-10-26 18:49:33 +03:00
# Create production build of Tailwind CSS
pushd build/javascript >> /dev/null
# Install the tailwind & postcss CLIs
npm install --quiet --no-progress
# Run the tailwind CLI and pipe it to postcss for minification.
# Save it to a temp directory that we will reference below.
NODE_ENV = "production" ./node_modules/.bin/tailwind build | ./node_modules/.bin/postcss > " ${ TMPDIR } tailwind.min.css "
popd
2020-06-17 03:27:55 +03:00
mkdir -p dist
build( ) {
NAME = $1
OS = $2
ARCH = $3
VERSION = $4
GIT_COMMIT = $5
2021-02-19 10:05:52 +03:00
echo " Building ${ NAME } ( ${ OS } / ${ ARCH } ) release from ${ GIT_BRANCH } ${ GIT_COMMIT } ... "
2020-06-17 03:27:55 +03:00
2020-06-23 04:11:56 +03:00
mkdir -p dist/${ NAME }
2020-11-18 07:27:14 +03:00
mkdir -p dist/${ NAME } /data
2020-06-17 03:27:55 +03:00
cp -R webroot/ dist/${ NAME } /webroot/
2020-11-19 19:48:33 +03:00
2020-10-26 18:49:33 +03:00
# Copy the production pruned+minified css to the build's directory.
cp " ${ TMPDIR } tailwind.min.css " ./dist/${ NAME } /webroot/js/web_modules/tailwindcss/dist/tailwind.min.css
2020-06-26 03:44:47 +03:00
cp -R static/ dist/${ NAME } /static
2020-06-17 03:27:55 +03:00
cp README.md dist/${ NAME }
pushd dist/${ NAME } >> /dev/null
2020-07-13 03:58:34 +03:00
2021-02-19 10:05:52 +03:00
CGO_ENABLED = 1 ~/go/bin/xgo --branch ${ GIT_BRANCH } -ldflags " -s -w -X main.GitCommit= ${ GIT_COMMIT } -X main.BuildVersion= ${ VERSION } -X main.BuildPlatform= ${ NAME } " -targets " ${ OS } / ${ ARCH } " github.com/owncast/owncast
2020-07-13 03:58:34 +03:00
mv owncast-*-${ ARCH } owncast
2020-10-24 23:50:45 +03:00
zip -r -q -8 ../owncast-$VERSION -$NAME .zip .
2020-06-17 03:27:55 +03:00
popd >> /dev/null
rm -rf dist/${ NAME } /
}
2020-07-21 08:04:00 +03:00
for i in " ${ !DISTRO[@] } " ; do
build ${ DISTRO [ $i ] } ${ OS [ $i ] } ${ ARCH [ $i ] } $VERSION $GIT_COMMIT
done
2020-06-17 03:27:55 +03:00
2021-01-12 06:38:44 +03:00
echo " Build archives are available in $BUILD_TEMP_DIRECTORY /owncast/dist "
ls -alh " $BUILD_TEMP_DIRECTORY /owncast/dist "
2020-08-30 22:03:28 +03:00
# Use the second argument "release" to create an actual release.
if [ " $SHOULD_RELEASE " != "release" ] ; then
2021-01-12 06:38:44 +03:00
echo "Not uploading a release."
2020-08-30 22:03:28 +03:00
exit
fi
2020-06-17 03:27:55 +03:00
# Create the tag
2020-08-30 22:03:28 +03:00
git tag -a " v ${ VERSION } " -m " Release build v ${ VERSION } "
2020-06-17 03:27:55 +03:00
2020-08-30 22:03:28 +03:00
# On macOS open the Github page for new releases so they can be uploaded
if test -f "/usr/bin/open" ; then
2020-10-05 20:07:09 +03:00
open "https://github.com/owncast/owncast/releases/new"
2020-08-30 22:03:28 +03:00
open dist
fi
2020-07-07 10:23:21 +03:00
# Docker build
# Must authenticate first: https://docs.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-docker-for-use-with-github-packages#authenticating-to-github-packages
2020-08-30 22:03:28 +03:00
DOCKER_IMAGE = " owncast- ${ VERSION } "
echo " Building Docker image ${ DOCKER_IMAGE } ... "
# Change to the root directory of the repository
cd $( git rev-parse --show-toplevel)
2020-12-14 09:13:09 +03:00
# Docker build
docker build --build-arg NAME = docker --build-arg VERSION = ${ VERSION } --build-arg GIT_COMMIT = $GIT_COMMIT -t gabekangas/owncast:$VERSION -t gabekangas/owncast:latest -t owncast . -f build/release/Dockerfile-build
2020-07-21 04:39:39 +03:00
# Dockerhub
# You must be authenticated via `docker login` with your Dockerhub credentials first.
2021-05-15 01:28:13 +03:00
docker push " gabekangas/owncast: ${ VERSION } "