Skip to content

Commit

Permalink
slime: update build-tools and support make test
Browse files Browse the repository at this point in the history
  • Loading branch information
believening committed May 31, 2024
1 parent 3db619f commit 16b0e5f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 35 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,5 @@ boot/helm-charts/slimeboot/templates/modules/*
### netease ###
/efficiency.json

### binary tools for test ###
/testdata/bin
69 changes: 36 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,42 +73,51 @@ gen-slimeboot-crd:
controller-gen crd:ignoreUnexportedFields=true paths="./apis/config/..." output:crd:dir="./charts/crds" 1>/dev/null 2>&1; \
popd 1>/dev/null 2>&1

.PHONY: format-go
format-go:
go list -f '{{.Dir}}/...' -m | xargs golangci-lint run --fix -c ./.golangci-format.yaml

.PHONY: lint-go
lint-go:
go list -f '{{.Dir}}/...' -m | xargs golangci-lint run -c ./.golangci.yaml

TEST_K8S_VERSION ?= 1.26.0
.PHONY: modules-test
modules-test:
$(eval BIN_ASSETS:=$(shell setup-envtest --bin-dir=./testdata/bin -p path use $(TEST_K8S_VERSION) --os $(shell go env GOOS) --arch $(shell go env GOARCH)))
@export KUBEBUILDER_ASSETS=$${PWD}/$(BIN_ASSETS) && \
go test -cover ./staging/src/slime.io/slime/modules/{limiter,meshregistry,plugin}/...

# Generate code
.PHONY: generate-module generate-framework
.PHONY: generate-module generate-framework format lint test
ifeq ($(IN_CONTAINER),1)
generate-module: modules-api-gen modules-k8s-gen
generate-framework: framework-api-gen gen-slimeboot-crd
generate-all: generate-module generate-framework
format: format-go
lint: lint-go
test: modules-test
else
generate-module:
@docker run --rm \
--env IN_CONTAINER=1 \
generate-module generate-all:
@$(DOCKER_RUN) \
--env MODULES_ROOT=$(MODULES_ROOT) \
--env MODULES="$(MODULES)" \
-v $(root_dir):/workspaces/slime \
--workdir /workspaces/slime \
--user $(shell id -u):$(shell id -g) \
$(IMG) \
make $@

generate-framework:
@docker run --rm \
--env IN_CONTAINER=1 \
-v $(root_dir):/workspaces/slime \
--workdir /workspaces/slime \
--user $(shell id -u):$(shell id -g) \
@$(DOCKER_RUN) \
$(IMG) \
make $@

generate-all:
@docker run --rm \
--env IN_CONTAINER=1 \
--env MODULES_ROOT=$(MODULES_ROOT) \
--env MODULES="$(MODULES)" \
-v $(root_dir):/workspaces/slime \
--workdir /workspaces/slime \
--user $(shell id -u):$(shell id -g) \
format lint:
@$(DOCKER_RUN) \
--env GOLANGCI_LINT_CACHE=/go/.cache \
$(IMG) \
make $@

test:
@$(DOCKER_RUN) \
$(IMG) \
make $@
endif
Expand All @@ -119,24 +128,18 @@ shell:
@echo "already in a container"
else
shell:
@docker run --rm -ti \
--env IN_CONTAINER=1 \
-v $(root_dir):/workspaces/slime \
--workdir /workspaces/slime \
--user $(shell id -u):$(shell id -g) \
@$(DOCKER_RUN) -it \
$(IMG) \
bash
endif

DOCKER_RUN := docker run --rm \
-v $(root_dir):/workspaces/slime \
--workdir /workspaces/slime \
--user $(shell id -u):$(shell id -g) \
--env IN_CONTAINER=1 \

MODULE_NAME?=
.PHONY: new-module
new-module:
bash bin/gen_module.sh $(MODULE_NAME)

.PHONY: format-go
format-go:
go list -f '{{.Dir}}/...' -m | xargs golangci-lint run --fix -c ./.golangci-format.yaml

.PHONY: lint-go
lint-go:
go list -f '{{.Dir}}/...' -m | xargs golangci-lint run -c ./.golangci.yaml
8 changes: 6 additions & 2 deletions docker/Dockerfile.build-tools
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ENV GOLANG_PROTOBUF_VERSION=v1.31.0
ENV PROTOC_VERSION=3.20.1
ENV K8S_API_VERSION=0.26.0
ENV GOLANGCI_LINT_VERSION=v1.53.3
ENV ENVTEST_VERSION=v0.0.0-20230216140739-c98506dc3b8e

RUN \
# install controller-gen
Expand All @@ -38,7 +39,10 @@ RUN \
# install istio code-generator
CGO_ENABLED=0 go install -ldflags='-extldflags -static -s -w' istio.io/tools/cmd/protoc-gen-golang-jsonshim@${ISTIO_TOOLS_VERSION} && \
CGO_ENABLED=0 go install -ldflags='-extldflags -static -s -w' istio.io/tools/cmd/protoc-gen-golang-deepcopy@${ISTIO_TOOLS_VERSION} && \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}
# install linter
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION} && \
# install integration test binaries
CGO_ENABLED=0 go install -ldflags='-extldflags -static -s -w' sigs.k8s.io/controller-runtime/tools/setup-envtest@${ENVTEST_VERSION}

# install k8s api protobuf
RUN mkdir -p ${GOPATH}/src/k8s.io && \
Expand All @@ -62,4 +66,4 @@ RUN export PB_REL="https://github.com/protocolbuffers/protobuf/releases"; \
rm protoc-${PROTOC_VERSION}-linux-${ARCH}.zip

ENV GOCACHE ${GOPATH}/.cache
RUN chmod -R 777 "$GOPATH"
RUN chmod -R 777 "$GOPATH"
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/zapr v1.2.3 h1:a9vnzlIBPQBBkeaR9IuMUfmVOrQlkoC4YfPoFkX3T7A=
github.com/go-logr/zapr v1.2.3/go.mod h1:eIauM6P8qSvTw5o2ez6UEAfGjQKrxQTl5EoK+Qa2oG4=
github.com/go-openapi/jsonreference v0.20.0/go.mod h1:Ag74Ico3lPc+zR+qjn4XBUmXymS4zJbYVCZmcgkasdo=
github.com/go-openapi/jsonreference v0.20.1/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k=
Expand Down

0 comments on commit 16b0e5f

Please sign in to comment.