build.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/bin/sh
  2. # Human readable names of binary distributions
  3. DISTRO=(macOS-64bit linux-64bit linux-32bit linux-arm7 linux-arm64)
  4. # Operating systems for the respective distributions
  5. OS=(darwin linux linux linux linux)
  6. # Architectures for the respective distributions
  7. ARCH=(amd64 amd64 386 arm-7 arm64)
  8. # Version
  9. VERSION=$1
  10. SHOULD_RELEASE=$2
  11. # Build info
  12. GIT_COMMIT=$(git rev-list -1 HEAD)
  13. GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
  14. if [[ -z "${VERSION}" ]]; then
  15. echo "Version must be specified when running build"
  16. exit
  17. fi
  18. BUILD_TEMP_DIRECTORY="$(mktemp -d)"
  19. cd $BUILD_TEMP_DIRECTORY
  20. echo "Cloning owncast into $BUILD_TEMP_DIRECTORY..."
  21. git clone https://github.com/owncast/owncast 2> /dev/null
  22. cd owncast
  23. echo "Changing to branch: $GIT_BRANCH"
  24. git checkout $GIT_BRANCH
  25. [[ -z "${VERSION}" ]] && VERSION='unknownver' || VERSION="${VERSION}"
  26. # Change to the root directory of the repository
  27. cd $(git rev-parse --show-toplevel)
  28. echo "Cleaning working directories..."
  29. rm -rf ./webroot/hls/* ./hls/* ./webroot/thumbnail.jpg
  30. echo "Creating version ${VERSION} from commit ${GIT_COMMIT}"
  31. # Create production build of Tailwind CSS
  32. pushd build/javascript >> /dev/null
  33. # Install the tailwind & postcss CLIs
  34. npm install --quiet --no-progress
  35. # Run the tailwind CLI and pipe it to postcss for minification.
  36. # Save it to a temp directory that we will reference below.
  37. NODE_ENV="production" ./node_modules/.bin/tailwind build | ./node_modules/.bin/postcss > "${TMPDIR}tailwind.min.css"
  38. popd
  39. mkdir -p dist
  40. build() {
  41. NAME=$1
  42. OS=$2
  43. ARCH=$3
  44. VERSION=$4
  45. GIT_COMMIT=$5
  46. echo "Building ${NAME} (${OS}/${ARCH}) release from ${GIT_BRANCH} ${GIT_COMMIT}..."
  47. mkdir -p dist/${NAME}
  48. mkdir -p dist/${NAME}/data
  49. cp -R webroot/ dist/${NAME}/webroot/
  50. # Copy the production pruned+minified css to the build's directory.
  51. cp "${TMPDIR}tailwind.min.css" ./dist/${NAME}/webroot/js/web_modules/tailwindcss/dist/tailwind.min.css
  52. cp README.md dist/${NAME}
  53. pushd dist/${NAME} >> /dev/null
  54. CGO_ENABLED=1 ~/go/bin/xgo -go latest --branch ${GIT_BRANCH} -ldflags "-s -w -X github.com/owncast/owncast/config.GitCommit=${GIT_COMMIT} -X github.com/owncast/owncast/config.BuildVersion=${VERSION} -X github.com/owncast/owncast/config.BuildPlatform=${NAME}" -tags enable_updates -targets "${OS}/${ARCH}" github.com/owncast/owncast
  55. mv owncast-*-${ARCH} owncast
  56. zip -r -q -8 ../owncast-$VERSION-$NAME.zip .
  57. popd >> /dev/null
  58. rm -rf dist/${NAME}/
  59. }
  60. for i in "${!DISTRO[@]}"; do
  61. build ${DISTRO[$i]} ${OS[$i]} ${ARCH[$i]} $VERSION $GIT_COMMIT
  62. done
  63. echo "Build archives are available in $BUILD_TEMP_DIRECTORY/owncast/dist"
  64. ls -alh "$BUILD_TEMP_DIRECTORY/owncast/dist"
  65. # Use the second argument "release" to create an actual release.
  66. if [ "$SHOULD_RELEASE" != "release" ]; then
  67. echo "Not uploading a release."
  68. exit
  69. fi
  70. # Create the tag
  71. git tag -a "v${VERSION}" -m "Release build v${VERSION}"
  72. # On macOS open the Github page for new releases so they can be uploaded
  73. if test -f "/usr/bin/open"; then
  74. open "https://github.com/owncast/owncast/releases/new"
  75. open dist
  76. fi
  77. # Docker build
  78. # 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
  79. DOCKER_IMAGE="owncast-${VERSION}"
  80. echo "Building Docker image ${DOCKER_IMAGE}..."
  81. # Change to the root directory of the repository
  82. cd $(git rev-parse --show-toplevel)
  83. # Docker build
  84. 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 .
  85. # Dockerhub
  86. # You must be authenticated via `docker login` with your Dockerhub credentials first.
  87. docker push "gabekangas/owncast:${VERSION}"