From 06d1e7c76e202740a7d73368e4ab9e411b7198d1 Mon Sep 17 00:00:00 2001 From: Adam Janikowski <12255597+ajanikow@users.noreply.github.com> Date: Fri, 18 Oct 2024 14:22:24 +0200 Subject: [PATCH] [Maintenance] Improvie Pipeline (#1747) --- .circleci/continue_config.yml | 39 +++++++++++++++++++++++------------ .gitignore | 5 ++++- Makefile | 19 ++++++++--------- scripts/cache.sh | 24 +++++++++++++++++++++ 4 files changed, 63 insertions(+), 24 deletions(-) create mode 100644 scripts/cache.sh diff --git a/.circleci/continue_config.yml b/.circleci/continue_config.yml index 0b58819e3..4cae94177 100644 --- a/.circleci/continue_config.yml +++ b/.circleci/continue_config.yml @@ -16,7 +16,7 @@ parameters: executors: golang-executor: docker: - - image: 889010145541.dkr.ecr.us-east-1.amazonaws.com/cicd/golang:1.22.5 + - image: 889010145541.dkr.ecr.us-east-1.amazonaws.com/cicd/golang:1.22.8 aws_auth: oidc_role_arn: arn:aws:iam::889010145541:role/circleci-project-dev-kube-arangodb machine-executor: @@ -27,21 +27,31 @@ executors: jobs: check-code: executor: golang-executor + environment: + GOCACHE: "/tmp/go/cache" + GOPATH: "/tmp/go/path" + GO111MODULES: off + KEEP_GOPATH: 1 steps: - setup_remote_docker: docker_layer_caching: true - checkout - run: - name: Install deps - command: | - if [ -z "$CIRCLE_PULL_REQUEST" ]; then - make vendor - make tools-min - exit 0 - fi - apt-get update - apt-get install -y unzip - make init + name: Calculate cache + command: bash ./scripts/cache.sh . + - restore_cache: + keys: + - build-mod-{{ checksum ".checksum.mod" }} + - restore_cache: + keys: + - build-code-{{ checksum ".checksum.mod" }} + - run: + name: Run Vendor + command: make vendor tools-min init + - save_cache: + key: build-mod-{{ checksum ".checksum.mod" }} + paths: + - /tmp/go/path - run: name: License check command: | @@ -71,6 +81,7 @@ jobs: make bin - run: name: vulncheck + no_output_timeout: 1.5h command: | if [ -z "$CIRCLE_PULL_REQUEST" ]; then echo "This is not a pull request. Skipping..." @@ -85,8 +96,10 @@ jobs: exit 0 fi make ci-check - environment: - GO111MODULES: off + - save_cache: + key: build-code-{{ checksum ".checksum.mod" }} + paths: + - /tmp/go/cache manifests_verify: executor: machine-executor diff --git a/.gitignore b/.gitignore index 2b66d5b04..8082bf663 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,7 @@ license-header.enterprise.txt local/ kustomize_test/ -tools/codegen/boilerplate.go.txt \ No newline at end of file +tools/codegen/boilerplate.go.txt + +.checksum.code +.checksum.mod \ No newline at end of file diff --git a/Makefile b/Makefile index b4c7f8bdf..2c0837535 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,13 @@ RELEASE_MODE ?= community MAIN_DIR := $(ROOT)/pkg/entry/$(RELEASE_MODE) -GOBUILDDIR := $(SCRIPTDIR)/.gobuild +ifndef KEEP_GOPATH + GOBUILDDIR := $(SCRIPTDIR)/.gobuild + GOPATH := $(GOBUILDDIR) +else + GOBUILDDIR := $(GOPATH) +endif + SRCDIR := $(SCRIPTDIR) CACHEVOL := $(PROJECT)-gocache BINDIR := $(ROOTDIR)/bin @@ -42,10 +48,6 @@ REPOPATH := $(ORGPATH)/$(REPONAME) include $(ROOT)/$(RELEASE_MODE).mk -ifndef KEEP_GOPATH - GOPATH := $(GOBUILDDIR) -endif - TEST_BUILD ?= 0 GOBUILDARGS ?= GOBASEVERSION := 1.22.3 @@ -427,11 +429,8 @@ update-vendor: .PHONY: update-generated update-generated: - @rm -fr $(ORGDIR) - @mkdir -p $(ORGDIR) - @ln -s -f $(SCRIPTDIR) $(ORGDIR)/kube-arangodb @$(SED) -e 's/^/\/\/ /' -e 's/ *$$//' $(ROOTDIR)/tools/codegen/license-header.txt > $(ROOTDIR)/tools/codegen/boilerplate.go.txt - GOPATH=$(GOBUILDDIR) bash "${ROOTDIR}/scripts/codegen.sh" "${ROOTDIR}" + bash "${ROOTDIR}/scripts/codegen.sh" "${ROOTDIR}" dashboard/assets.go: cd $(DASHBOARDDIR) && docker build -t $(DASHBOARDBUILDIMAGE) -f Dockerfile.build $(DASHBOARDDIR) @@ -792,7 +791,7 @@ tools: tools-min @GOBIN=$(GOPATH)/bin go install github.com/golang/protobuf/protoc-gen-go@v1.5.2 @GOBIN=$(GOPATH)/bin go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2 @echo ">> Fetching govulncheck" - @GOBIN=$(GOPATH)/bin go install golang.org/x/vuln/cmd/govulncheck@v1.0.4 + @GOBIN=$(GOPATH)/bin go install golang.org/x/vuln/cmd/govulncheck@v1.1.3 .PHONY: vendor vendor: diff --git a/scripts/cache.sh b/scripts/cache.sh new file mode 100644 index 000000000..edc83821a --- /dev/null +++ b/scripts/cache.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +ROOT=$1 + +SHA_CODE=$( +find "${ROOT}/" \ + '(' -type f -name '*.go' -not -path "${ROOT}/vendor/*" -not -path "${ROOT}/.gobuild/*" -not -path "${ROOT}/deps/*" -exec sha256sum {} \; ')' -o \ + '(' -type f -name 'go.sum' -not -path "${ROOT}/vendor/*" -not -path "${ROOT}/.gobuild/*" -not -path "${ROOT}/deps/*" -exec sha256sum {} \; ')' -o \ + '(' -type f -name 'go.mod' -not -path "${ROOT}/vendor/*" -not -path "${ROOT}/.gobuild/*" -not -path "${ROOT}/deps/*" -exec sha256sum {} \; ')' \ + | cut -d ' ' -f1 | sha256sum | cut -d ' ' -f1 +) + +SHA_MOD=$( +find "${ROOT}/" \ + '(' -type f -name 'go.sum' -not -path "${ROOT}/vendor/*" -not -path "${ROOT}/.gobuild/*" -not -path "${ROOT}/deps/*" -exec sha256sum {} \; ')' -o \ + '(' -type f -name 'go.mod' -not -path "${ROOT}/vendor/*" -not -path "${ROOT}/.gobuild/*" -not -path "${ROOT}/deps/*" -exec sha256sum {} \; ')' \ + | cut -d ' ' -f1 | sha256sum | cut -d ' ' -f1 +) + +echo "Checksum Code: ${SHA_CODE}" +echo "Checksum Mod: ${SHA_MOD}" + +echo -n "${SHA_CODE}" > ${ROOT}/.checksum.code +echo -n "${SHA_MOD}" > ${ROOT}/.checksum.mod \ No newline at end of file