From d546288c2a19d88869e97aabaeacdceee70e7119 Mon Sep 17 00:00:00 2001 From: Kyle Sanderson Date: Sat, 22 Apr 2023 16:48:25 -0700 Subject: [PATCH] build: make ci 2-3x faster (#859) * Create scratch.Dockerfile * "best practices" * even faster? * too fast. change outdir * flip to 1.20.3 + v4 + setup go on docker * download deps * debug * Update ci.Dockerfile * Update goreleaser.Dockerfile * enable web caching * Update release.yml * Update ci.Dockerfile * revert goreleaser * cleanup * set GOCACHE * Update ci.Dockerfile * Delete scratch.Dockerfile --- .github/workflows/release.yml | 14 ++++++------- ci.Dockerfile | 37 +++++++++++++++-------------------- web/.yarnrc.yml | 1 + 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7bf35ef..8bc09c1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -59,9 +59,9 @@ jobs: # 1.20 is the last version to support Windows < 10, Server < 2016, and MacOS < 1.15. - name: Set up Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v4 with: - go-version: '1.20.1' + go-version: '1.20.3' cache: true - name: Test @@ -86,9 +86,9 @@ jobs: # 1.20 is the last version to support Windows < 10, Server < 2016, and MacOS < 1.15. - name: Set up Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v4 with: - go-version: '1.20.1' + go-version: '1.20.3' cache: true - name: Run GoReleaser build @@ -125,9 +125,9 @@ jobs: # 1.20 is the last version to support Windows < 10, Server < 2016, and MacOS < 1.15. - name: Set up Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v4 with: - go-version: '1.20.1' + go-version: '1.20.3' cache: true - name: Run GoReleaser build and publish tags @@ -195,4 +195,4 @@ jobs: VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} REVISION=${{ github.event.pull_request.head.sha }} - name: Image digest - run: echo ${{ steps.docker_build.outputs.digest }} \ No newline at end of file + run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/ci.Dockerfile b/ci.Dockerfile index f48b307..54a7aec 100644 --- a/ci.Dockerfile +++ b/ci.Dockerfile @@ -1,26 +1,25 @@ # build app -FROM golang:1.20-alpine3.16 AS app-builder +FROM --platform=$BUILDPLATFORM golang:1.20-alpine3.16 AS app-builder -ARG VERSION=dev -ARG REVISION=dev -ARG BUILDTIME - -RUN apk add --no-cache git make build-base tzdata +RUN apk add --no-cache git tzdata ENV SERVICE=autobrr WORKDIR /src - -COPY go.mod go.sum ./ -RUN go mod download - COPY . ./ -#ENV GOOS=linux -#ENV CGO_ENABLED=0 +RUN --mount=target=. \ + go mod download -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 +ARG VERSION=dev +ARG REVISION=dev +ARG BUILDTIME +ARG TARGETOS TARGETARCH + +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 # build runner FROM alpine:latest @@ -34,13 +33,9 @@ XDG_DATA_HOME="/config" RUN apk --no-cache add ca-certificates curl tzdata jq WORKDIR /app - VOLUME /config - -COPY --from=app-builder /src/bin/autobrr /usr/local/bin/ -COPY --from=app-builder /src/bin/autobrrctl /usr/local/bin/ - EXPOSE 7474 - ENTRYPOINT ["/usr/local/bin/autobrr", "--config", "/config"] -#CMD ["--config", "/config"] + +COPY --from=app-builder /out/bin/autobrr /usr/local/bin/ +COPY --from=app-builder /out/bin/autobrrctl /usr/local/bin/ diff --git a/web/.yarnrc.yml b/web/.yarnrc.yml index ec7a168..a7f54ae 100644 --- a/web/.yarnrc.yml +++ b/web/.yarnrc.yml @@ -1,2 +1,3 @@ yarnPath: .yarn/releases/yarn-3.2.2.cjs nodeLinker: node-modules +enableGlobalCache: true