diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4a1686e..b30c60d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,6 +9,10 @@ on: - 'v*' pull_request: +env: + REGISTRY: ghcr.io + REGISTRY_IMAGE: ghcr.io/autobrr/autobrr + permissions: contents: write packages: write @@ -64,7 +68,7 @@ jobs: POSTGRES_USER: testdb POSTGRES_PASSWORD: testdb POSTGRES_DB: autobrr - options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + options: --health-cmd pg_isready --health-interval 1s --health-timeout 5s --health-retries 60 steps: - name: Checkout uses: actions/checkout@v4 @@ -82,8 +86,7 @@ jobs: run: go test -v ./... goreleaserbuild: - name: Build Go binaries - if: github.event_name == 'pull_request' + name: Build distribution binaries runs-on: windows-latest needs: [web, test] steps: @@ -106,50 +109,17 @@ jobs: cache: true - name: Run GoReleaser build + if: github.event_name == 'pull_request' uses: goreleaser/goreleaser-action@v5 with: distribution: goreleaser version: latest - args: release --clean --skip-validate --skip-publish --parallelism 5 + args: release --clean --skip=validate --skip=publish --parallelism 5 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Upload assets - uses: actions/upload-artifact@v4 - with: - name: autobrr - path: | - dist/*.tar.gz - dist/*.zip - dist/*.apk - dist/*.deb - dist/*.rpm - - goreleaser: - name: Build and publish binaries - if: startsWith(github.ref, 'refs/tags/') - runs-on: ubuntu-latest - needs: [web, test] - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Download web production build - uses: actions/download-artifact@v4 - with: - name: web-dist - path: web/dist - -# 1.20 is the last version to support Windows < 10, Server < 2016, and MacOS < 1.15. - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: '1.20.12' - cache: true - - name: Run GoReleaser build and publish tags + if: startsWith(github.ref, 'refs/tags/') uses: goreleaser/goreleaser-action@v5 with: distribution: goreleaser @@ -170,8 +140,24 @@ jobs: dist/*.rpm docker: - name: Build and publish Docker images + name: Build Docker images runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + platform: + - linux/386 + - linux/amd64 + - linux/amd64/v2 + - linux/amd64/v3 + - linux/arm/v6 + - linux/arm/v7 + - linux/arm64 +# - linux/mips64le +# - linux/mips64 + - linux/ppc64le +# - linux/riscv64 + - linux/s390x needs: [web, test] steps: - name: Checkout @@ -188,7 +174,7 @@ jobs: - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: - registry: ghcr.io + registry: ${{ env.REGISTRY }} username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} @@ -196,7 +182,7 @@ jobs: id: meta uses: docker/metadata-action@v5 with: - images: ghcr.io/autobrr/autobrr + images: ${{ env.REGISTRY_IMAGE }} tags: | type=semver,pattern={{raw}} type=ref,event=branch @@ -208,20 +194,71 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Supported Architectures + run: docker buildx ls + - name: Build and publish image id: docker_build uses: docker/build-push-action@v5 with: context: . file: ./ci.Dockerfile - platforms: linux/amd64,linux/arm/v7,linux/arm64/v8 - push: ${{ github.event.pull_request.head.repo.full_name == 'autobrr/autobrr' || github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} + platforms: ${{ matrix.platform }} + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true labels: ${{ steps.meta.outputs.labels }} build-args: | BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }} VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} REVISION=${{ github.event.pull_request.head.sha }} + cache-from: type=gha + cache-to: type=gha,mode=max + - name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.docker_build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + - name: Upload digest + uses: actions/upload-artifact@v3 + with: + name: digests + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 - - name: Image digest - run: echo ${{ steps.docker_build.outputs.digest }} + docker-merge: + name: Publish Docker multi-arch manifest + if: ${{ github.event.pull_request.head.repo.full_name == 'autobrr/autobrr' || github.event_name != 'pull_request' }} + runs-on: ubuntu-latest + needs: [docker, test] + steps: + - name: Download digests + uses: actions/download-artifact@v3 + with: + name: digests + path: /tmp/digests + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + + - name: Create manifest list and push + working-directory: /tmp/digests + run: | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) + + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} diff --git a/Dockerfile b/Dockerfile index 91ed9b7..26e95f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,8 +33,8 @@ COPY --from=web-builder /web/build.go ./web #ENV GOOS=linux #ENV CGO_ENABLED=0 -RUN go build -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${REVISION} -X main.date=${BUILDTIME}" -o bin/autobrr cmd/autobrr/main.go -RUN go build -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${REVISION} -X main.date=${BUILDTIME}" -o bin/autobrrctl cmd/autobrrctl/main.go +RUN go build -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${REVISION} -X main.date=${BUILDTIME}" -o bin/autobrr cmd/autobrr/main.go && \ + go build -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${REVISION} -X main.date=${BUILDTIME}" -o bin/autobrrctl cmd/autobrrctl/main.go # build runner FROM alpine:latest diff --git a/ci.Dockerfile b/ci.Dockerfile index c51380d..99f52ff 100644 --- a/ci.Dockerfile +++ b/ci.Dockerfile @@ -1,30 +1,38 @@ # build app FROM --platform=$BUILDPLATFORM golang:1.20-alpine3.19 AS app-builder - RUN apk add --no-cache git tzdata ENV SERVICE=autobrr WORKDIR /src -COPY . ./ -RUN --mount=target=. \ - go mod download +# Cache Go modules +COPY go.mod go.sum ./ +RUN go mod download + +COPY . ./ ARG VERSION=dev ARG REVISION=dev ARG BUILDTIME -ARG TARGETOS TARGETARCH +ARG TARGETOS TARGETARCH TARGETVARIANT -RUN --mount=target=. \ - GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${REVISION} -X main.date=${BUILDTIME}" -o /out/bin/autobrr cmd/autobrr/main.go -RUN --mount=target=. \ - GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${REVISION} -X main.date=${BUILDTIME}" -o /out/bin/autobrrctl cmd/autobrrctl/main.go +RUN --network=none --mount=target=. \ +export GOOS=$TARGETOS; \ +export GOARCH=$TARGETARCH; \ +[[ "$GOARCH" == "amd64" ]] && export GOAMD64=$TARGETVARIANT; \ +[[ "$GOARCH" == "arm" ]] && [[ "$TARGETVARIANT" == "v6" ]] && export GOARM=6; \ +[[ "$GOARCH" == "arm" ]] && [[ "$TARGETVARIANT" == "v7" ]] && export GOARM=7; \ +echo $GOARCH $GOOS $GOARM$GOAMD64; \ +go build -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${REVISION} -X main.date=${BUILDTIME}" -o /out/bin/autobrr cmd/autobrr/main.go && \ +go build -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${REVISION} -X main.date=${BUILDTIME}" -o /out/bin/autobrrctl cmd/autobrrctl/main.go # build runner -FROM alpine:latest +FROM alpine:latest AS runner LABEL org.opencontainers.image.source = "https://github.com/autobrr/autobrr" +LABEL org.opencontainers.image.licenses = "GPL-2.0-or-later" +LABEL org.opencontainers.image.base.name = "alpine:latest" ENV HOME="/config" \ XDG_CONFIG_HOME="/config" \ @@ -35,7 +43,7 @@ RUN apk --no-cache add ca-certificates curl tzdata jq WORKDIR /app VOLUME /config EXPOSE 7474 -ENTRYPOINT ["/usr/local/bin/autobrr", "--config", "/config"] -COPY --from=app-builder /out/bin/autobrr /usr/local/bin/ -COPY --from=app-builder /out/bin/autobrrctl /usr/local/bin/ +COPY --link --from=app-builder /out/bin/autobrr* /usr/local/bin/ + +ENTRYPOINT ["/usr/local/bin/autobrr", "--config", "/config"]