Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

10.2 KB
Raw Blame
VERSION --new-platform 0.6

FROM --platform=linux/amd64 alpine:3.24.0
ARG version=develop

WORKDIR /build

build-all:
  BUILD --platform=linux/amd64 --platform=linux/386 --platform=linux/arm64 --platform=linux/arm/v7 --platform=darwin/amd64 --platform=darwin/arm64 +build

package-all:
  BUILD --platform=linux/amd64 --platform=linux/386 --platform=linux/arm64 --platform=linux/arm/v7 --platform=darwin/amd64 --platform=darwin/arm64 +package

docker-all:
  BUILD --platform=linux/amd64 --platform=linux/386 --platform=linux/arm64 --platform=linux/arm/v7 +docker

crosscompiler:
  # This image is missing a few platforms, so we'll add them locally
  FROM --platform=linux/amd64 ghcr.io/gabek/go-crosscompile:latest
  ENV GOTOOLCHAIN=auto
  RUN apk add --update --no-cache tar gzip upx >> /dev/null
  RUN curl -sfL "https://owncast-infra.nyc3.cdn.digitaloceanspaces.com/build/armv7l-linux-musleabihf-cross.tgz" | tar zxf - -C /usr/ --strip-components=1
  RUN curl -sfL "https://owncast-infra.nyc3.cdn.digitaloceanspaces.com/build/i686-linux-musl-cross.tgz" | tar zxf - -C /usr/ --strip-components=1
  RUN curl -sfL "https://owncast-infra.nyc3.cdn.digitaloceanspaces.com/build/x86_64-linux-musl-cross.tgz" | tar zxf - -C /usr/ --strip-components=1
	RUN curl -sfL "https://owncast-infra.nyc3.cdn.digitaloceanspaces.com/build/aarch64-linux-musl-cross.tgz" | tar zxf - -C /usr/ --strip-components=1

code:
  FROM --platform=linux/amd64 +crosscompiler
  COPY . /build

