Skip to content

Commit

Permalink
example project should not use relative path to the root (#415)
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <[email protected]>
  • Loading branch information
spacewander authored Mar 27, 2024
1 parent 800c777 commit 2fa85a8
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 128 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ gen-proto: dev-tools install-go-fmtter $(GO_TARGETS)
docker run --rm -v $(PWD):/go/src/${PROJECT_NAME} --user $(shell id -u) -w /go/src/${PROJECT_NAME} \
${DEV_TOOLS_IMAGE} \
protoc --proto_path=. --go_opt="paths=source_relative" --go_out=. --validate_out="lang=go,paths=source_relative:." \
-I ../../protoc-gen-validate $<
-I /go/src/protoc-gen-validate $<
$(LOCALBIN)/gosimports -w -local ${PROJECT_NAME} $@

# We don't run the controller's unit test in this task. Because the controller is considered as a
Expand Down
30 changes: 25 additions & 5 deletions examples/dev_your_plugin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,43 @@
SHELL = /bin/bash

TARGET_SO = libgolang.so
PROJECT_NAME = mosn.io/htnn
PROJECT_NAME = mosn.io/htnn/dev_your_plugin
# Both images use glibc 2.31. Ensure libc in the images match each other.
BUILD_IMAGE ?= golang:1.21-bullseye
# FIXME: pin a version once we release htnn
PROXY_IMAGE ?= envoyproxy/envoy@sha256:4ac92ea7095c787b6d1d74ea7d27a5c776ded08a0dee9b6737f2105f790fa384
# This is the envoyproxy/envoy:contrib-v1.29.2
# Use docker inspect --format='{{index .RepoDigests 0}}' envoyproxy/envoy:contrib-v1.29.2
# to get the sha256 ID
PROXY_IMAGE ?= envoyproxy/envoy@sha256:c47136604751274b30fa7a89132314b8e3586d54d8f8cc30d7a911a9ecc5e11c
DEV_TOOLS_IMAGE ?= ghcr.io/mosn/htnn-dev-tools:2024-03-05

PROTOC = protoc
PROTO_FILES = $(call rwildcard,./,*.proto)
GO_TARGETS = $(patsubst %.proto,%.pb.go,$(PROTO_FILES))

.PHONY: dev-tools
dev-tools:
@if ! docker images ${DEV_TOOLS_IMAGE} | grep dev-tools > /dev/null; then \
docker pull ${DEV_TOOLS_IMAGE}; \
fi

.PHONY: gen-proto
gen-proto: dev-tools $(GO_TARGETS)
%.pb.go: %.proto
docker run --rm -v $(PWD):/go/src/${PROJECT_NAME} --user $(shell id -u) -w /go/src/${PROJECT_NAME} \
${DEV_TOOLS_IMAGE} \
protoc --proto_path=. --go_opt="paths=source_relative" --go_out=. --validate_out="lang=go,paths=source_relative:." \
-I /go/src/protoc-gen-validate $<

.PHONY: build-so-local
build-so-local:
CGO_ENABLED=1 go build -tags so \
--buildmode=c-shared \
-v -o ${TARGET_SO} \
${PROJECT_NAME}/dev_your_plugin/cmd/libgolang
${PROJECT_NAME}/cmd/libgolang

.PHONY: build-so
build-so:
docker run --rm -v $(shell go env GOPATH):/go -v $(PWD)/../..:/go/src/${PROJECT_NAME} -w /go/src/${PROJECT_NAME}/examples/dev_your_plugin \
docker run --rm -v $(shell go env GOPATH):/go -v $(PWD):/go/src/${PROJECT_NAME} -w /go/src/${PROJECT_NAME} \
-e GOPROXY \
${BUILD_IMAGE} \
bash -c "git config --global --add safe.directory '*' && make build-so-local"
Expand Down
2 changes: 1 addition & 1 deletion examples/dev_your_plugin/cmd/libgolang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

func init() {
http.RegisterHttpFilterFactoryAndConfigParser("fm", filtermanager.FilterManagerFactory, &filtermanager.FilterManagerConfigParser{})
http.RegisterHttpFilterConfigFactoryAndParser("fm", filtermanager.FilterManagerFactory, &filtermanager.FilterManagerConfigParser{})
}

func main() {}
40 changes: 19 additions & 21 deletions examples/dev_your_plugin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ go 1.21
toolchain go1.21.5

require (
// TODO: upgrade to Envoy 1.29.x once we release htnn v0.3.0
github.com/envoyproxy/envoy v1.29.1-0.20240208055117-b788e1a92347
github.com/envoyproxy/envoy v1.29.2
google.golang.org/protobuf v1.33.0
mosn.io/htnn v0.2.0
mosn.io/htnn v0.2.1-0.20240326063124-e57cd09f75e8
)

require (
Expand All @@ -31,30 +30,29 @@ require (
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
github.com/avast/retry-go v3.0.0+incompatible // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/casbin/casbin/v2 v2.82.0 // indirect
github.com/casbin/casbin/v2 v2.85.0 // indirect
github.com/casbin/govaluate v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cncf/xds/go v0.0.0-20231109132714-523115ebc101 // indirect
github.com/coreos/go-oidc/v3 v3.9.0 // indirect
github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa // indirect
github.com/coreos/go-oidc/v3 v3.10.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/envoyproxy/protoc-gen-validate v1.0.2 // indirect
github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
github.com/go-jose/go-jose/v4 v4.0.1 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/cel-go v0.20.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/cel-go v0.20.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/securecookie v1.1.2 // indirect
github.com/jellydator/ttlcache/v3 v3.2.0 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/open-policy-agent/opa v0.61.0 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/open-policy-agent/opa v0.62.1 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/redis/go-redis/v9 v9.5.1 // indirect
Expand All @@ -70,17 +68,17 @@ require (
go.opentelemetry.io/otel/trace v1.21.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20231219180239-dc181d75b848 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading

0 comments on commit 2fa85a8

Please sign in to comment.