Earthfile 5.3 KB

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