build:
  ARG EARTHLY_GIT_HASH # provided by Earthly
  ARG TARGETPLATFORM   # provided by Earthly
  ARG TARGETOS         # provided by Earthly
  ARG TARGETARCH       # provided by Earthly
  ARG GOOS=$TARGETOS
  ARG GOARCH=$TARGETARCH

  FROM --platform=linux/amd64 +code

  RUN echo "Finding CC configuration for $TARGETPLATFORM"
  IF [ "$TARGETPLATFORM" = "linux/amd64" ]
    ARG NAME=linux-64bit
    ARG CC=x86_64-linux-musl-gcc
    ARG CXX=x86_64-linux-musl-g++
  ELSE IF [ "$TARGETPLATFORM" = "linux/386" ]
    ARG NAME=linux-32bit
    ARG CC=i686-linux-musl-gcc
    ARG CXX=i686-linux-musl-g++
  ELSE IF [ "$TARGETPLATFORM" = "linux/arm64" ]
    ARG NAME=linux-arm64
    ARG CC=aarch64-linux-musl-gcc
    ARG CXX=aarch64-linux-musl-g++
  ELSE IF [ "$TARGETPLATFORM" = "linux/arm/v7" ]
    ARG NAME=linux-arm7
    ARG CC=armv7l-linux-musleabihf-gcc
    ARG CXX=armv7l-linux-musleabihf-g++
    ARG GOARM=7
  ELSE IF [ "$TARGETPLATFORM" = "darwin/amd64" ]
    ARG NAME=macOS-64bit
    ARG CC=o64-clang
    ARG CXX=o64-clang++
  ELSE IF [ "$TARGETPLATFORM" = "darwin/arm64" ]
    ARG NAME=macOS-arm64
    ARG CC=o64-clang
    ARG CXX=o64-clang++
  ELSE
    RUN echo "Failed to find CC configuration for $TARGETPLATFORM"
    ARG --required CC
    ARG --required CXX
  END

  ENV CGO_ENABLED=1
  ENV GOOS=$GOOS
  ENV GOARCH=$GOARCH
  ENV GOARM=$GOARM
  ENV CC=$CC
  ENV CXX=$CXX

  WORKDIR /build
  # MacOSX disallows static executables, so we omit the static flag on this platform
  RUN go build -a -installsuffix cgo -ldflags "$([ "$GOOS"z != darwinz ] && echo "-linkmode external -extldflags -static ") -s -w -X github.com/owncast/owncast/config.GitCommit=$EARTHLY_GIT_HASH -X github.com/owncast/owncast/config.VersionNumber=$version -X github.com/owncast/owncast/config.BuildPlatform=$NAME" -tags sqlite_omit_load_extension -o owncast main.go

	# Decrease the size of the shipped binary. But only for non-Apple platforms.
  # See https://github.com/upx/upx/issues/612
  IF [ "$GOOS" != "darwin" ]
	  RUN upx --best --lzma owncast
	  # Test the binary integrity
	  RUN upx -t owncast
  END

  # Sanity check: verify the binary runs without immediate crash.
  # We can only run Linux binaries in this container. macOS binaries are skipped.
  # The check downloads a static ffmpeg (required dependency), starts the binary,
  # waits 3 seconds, then verifies the process is still running.
  IF [ "$GOOS" = "linux" ]
    IF [ "$TARGETPLATFORM" = "linux/amd64" ]
      # Native architecture - run directly
      RUN curl -sL -o /usr/local/bin/ffmpeg https://github.com/eugeneware/ffmpeg-static/releases/download/b6.1.1/ffmpeg-linux-x64 && chmod +x /usr/local/bin/ffmpeg
      RUN ./owncast & PID=$!; sleep 3; if kill -0 $PID 2>/dev/null; then kill $PID; echo "Sanity check passed: binary runs on linux/amd64"; else echo "Sanity check FAILED: binary crashed on linux/amd64"; exit 1; fi
    ELSE IF [ "$TARGETPLATFORM" = "linux/arm64" ]
      # ARM64 - use QEMU
      RUN apk add --no-cache qemu-aarch64 >> /dev/null
      RUN curl -sL -o /usr/local/bin/ffmpeg https://github.com/eugeneware/ffmpeg-static/releases/download/b6.1.1/ffmpeg-linux-arm64 && chmod +x /usr/local/bin/ffmpeg
      RUN qemu-aarch64 ./owncast & PID=$!; sleep 3; if kill -0 $PID 2>/dev/null; then kill $PID; echo "Sanity check passed: binary runs on linux/arm64"; else echo "Sanity check FAILED: binary crashed on linux/arm64"; exit 1; fi
    ELSE IF [ "$TARGETPLATFORM" = "linux/arm/v7" ]
      # ARMv7 - use QEMU
      RUN apk add --no-cache qemu-arm >> /dev/null
      RUN curl -sL -o /usr/local/bin/ffmpeg https://github.com/eugeneware/ffmpeg-static/releases/download/b6.1.1/ffmpeg-linux-arm && chmod +x /usr/local/bin/ffmpeg
      RUN qemu-arm ./owncast & PID=$!; sleep 3; if kill -0 $PID 2>/dev/null; then kill $PID; echo "Sanity check passed: binary runs on linux/arm/v7"; else echo "Sanity check FAILED: binary crashed on linux/arm/v7"; exit 1; fi
    ELSE IF [ "$TARGETPLATFORM" = "linux/386" ]
      # 32-bit x86 - use QEMU
      RUN apk add --no-cache qemu-i386 >> /dev/null
      RUN curl -sL -o /usr/local/bin/ffmpeg https://github.com/eugeneware/ffmpeg-static/releases/download/b6.1.1/ffmpeg-linux-ia32 && chmod +x /usr/local/bin/ffmpeg
      RUN qemu-i386 ./owncast & PID=$!; sleep 3; if kill -0 $PID 2>/dev/null; then kill $PID; echo "Sanity check passed: binary runs on linux/386"; else echo "Sanity check FAILED: binary crashed on linux/386"; exit 1; fi
    END
  ELSE
    RUN echo "Skipping sanity check for $TARGETPLATFORM (cannot execute on Linux)"
  END

  SAVE ARTIFACT --keep-ts owncast owncast

package:
  RUN apk add --update --no-cache zip >> /dev/null

  ARG TARGETPLATFORM   # provided by Earthly
  IF [ "$TARGETPLATFORM" = "linux/amd64" ]
    ARG NAME=linux-64bit
  ELSE IF [ "$TARGETPLATFORM" = "linux/386" ]
    ARG NAME=linux-32bit
  ELSE IF [ "$TARGETPLATFORM" = "linux/arm64" ]
    ARG NAME=linux-arm64
  ELSE IF [ "$TARGETPLATFORM" = "linux/arm/v7" ]
    ARG NAME=linux-arm7
  ELSE IF [ "$TARGETPLATFORM" = "darwin/amd64" ]
    ARG NAME=macOS-64bit
  ELSE IF [ "$TARGETPLATFORM" = "darwin/arm64" ]
    ARG NAME=macOS-arm64
  ELSE
    ARG NAME=custom
  END

  COPY --keep-ts (+build/owncast --platform $TARGETPLATFORM) /build/dist/owncast
  ENV ZIPNAME owncast-$version-$NAME.zip
  RUN cd /build/dist && zip -r -q -8 /build/dist/owncast.zip .
  SAVE ARTIFACT --keep-ts /build/dist/owncast.zip owncast.zip AS LOCAL dist/$ZIPNAME

