From 8b2c54bf57ea86892e77cd56d9646663dd2b0840 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Thu, 5 May 2022 11:07:30 +0200 Subject: [PATCH 1/5] ci: remove dco check (dco bot already does this) Signed-off-by: CrazyMax --- .github/workflows/ci.yml | 7 ------- script/validate/dco | 12 ------------ 2 files changed, 19 deletions(-) delete mode 100755 script/validate/dco diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a36a7738..c8e6c731 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,16 +36,9 @@ jobs: with: go-version: ${{ matrix.go-version }} - - name: Dependencies - run: | - sudo apt-get -q update - sudo -E apt-get -yq --no-install-suggests --no-install-recommends install python2-minimal - cd /tmp && go install github.com/vbatts/git-validation@latest - - name: Build working-directory: ./src/github.com/distribution/distribution run: | - DCO_VERBOSITY=-q script/validate/dco go build -i . make build make binaries diff --git a/script/validate/dco b/script/validate/dco deleted file mode 100755 index 401f3642..00000000 --- a/script/validate/dco +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -set -eu -o pipefail - -if ! command -v git-validation; then - >&2 echo "ERROR: git-validation not found. Install with:" - >&2 echo " go install github.com/vbatts/git-validation@latest" - exit 1 -fi - -verbosity="${DCO_VERBOSITY--v}" -GIT_CHECK_EXCLUDE="./vendor:./script/validate/template" git-validation "$verbosity" -range "$COMMIT_RANGE" -run DCO,short-subject,dangling-whitespace \ No newline at end of file From 1a905ab966549bf9ce80494a36728c497dcaea9e Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 20 Jul 2022 14:18:18 +0200 Subject: [PATCH 2/5] ci: git validation target Signed-off-by: CrazyMax --- .github/workflows/validate.yml | 7 ++++--- Makefile | 5 ++++- docker-bake.hcl | 15 ++++++++++++++- dockerfiles/git.Dockerfile | 23 +++++++++++++++++++++++ 4 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 dockerfiles/git.Dockerfile diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 9a5b4dec..73e953af 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -8,8 +8,6 @@ on: tags: - 'v*' pull_request: - branches: - - '*' jobs: validate: @@ -20,11 +18,14 @@ jobs: target: - lint - validate-vendor + - validate-git steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Run run: | make ${{ matrix.target }} + env: + COMMIT_RANGE: ${{ format('{0}..{1}', github.sha, 'HEAD') }} diff --git a/Makefile b/Makefile index 2f58f44f..42db005e 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ BINARIES=$(addprefix bin/,$(COMMANDS)) TESTFLAGS ?= -v $(TESTFLAGS_RACE) TESTFLAGS_PARALLEL ?= 8 -.PHONY: all build binaries clean test test-race test-full integration coverage validate lint validate-vendor vendor mod-outdated +.PHONY: all build binaries clean test test-race test-full integration coverage validate lint validate-git validate-vendor vendor mod-outdated .DEFAULT: all all: binaries @@ -103,6 +103,9 @@ validate: ## run all validators lint: ## run all linters docker buildx bake $@ +validate-git: ## validate git + docker buildx bake $@ + validate-vendor: ## validate vendor docker buildx bake $@ diff --git a/docker-bake.hcl b/docker-bake.hcl index 4b776fcc..db9fa1f5 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -3,7 +3,7 @@ group "default" { } group "validate" { - targets = ["lint", "validate-vendor"] + targets = ["lint", "validate-git", "validate-vendor"] } target "lint" { @@ -11,6 +11,19 @@ target "lint" { output = ["type=cacheonly"] } +variable "COMMIT_RANGE" { + default = "" +} +target "validate-git" { + dockerfile = "./dockerfiles/git.Dockerfile" + target = "validate" + args = { + COMMIT_RANGE = COMMIT_RANGE + BUILDKIT_CONTEXT_KEEP_GIT_DIR = 1 + } + output = ["type=cacheonly"] +} + target "validate-vendor" { dockerfile = "./dockerfiles/vendor.Dockerfile" target = "validate" diff --git a/dockerfiles/git.Dockerfile b/dockerfiles/git.Dockerfile new file mode 100644 index 00000000..1d217eff --- /dev/null +++ b/dockerfiles/git.Dockerfile @@ -0,0 +1,23 @@ +# syntax=docker/dockerfile:1 + +ARG GO_VERSION=1.18 +ARG ALPINE_VERSION=3.16 + +FROM alpine:${ALPINE_VERSION} AS base +RUN apk add --no-cache git gpg + +FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS gitvalidation +ARG GIT_VALIDATION_VERSION=v1.1.0 +RUN --mount=type=cache,target=/root/.cache \ + --mount=type=cache,target=/go/pkg/mod \ + GOBIN=/out go install "github.com/vbatts/git-validation@${GIT_VALIDATION_VERSION}" + +FROM base AS validate +ARG COMMIT_RANGE +RUN if [ -z "$COMMIT_RANGE" ]; then echo "COMMIT_RANGE required" && exit 1; fi +ENV GIT_CHECK_EXCLUDE="./vendor" +WORKDIR /src +RUN --mount=type=bind,target=. \ + --mount=type=cache,target=/root/.cache \ + --mount=from=gitvalidation,source=/out/git-validation,target=/usr/bin/git-validation \ + git-validation -q -range "$COMMIT_RANGE" -run short-subject,dangling-whitespace From 7e546784a409f88aead01cc718583e7e47a241e0 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Thu, 5 May 2022 18:09:57 +0200 Subject: [PATCH 3/5] ci: move test step to build workflow and remove ci workflow Signed-off-by: CrazyMax --- .github/workflows/build.yml | 29 ++++++++++++++++++++++ .github/workflows/ci.yml | 49 ------------------------------------- 2 files changed, 29 insertions(+), 49 deletions(-) delete mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dc4b92ba..f01cdf4c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,8 +15,37 @@ env: DOCKERHUB_SLUG: distribution/distribution jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + go: + - 1.17 + - 1.18 + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go }} + - + name: Test + run: | + make coverage + - + name: Codecov + uses: codecov/codecov-action@v3 + with: + directory: ./ + build: runs-on: ubuntu-latest + needs: + - test steps: - name: Checkout diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index c8e6c731..00000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: CI - - -on: - push: - branches: - - main - pull_request: - branches: - - main - -jobs: - - build: - strategy: - matrix: - go-version: ["1.17.x", "1.18.x"] - platform: ["ubuntu-latest"] - runs-on: ${{ matrix.platform }} - env: - DOCKER_BUILDTAGS: "include_oss include_gcs" - CGO_ENABLED: 1 - GO111MODULE: "auto" - GOPATH: ${{ github.workspace }} - GOOS: linux - COMMIT_RANGE: ${{ github.event_name == 'pull_request' && format('{0}..{1}',github.event.pull_request.base.sha, github.event.pull_request.head.sha) || format('{0}..{1}', github.event.before, github.event.after) }} - - steps: - - uses: actions/checkout@v2 - with: - path: src/github.com/distribution/distribution - fetch-depth: 50 - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: ${{ matrix.go-version }} - - - name: Build - working-directory: ./src/github.com/distribution/distribution - run: | - go build -i . - make build - make binaries - if [ "$GOOS" = "linux" ]; then make coverage ; fi - - - uses: codecov/codecov-action@v1 - with: - directory: ./src/github.com/distribution/distribution From b066451b4029c4b063c06e65390a92e56a668a43 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 20 Jul 2022 14:19:39 +0200 Subject: [PATCH 4/5] dockerfiles: set ALPINE_VERSION Signed-off-by: CrazyMax --- Dockerfile | 5 +++-- dockerfiles/lint.Dockerfile | 3 ++- dockerfiles/vendor.Dockerfile | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 276b68f4..72ed20e6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,11 @@ # syntax=docker/dockerfile:1 ARG GO_VERSION=1.18 +ARG ALPINE_VERSION=3.16 ARG XX_VERSION=1.1.1 FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx -FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS base +FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base COPY --from=xx / / RUN apk add --no-cache bash coreutils file git ENV GO111MODULE=auto @@ -49,7 +50,7 @@ RUN --mount=from=binary,target=/build \ FROM scratch AS artifact COPY --from=releaser /out / -FROM alpine:3.16 +FROM alpine:${ALPINE_VERSION} RUN apk add --no-cache ca-certificates COPY cmd/registry/config-dev.yml /etc/docker/registry/config.yml COPY --from=binary /registry /bin/registry diff --git a/dockerfiles/lint.Dockerfile b/dockerfiles/lint.Dockerfile index 2f24d0d0..51052fa9 100644 --- a/dockerfiles/lint.Dockerfile +++ b/dockerfiles/lint.Dockerfile @@ -1,11 +1,12 @@ # syntax=docker/dockerfile:1 ARG GO_VERSION=1.18 +ARG ALPINE_VERSION=3.16 ARG GOLANGCI_LINT_VERSION=v1.45 FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint -FROM golang:${GO_VERSION}-alpine AS base +FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base RUN apk add --no-cache gcc musl-dev WORKDIR /src diff --git a/dockerfiles/vendor.Dockerfile b/dockerfiles/vendor.Dockerfile index 339b0e33..42cce5ec 100644 --- a/dockerfiles/vendor.Dockerfile +++ b/dockerfiles/vendor.Dockerfile @@ -1,9 +1,10 @@ # syntax=docker/dockerfile:1 ARG GO_VERSION=1.18 +ARG ALPINE_VERSION=3.16 ARG MODOUTDATED_VERSION=v0.8.0 -FROM golang:${GO_VERSION}-alpine AS base +FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base RUN apk add --no-cache git rsync WORKDIR /src From 0e17e5409133bf70576844a1031e579ff3634d82 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 20 Jul 2022 16:44:31 +0200 Subject: [PATCH 5/5] dockerfiles: formatting Signed-off-by: CrazyMax --- Dockerfile | 24 +++++++++---------- dockerfiles/git.Dockerfile | 10 ++++---- dockerfiles/lint.Dockerfile | 6 ++--- dockerfiles/vendor.Dockerfile | 44 +++++++++++++++++------------------ 4 files changed, 42 insertions(+), 42 deletions(-) diff --git a/Dockerfile b/Dockerfile index 72ed20e6..d99d8288 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,11 +24,11 @@ ARG TARGETPLATFORM ARG LDFLAGS="-s -w" ARG BUILDTAGS="include_oss include_gcs" RUN --mount=type=bind,target=/src,rw \ - --mount=type=cache,target=/root/.cache/go-build \ - --mount=target=/go/pkg/mod,type=cache \ - --mount=type=bind,source=/tmp/.ldflags,target=/tmp/.ldflags,from=version \ - set -x ; xx-go build -trimpath -ldflags "$(cat /tmp/.ldflags) ${LDFLAGS}" -o /usr/bin/registry ./cmd/registry \ - && xx-verify --static /usr/bin/registry + --mount=type=cache,target=/root/.cache/go-build \ + --mount=target=/go/pkg/mod,type=cache \ + --mount=type=bind,source=/tmp/.ldflags,target=/tmp/.ldflags,from=version \ + set -x ; xx-go build -trimpath -ldflags "$(cat /tmp/.ldflags) ${LDFLAGS}" -o /usr/bin/registry ./cmd/registry \ + && xx-verify --static /usr/bin/registry FROM scratch AS binary COPY --from=build /usr/bin/registry / @@ -39,13 +39,13 @@ ARG TARGETARCH ARG TARGETVARIANT WORKDIR /work RUN --mount=from=binary,target=/build \ - --mount=type=bind,target=/src \ - --mount=type=bind,source=/tmp/.version,target=/tmp/.version,from=version \ - VERSION=$(cat /tmp/.version) \ - && mkdir -p /out \ - && cp /build/registry /src/README.md /src/LICENSE . \ - && tar -czvf "/out/registry_${VERSION#v}_${TARGETOS}_${TARGETARCH}${TARGETVARIANT}.tar.tgz" * \ - && sha256sum -z "/out/registry_${VERSION#v}_${TARGETOS}_${TARGETARCH}${TARGETVARIANT}.tar.tgz" | awk '{ print $1 }' > "/out/registry_${VERSION#v}_${TARGETOS}_${TARGETARCH}${TARGETVARIANT}.tar.tgz.sha256" + --mount=type=bind,target=/src \ + --mount=type=bind,source=/tmp/.version,target=/tmp/.version,from=version \ + VERSION=$(cat /tmp/.version) \ + && mkdir -p /out \ + && cp /build/registry /src/README.md /src/LICENSE . \ + && tar -czvf "/out/registry_${VERSION#v}_${TARGETOS}_${TARGETARCH}${TARGETVARIANT}.tar.tgz" * \ + && sha256sum -z "/out/registry_${VERSION#v}_${TARGETOS}_${TARGETARCH}${TARGETVARIANT}.tar.tgz" | awk '{ print $1 }' > "/out/registry_${VERSION#v}_${TARGETOS}_${TARGETARCH}${TARGETVARIANT}.tar.tgz.sha256" FROM scratch AS artifact COPY --from=releaser /out / diff --git a/dockerfiles/git.Dockerfile b/dockerfiles/git.Dockerfile index 1d217eff..38effe42 100644 --- a/dockerfiles/git.Dockerfile +++ b/dockerfiles/git.Dockerfile @@ -9,8 +9,8 @@ RUN apk add --no-cache git gpg FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS gitvalidation ARG GIT_VALIDATION_VERSION=v1.1.0 RUN --mount=type=cache,target=/root/.cache \ - --mount=type=cache,target=/go/pkg/mod \ - GOBIN=/out go install "github.com/vbatts/git-validation@${GIT_VALIDATION_VERSION}" + --mount=type=cache,target=/go/pkg/mod \ + GOBIN=/out go install "github.com/vbatts/git-validation@${GIT_VALIDATION_VERSION}" FROM base AS validate ARG COMMIT_RANGE @@ -18,6 +18,6 @@ RUN if [ -z "$COMMIT_RANGE" ]; then echo "COMMIT_RANGE required" && exit 1; fi ENV GIT_CHECK_EXCLUDE="./vendor" WORKDIR /src RUN --mount=type=bind,target=. \ - --mount=type=cache,target=/root/.cache \ - --mount=from=gitvalidation,source=/out/git-validation,target=/usr/bin/git-validation \ - git-validation -q -range "$COMMIT_RANGE" -run short-subject,dangling-whitespace + --mount=type=cache,target=/root/.cache \ + --mount=from=gitvalidation,source=/out/git-validation,target=/usr/bin/git-validation \ + git-validation -q -range "${COMMIT_RANGE}" -run short-subject,dangling-whitespace diff --git a/dockerfiles/lint.Dockerfile b/dockerfiles/lint.Dockerfile index 51052fa9..113db75a 100644 --- a/dockerfiles/lint.Dockerfile +++ b/dockerfiles/lint.Dockerfile @@ -13,6 +13,6 @@ WORKDIR /src FROM base ENV GOFLAGS="-buildvcs=false" RUN --mount=type=bind,target=. \ - --mount=type=cache,target=/root/.cache \ - --mount=from=golangci-lint,source=/usr/bin/golangci-lint,target=/usr/bin/golangci-lint \ - golangci-lint run + --mount=type=cache,target=/root/.cache \ + --mount=from=golangci-lint,source=/usr/bin/golangci-lint,target=/usr/bin/golangci-lint \ + golangci-lint run diff --git a/dockerfiles/vendor.Dockerfile b/dockerfiles/vendor.Dockerfile index 42cce5ec..b56e5ee9 100644 --- a/dockerfiles/vendor.Dockerfile +++ b/dockerfiles/vendor.Dockerfile @@ -10,14 +10,14 @@ WORKDIR /src FROM base AS vendored RUN --mount=target=/context \ - --mount=target=.,type=tmpfs \ - --mount=target=/go/pkg/mod,type=cache <&2 'ERROR: Vendor result differs. Please vendor your package with "make vendor"' - git status --porcelain -- go.mod go.sum vendor - exit 1 -fi + --mount=target=.,type=tmpfs <&2 'ERROR: Vendor result differs. Please vendor your package with "make vendor"' + git status --porcelain -- go.mod go.sum vendor + exit 1 + fi EOT FROM psampaz/go-mod-outdated:${MODOUTDATED_VERSION} AS go-mod-outdated FROM base AS outdated ARG _RANDOM RUN --mount=target=.,ro \ - --mount=target=/go/pkg/mod,type=cache \ - --mount=from=go-mod-outdated,source=/home/go-mod-outdated,target=/usr/bin/go-mod-outdated \ - go list -mod=readonly -u -m -json all | go-mod-outdated -update -direct + --mount=target=/go/pkg/mod,type=cache \ + --mount=from=go-mod-outdated,source=/home/go-mod-outdated,target=/usr/bin/go-mod-outdated \ + go list -mod=readonly -u -m -json all | go-mod-outdated -update -direct