Skip to content

Commit

Permalink
validate and update vendor target
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Apr 22, 2022
1 parent 27b5563 commit ffa3019
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
29 changes: 29 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: validate

on:
push:
branches:
- 'main'
- 'release/*'
tags:
- 'v*'
pull_request:
branches:
- '*'

jobs:
validate:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target:
- validate-vendor
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Run
run: |
make ${{ matrix.target }}
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ BINARIES=$(addprefix bin/,$(COMMANDS))
TESTFLAGS ?= -v $(TESTFLAGS_RACE)
TESTFLAGS_PARALLEL ?= 8

.PHONY: all build binaries check clean test test-race test-full integration coverage
.PHONY: all build binaries check clean test test-race test-full integration coverage validate-vendor vendor
.DEFAULT: all

all: binaries
Expand Down Expand Up @@ -100,3 +100,13 @@ build:
clean: ## clean up binaries
@echo "$(WHALE) $@"
@rm -f $(BINARIES)

validate-vendor: ## validate vendor
docker buildx bake validate-vendor

vendor: ## update vendor
$(eval $@_TMP_OUT := $(shell mktemp -d -t buildx-output.XXXXXXXXXX))
docker buildx bake --set "*.output=$($@_TMP_OUT)" update-vendor
rm -rf ./vendor
cp -R "$($@_TMP_OUT)"/out/* .
rm -rf $($@_TMP_OUT)/*
16 changes: 16 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ target "docker-metadata-action" {
tags = ["registry:local"]
}

group "validate" {
targets = ["validate-vendor"]
}

target "validate-vendor" {
dockerfile = "./dockerfiles/vendor.Dockerfile"
target = "validate"
output = ["type=cacheonly"]
}

target "update-vendor" {
dockerfile = "./dockerfiles/vendor.Dockerfile"
target = "update"
output = ["."]
}

target "binary" {
inherits = ["_common"]
target = "binary"
Expand Down
37 changes: 37 additions & 0 deletions dockerfiles/vendor.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# syntax=docker/dockerfile:1

ARG GO_VERSION=1.17

FROM golang:${GO_VERSION}-alpine AS base
RUN apk add --no-cache git rsync
WORKDIR /src

FROM base AS vendored
RUN --mount=target=/context \
--mount=target=.,type=tmpfs \
--mount=target=/go/pkg/mod,type=cache <<EOT
set -e
rsync -a /context/. .
go mod tidy
go mod vendor
mkdir /out
cp -r go.mod go.sum vendor /out
EOT

FROM scratch AS update
COPY --from=vendored /out /out

FROM vendored AS validate
RUN --mount=target=/context \
--mount=target=.,type=tmpfs <<EOT
set -e
rsync -a /context/. .
git add -A
rm -rf vendor
cp -rf /out/* .
if [ -n "$(git status --porcelain -- go.mod go.sum vendor)" ]; then
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "make vendor"'
git status --porcelain -- go.mod go.sum vendor
exit 1
fi
EOT

0 comments on commit ffa3019

Please sign in to comment.