Earthfile 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. VERSION --new-platform 0.6
  2. FROM --platform=linux/amd64 alpine:3.20.3
  3. ARG version=develop
  4. WORKDIR /build
  5. build-all:
  6. BUILD --platform=linux/amd64 --platform=linux/386 --platform=linux/arm64 --platform=linux/arm/v7 --platform=darwin/amd64 --platform=darwin/arm64 +build
  7. package-all:
  8. BUILD --platform=linux/amd64 --platform=linux/386 --platform=linux/arm64 --platform=linux/arm/v7 --platform=darwin/amd64 --platform=darwin/arm64 +package
  9. docker-all:
  10. BUILD --platform=linux/amd64 --platform=linux/386 --platform=linux/arm64 --platform=linux/arm/v7 +docker
  11. crosscompiler:
  12. # This image is missing a few platforms, so we'll add them locally
  13. FROM --platform=linux/amd64 bdwyertech/go-crosscompile
  14. RUN apk add --update --no-cache tar gzip upx >> /dev/null
  15. RUN curl -sfL "https://owncast-infra.nyc3.cdn.digitaloceanspaces.com/build/armv7l-linux-musleabihf-cross.tgz" | tar zxf - -C /usr/ --strip-components=1
  16. RUN curl -sfL "https://owncast-infra.nyc3.cdn.digitaloceanspaces.com/build/i686-linux-musl-cross.tgz" | tar zxf - -C /usr/ --strip-components=1
  17. RUN curl -sfL "https://owncast-infra.nyc3.cdn.digitaloceanspaces.com/build/x86_64-linux-musl-cross.tgz" | tar zxf - -C /usr/ --strip-components=1
  18. code:
  19. FROM --platform=linux/amd64 +crosscompiler
  20. COPY . /build
  21. build:
  22. ARG EARTHLY_GIT_HASH # provided by Earthly
  23. ARG TARGETPLATFORM # provided by Earthly
  24. ARG TARGETOS # provided by Earthly
  25. ARG TARGETARCH # provided by Earthly
  26. ARG GOOS=$TARGETOS
  27. ARG GOARCH=$TARGETARCH
  28. FROM --platform=linux/amd64 +code
  29. RUN echo "Finding CC configuration for $TARGETPLATFORM"
  30. IF [ "$TARGETPLATFORM" = "linux/amd64" ]
  31. ARG NAME=linux-64bit
  32. ARG CC=x86_64-linux-musl-gcc
  33. ARG CXX=x86_64-linux-musl-g++
  34. ELSE IF [ "$TARGETPLATFORM" = "linux/386" ]
  35. ARG NAME=linux-32bit
  36. ARG CC=i686-linux-musl-gcc
  37. ARG CXX=i686-linux-musl-g++
  38. ELSE IF [ "$TARGETPLATFORM" = "linux/arm64" ]
  39. ARG NAME=linux-arm64
  40. ARG CC=aarch64-linux-musl-gcc
  41. ARG CXX=aarch64-linux-musl-g++
  42. ELSE IF [ "$TARGETPLATFORM" = "linux/arm/v7" ]
  43. ARG NAME=linux-arm7
  44. ARG CC=armv7l-linux-musleabihf-gcc
  45. ARG CXX=armv7l-linux-musleabihf-g++
  46. ARG GOARM=7
  47. ELSE IF [ "$TARGETPLATFORM" = "darwin/amd64" ]
  48. ARG NAME=macOS-64bit
  49. ARG CC=o64-clang
  50. ARG CXX=o64-clang++
  51. ELSE IF [ "$TARGETPLATFORM" = "darwin/arm64" ]
  52. ARG NAME=macOS-arm64
  53. ARG CC=o64-clang
  54. ARG CXX=o64-clang++
  55. ELSE
  56. RUN echo "Failed to find CC configuration for $TARGETPLATFORM"
  57. ARG --required CC
  58. ARG --required CXX
  59. END
  60. ENV CGO_ENABLED=1
  61. ENV GOOS=$GOOS
  62. ENV GOARCH=$GOARCH
  63. ENV GOARM=$GOARM
  64. ENV CC=$CC
  65. ENV CXX=$CXX
  66. WORKDIR /build
  67. # MacOSX disallows static executables, so we omit the static flag on this platform
  68. 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
  69. # Decrease the size of the shipped binary. But only for non-Apple platforms.
  70. # See https://github.com/upx/upx/issues/612
  71. IF [ "$GOOS" != "darwin" ]
  72. RUN upx --best --lzma owncast
  73. # Test the binary
  74. RUN upx -t owncast
  75. END
  76. SAVE ARTIFACT --keep-ts owncast owncast
  77. package:
  78. RUN apk add --update --no-cache zip >> /dev/null
  79. ARG TARGETPLATFORM # provided by Earthly
  80. IF [ "$TARGETPLATFORM" = "linux/amd64" ]
  81. ARG NAME=linux-64bit
  82. ELSE IF [ "$TARGETPLATFORM" = "linux/386" ]
  83. ARG NAME=linux-32bit
  84. ELSE IF [ "$TARGETPLATFORM" = "linux/arm64" ]
  85. ARG NAME=linux-arm64
  86. ELSE IF [ "$TARGETPLATFORM" = "linux/arm/v7" ]
  87. ARG NAME=linux-arm7
  88. ELSE IF [ "$TARGETPLATFORM" = "darwin/amd64" ]
  89. ARG NAME=macOS-64bit
  90. ELSE IF [ "$TARGETPLATFORM" = "darwin/arm64" ]
  91. ARG NAME=macOS-arm64
  92. ELSE
  93. ARG NAME=custom
  94. END
  95. COPY --keep-ts (+build/owncast --platform $TARGETPLATFORM) /build/dist/owncast
  96. ENV ZIPNAME owncast-$version-$NAME.zip
  97. RUN cd /build/dist && zip -r -q -8 /build/dist/owncast.zip .
  98. SAVE ARTIFACT --keep-ts /build/dist/owncast.zip owncast.zip AS LOCAL dist/$ZIPNAME
  99. docker:
  100. # Multiple image names can be tagged at once. They should all be passed
  101. # in as space separated strings using the full account/repo:tag format.
  102. # https://github.com/earthly/earthly/blob/aea38448fa9c0064b1b70d61be717ae740689fb9/docs/earthfile/earthfile.md#assigning-multiple-image-names
  103. ARG TARGETPLATFORM
  104. FROM --platform=$TARGETPLATFORM alpine:3.20.3
  105. RUN apk update && apk add --no-cache ffmpeg ffmpeg-libs ca-certificates unzip && update-ca-certificates
  106. RUN addgroup -g 101 -S owncast && adduser -u 101 -S owncast -G owncast
  107. WORKDIR /app
  108. COPY --keep-ts --platform=$TARGETPLATFORM +package/owncast.zip /app
  109. RUN unzip -x owncast.zip && mkdir data
  110. # temporarily disable until we figure out how to move forward
  111. # RUN chown -R owncast:owncast /app
  112. # USER owncast
  113. ENTRYPOINT ["/app/owncast"]
  114. EXPOSE 8080 1935
  115. ARG images=ghcr.io/owncast/owncast:testing
  116. RUN echo "Saving images: ${images}"
  117. # Tag this image with the list of names
  118. # passed along.
  119. FOR --no-cache i IN ${images}
  120. SAVE IMAGE --push "${i}"
  121. END
  122. dockerfile:
  123. FROM DOCKERFILE -f Dockerfile .
  124. unit-tests:
  125. FROM --platform=linux/amd64 bdwyertech/go-crosscompile
  126. COPY . /build
  127. WORKDIR /build
  128. RUN go test ./...
  129. api-tests:
  130. FROM --platform=linux/amd64 bdwyertech/go-crosscompile
  131. RUN apk add npm font-noto && fc-cache -f
  132. COPY . /build
  133. WORKDIR /build/test/automated/api
  134. RUN npm install
  135. RUN ./run.sh
  136. hls-tests:
  137. FROM --platform=linux/amd64 bdwyertech/go-crosscompile
  138. RUN apk add npm font-noto && fc-cache -f
  139. COPY . /build
  140. WORKDIR /build/test/automated/hls
  141. RUN npm install
  142. RUN ./run.sh