Earthfile 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 >> /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. #GIT CLONE --branch=$version git@github.com:owncast/owncast.git /build
  22. build:
  23. ARG EARTHLY_GIT_HASH # provided by Earthly
  24. ARG TARGETPLATFORM # provided by Earthly
  25. ARG TARGETOS # provided by Earthly
  26. ARG TARGETARCH # provided by Earthly
  27. ARG GOOS=$TARGETOS
  28. ARG GOARCH=$TARGETARCH
  29. FROM --platform=linux/amd64 +code
  30. RUN echo $EARTHLY_GIT_HASH
  31. RUN echo "Finding CC configuration for $TARGETPLATFORM"
  32. IF [ "$TARGETPLATFORM" = "linux/amd64" ]
  33. ARG NAME=linux-64bit
  34. ARG CC=x86_64-linux-musl-gcc
  35. ARG CXX=x86_64-linux-musl-g++
  36. ELSE IF [ "$TARGETPLATFORM" = "linux/386" ]
  37. ARG NAME=linux-32bit
  38. ARG CC=i686-linux-musl-gcc
  39. ARG CXX=i686-linux-musl-g++
  40. ELSE IF [ "$TARGETPLATFORM" = "linux/arm64" ]
  41. ARG NAME=linux-arm64
  42. ARG CC=aarch64-linux-musl-gcc
  43. ARG CXX=aarch64-linux-musl-g++
  44. ELSE IF [ "$TARGETPLATFORM" = "linux/arm/v7" ]
  45. ARG NAME=linux-arm7
  46. ARG CC=armv7l-linux-musleabihf-gcc
  47. ARG CXX=armv7l-linux-musleabihf-g++
  48. ARG GOARM=7
  49. ELSE IF [ "$TARGETPLATFORM" = "darwin/amd64" ]
  50. ARG NAME=macOS-64bit
  51. ARG CC=o64-clang
  52. ARG CXX=o64-clang++
  53. ELSE
  54. RUN echo "Failed to find CC configuration for $TARGETPLATFORM"
  55. ARG --required CC
  56. ARG --required CXX
  57. END
  58. ENV CGO_ENABLED=1
  59. ENV GOOS=$GOOS
  60. ENV GOARCH=$GOARCH
  61. ENV GOARM=$GOARM
  62. ENV CC=$CC
  63. ENV CXX=$CXX
  64. WORKDIR /build
  65. # MacOSX disallows static executables, so we omit the static flag on this platform
  66. 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
  67. SAVE ARTIFACT owncast owncast
  68. SAVE ARTIFACT README.md README.md
  69. package:
  70. RUN apk add --update --no-cache zip >> /dev/null
  71. ARG TARGETPLATFORM # provided by Earthly
  72. IF [ "$TARGETPLATFORM" = "linux/amd64" ]
  73. ARG NAME=linux-64bit
  74. ELSE IF [ "$TARGETPLATFORM" = "linux/386" ]
  75. ARG NAME=linux-32bit
  76. ELSE IF [ "$TARGETPLATFORM" = "linux/arm64" ]
  77. ARG NAME=linux-arm64
  78. ELSE IF [ "$TARGETPLATFORM" = "linux/arm/v7" ]
  79. ARG NAME=linux-arm7
  80. ELSE IF [ "$TARGETPLATFORM" = "darwin/amd64" ]
  81. ARG NAME=macOS-64bit
  82. ELSE
  83. ARG NAME=custom
  84. END
  85. COPY (+build/owncast --platform $TARGETPLATFORM) /build/dist/owncast
  86. COPY (+build/README.md --platform $TARGETPLATFORM) /build/dist/README.md
  87. ENV ZIPNAME owncast-$version-$NAME.zip
  88. RUN cd /build/dist && zip -r -q -8 /build/dist/owncast.zip .
  89. SAVE ARTIFACT /build/dist/owncast.zip owncast.zip AS LOCAL dist/$ZIPNAME
  90. docker:
  91. ARG image=ghcr.io/owncast/owncast
  92. ARG tag=develop
  93. ARG TARGETPLATFORM
  94. FROM --platform=$TARGETPLATFORM alpine:3.15.5
  95. RUN apk update && apk add --no-cache ffmpeg ffmpeg-libs ca-certificates unzip && update-ca-certificates
  96. WORKDIR /app
  97. COPY --platform=$TARGETPLATFORM +package/owncast.zip /app
  98. RUN unzip -x owncast.zip && mkdir data
  99. ENTRYPOINT ["/app/owncast"]
  100. EXPOSE 8080 1935
  101. SAVE IMAGE --push $image:$tag
  102. unit-tests:
  103. FROM --platform=linux/amd64 bdwyertech/go-crosscompile
  104. COPY . /build
  105. WORKDIR /build
  106. RUN go test ./...
  107. api-tests:
  108. FROM --platform=linux/amd64 bdwyertech/go-crosscompile
  109. RUN apk add ffmpeg npm
  110. COPY . /build
  111. WORKDIR /build/test/automated/api
  112. RUN npm install
  113. RUN ./run.sh