docker-image:
  # Internal target that builds the docker image. Used by +docker for testing.
  ARG TARGETPLATFORM
  FROM --platform=$TARGETPLATFORM alpine:3.24.0
  RUN apk update && apk add --no-cache ffmpeg ffmpeg-libs ca-certificates unzip && update-ca-certificates
  RUN addgroup -g 101 -S owncast && adduser -u 101 -S owncast -G owncast
  WORKDIR /app
  COPY --keep-ts --platform=$TARGETPLATFORM +package/owncast.zip /app
  RUN unzip -x owncast.zip && mkdir data

	# temporarily disable until we figure out how to move forward
  # RUN chown -R owncast:owncast /app
  # USER owncast

  ENTRYPOINT ["/app/owncast"]
  EXPOSE 8080 1935

docker:
	# Multiple image names can be tagged at once. They should all be passed
	# in as space separated strings using the full account/repo:tag format.
	# https://github.com/earthly/earthly/blob/aea38448fa9c0064b1b70d61be717ae740689fb9/docs/earthfile/earthfile.md#assigning-multiple-image-names
  ARG TARGETPLATFORM
  ARG images=ghcr.io/owncast/owncast:testing

  # Sanity check: run the container to verify it starts without crashing.
  # Only run for linux/amd64 as other architectures would need QEMU emulation.
  IF [ "$TARGETPLATFORM" = "linux/amd64" ]
    WITH DOCKER --load owncast:sanity-test=+docker-image
      RUN docker run -d --name owncast-sanity-test owncast:sanity-test && \
          sleep 5 && \
          if docker ps | grep -q owncast-sanity-test; then \
            echo "Docker sanity check passed: container runs on $TARGETPLATFORM"; \
            docker stop owncast-sanity-test; \
          else \
            echo "Docker sanity check FAILED: container crashed on $TARGETPLATFORM"; \
            docker logs owncast-sanity-test; \
            exit 1; \
          fi
    END
  ELSE
    RUN echo "Skipping docker sanity check for $TARGETPLATFORM (only runs on linux/amd64)"
  END

  FROM --platform=$TARGETPLATFORM +docker-image

	RUN echo "Saving images: ${images}"

	# Tag this image with the list of names
	# passed along.
	FOR --no-cache i IN ${images}
		SAVE IMAGE --push "${i}"
	END

dockerfile:
  FROM DOCKERFILE -f Dockerfile .

unit-tests:
  FROM --platform=linux/amd64 ghcr.io/gabek/go-crosscompile:latest
  ENV GOTOOLCHAIN=auto
  COPY . /build
	WORKDIR /build
	RUN go test ./...

api-tests:
	FROM --platform=linux/amd64 ghcr.io/gabek/go-crosscompile:latest
	ENV GOTOOLCHAIN=auto
	RUN apk add npm font-noto && fc-cache -f
  COPY . /build
	WORKDIR /build/test/automated/api
	RUN npm install
	RUN ./run.sh

hls-tests:
	FROM --platform=linux/amd64 ghcr.io/gabek/go-crosscompile:latest
	ENV GOTOOLCHAIN=auto
	RUN apk add npm font-noto && fc-cache -f
  COPY . /build
	WORKDIR /build/test/automated/hls
	RUN npm install
	RUN ./run.sh

native-wasm-test-plugin:
	FROM --platform=linux/amd64 rust:1.97.1-alpine
	RUN rustup target add wasm32-unknown-unknown
	COPY test/automated/plugins/native-wasm-plugin /plugin
	WORKDIR /plugin
	RUN cargo build --locked --release --target wasm32-unknown-unknown
	SAVE ARTIFACT /plugin/target/wasm32-unknown-unknown/release/native_wasm_test.wasm

plugin-tests:
	FROM --platform=linux/amd64 ghcr.io/gabek/go-crosscompile:latest
	ENV GOTOOLCHAIN=auto
	# git clones the plugin SDK. npm builds the SDK examples and this test suite.
	# gcompat lets the SDK's prebuilt extism-js (glibc) run on this musl/alpine image.
	RUN apk add npm git gcompat font-noto && fc-cache -f
	COPY . /build
	COPY +native-wasm-test-plugin/native_wasm_test.wasm /build/test/automated/plugins/native-wasm-plugin/native_wasm_test.wasm
	WORKDIR /build/test/automated/plugins
	RUN ./run.sh