tao12345666333 commented on code in PR #994: URL: https://github.com/apache/apisix-ingress-controller/pull/994#discussion_r867284906
########## docs/en/latest/practices/how-to-use-go-plugin-runner-in-apisix-ingress.md: ########## @@ -0,0 +1,347 @@ +--- +title: How to use go-plugin-runner in APISIX Ingress +--- + +<!-- +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +--> + +## Proposal Description + +Based on version 0.3 of the go-plugin-runner plugin and version 1.4.0 of APISIX Ingress, this article goes through steps as follows: + +1. Prepare the environment (example as follows); +2. Create the cluster; +3. Build a container image that includes the x-plugin-runner; Review Comment: ```suggestion 3. Build a container image that includes the go-plugin-runner; ``` ########## docs/en/latest/practices/how-to-use-go-plugin-runner-in-apisix-ingress.md: ########## @@ -0,0 +1,347 @@ +--- +title: How to use go-plugin-runner in APISIX Ingress Review Comment: ```suggestion title: How to use go-plugin-runner with APISIX Ingress ``` ########## docs/en/latest/practices/how-to-use-go-plugin-runner-in-apisix-ingress.md: ########## @@ -0,0 +1,347 @@ +--- +title: How to use go-plugin-runner in APISIX Ingress +--- + +<!-- +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +--> + +## Proposal Description + +Based on version 0.3 of the go-plugin-runner plugin and version 1.4.0 of APISIX Ingress, this article goes through steps as follows: + +1. Prepare the environment (example as follows); +2. Create the cluster; +3. Build a container image that includes the x-plugin-runner; +4. Customize the helm chart package; +5. Install and Deploy; +6. Verify the function. + +It is guaranteed that the final result can be derived in full based on this environment example as follows: + +```bash +go-plugin-runner: 0.3 +APISIX Ingress: 1.4.0 + +kind: kind v0.12.0 go1.17.8 linux/amd64 +kubectl version: Client Version: v1.23.5/Server Version: v1.23.4 +golang: go1.18 linux/amd64 Review Comment: ```suggestion ``` ########## docs/en/latest/practices/how-to-use-go-plugin-runner-in-apisix-ingress.md: ########## @@ -0,0 +1,400 @@ +# How to use go-plugin-runner in APISIX Ingress + +## Background Description + +While wandering around the community, I found a user confused about "how to use multilingual plugins in APISIX Ingress environment". I happen to be a user of go-plugin-runner and have a little knowledge of the APISIX Ingress project, so this document was born. + +## Proposal Description + +Based on version 0.3 of the go-plugin-runner plugin and version 1.4.0 of APISIX Ingress, this article goes through building the cluster, building the image, customizing the helm chart package, and finally, deploying the resources. It is guaranteed that the final result can be derived in full based on this documentation. + +```bash +go-plugin-runner: 0.3 +APISIX Ingress: 1.4.0 + +kind: kind v0.12.0 go1.17.8 linux/amd64 +kubectl version: Client Version: v1.23.5/Server Version: v1.23.4 +golang: go1.18 linux/amd64 +``` + +## Begin + +### Build a cluster environment + +Select `kind` to build a local cluster environment. The command is as follows: + +```bash +cat <<EOF | kind create cluster --config=- +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +nodes: +- role: control-plane + kubeadmConfigPatches: + - | + kind: InitConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "ingress-ready=true" + extraPortMappings: + - containerPort: 80 + hostPort: 80 + protocol: TCP + - containerPort: 443 + hostPort: 443 + protocol: TCP +EOF +``` + +### Build the go-plugin-runner executable + +If you have finished writing the plugin, you can start compiling the executable to run with APISIX. + +This article recommends two packaging build options. + +1. put the packaging process into the Dockerfile and finish the compilation process when you build the docker image later. +2. You can also follow the scheme used in this document, building the executable first and then copying the packaged executable to the image. + +How you choose the option should depend on your local hardware considerations. The reason for selecting the second option here is that I want to rely on my powerful local hardware to increase the building speed and speed up the process. + +### Go to the go-plugin-runner directory + +Choose a folder address `/home/chever/api7/cloud_native/tasks/plugin-runner` and place our `apisix-go-plugin-runner` project in this folder. + +After successful placement, the file tree is shown below: + +```bash +chever@cloud-native-01:~/api7/cloud_native/tasks/plugin-runner$ tree -L 1 +. +└── apisix-go-plugin-runner + +1 directory, 0 files +``` + +Then you need to go to the `apisix-go-plugin-runner/cmd/go-runner/plugins` directory and write the plugins you need in that directory. This article will use the default plugin `say` for demonstration purposes. + +```bash +chever@cloud-native-01:~/api7/cloud_native/tasks/plugin-runner/apisix-go-plugin-runner$ tree cmd +cmd +└── go-runner + ├── main.go + ├── main_test.go + ├── plugins + │ ├── fault_injection.go + │ ├── fault_injection_test.go + │ ├── limit_req.go + │ ├── limit_req_test.go + │ ├── say.go + │ └── say_test.go + └── version.go + +2 directories, 10 files +``` + +After writing the plugins, start compiling the executable formally, and note here that you should build static executables, not dynamic ones. + +The package compile command is as follows. + +```bash +CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' . +``` + +This successfully packages a statically compiled `go-runner` executable. + +In the `apisix-go-plugin-runner/cmd/go-runner/` directory, you can see that the current file tree looks like this: Review Comment: @Chever-John I don't see where you solved this comment. Lines 70 to 137 should not appear in this document. Note that **this is a document, not a blog post.** ########## docs/en/latest/practices/how-to-use-go-plugin-runner-in-apisix-ingress.md: ########## @@ -0,0 +1,347 @@ +--- +title: How to use go-plugin-runner in APISIX Ingress +--- + +<!-- +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +--> + +## Proposal Description + +Based on version 0.3 of the go-plugin-runner plugin and version 1.4.0 of APISIX Ingress, this article goes through steps as follows: + +1. Prepare the environment (example as follows); +2. Create the cluster; +3. Build a container image that includes the x-plugin-runner; +4. Customize the helm chart package; +5. Install and Deploy; +6. Verify the function. + +It is guaranteed that the final result can be derived in full based on this environment example as follows: + +```bash +go-plugin-runner: 0.3 +APISIX Ingress: 1.4.0 + +kind: kind v0.12.0 go1.17.8 linux/amd64 +kubectl version: Client Version: v1.23.5/Server Version: v1.23.4 +golang: go1.18 linux/amd64 +``` + +## Begin + +### Build a cluster environment + +Select `kind` to build a local cluster environment. The command is as follows: + +```bash +cat <<EOF | kind create cluster --config=- +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +nodes: +- role: control-plane + extraPortMappings: + - containerPort: 80 + hostPort: 80 + protocol: TCP + - containerPort: 443 + hostPort: 443 + protocol: TCP +EOF +``` + +### Build the go-plugin-runner executable + +If you have finished writing the plugin, you can start compiling the executable to run with APISIX. + +This article recommends two packaging build options. + +1. Put the packaging process into the Dockerfile and finish the compilation process when you build the docker image later. +2. You can also follow the scheme used in this document, building the executable first and then copying the packaged executable to the image. + +How you choose the option should depend on your local hardware considerations. The reason for selecting the second option here is that I want to rely on my powerful local hardware to increase the building speed and speed up the process. + +### Go to the go-plugin-runner directory + +Choose a folder address `/home/chever/api7/cloud_native/tasks/plugin-runner` and place our `apisix-go-plugin-runner` project in this folder. + +After successful placement, the file tree is shown below: + +```bash +chever@cloud-native-01:~/api7/cloud_native/tasks/plugin-runner$ tree -L 1 +. +└── apisix-go-plugin-runner + +1 directory, 0 files +``` + +Then you need to go to the `apisix-go-plugin-runner/cmd/go-runner/plugins` directory and write the plugins you need in that directory. This article will use the default plugin `say` for demonstration purposes. + +```bash +chever@cloud-native-01:~/api7/cloud_native/tasks/plugin-runner/apisix-go-plugin-runner$ tree cmd +cmd +└── go-runner + ├── main.go + ├── main_test.go + ├── plugins + │ ├── fault_injection.go + │ ├── fault_injection_test.go + │ ├── limit_req.go + │ ├── limit_req_test.go + │ ├── say.go + │ └── say_test.go + └── version.go + +2 directories, 10 files +``` + +After writing the plugins, start compiling the executable formally, and note here that you should build static executables, not dynamic ones. + +The package compile command is as follows. + +```bash +CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' . +``` + +This successfully packages a statically compiled `go-runner` executable. + +In the `apisix-go-plugin-runner/cmd/go-runner/` directory, you can see that the current file tree looks like this: + +```bash +chever@cloud-native-01:~/api7/cloud_native/tasks/plugin-runner/apisix-go-plugin-runner/cmd/go-runner$ tree -L 1 +. +├── go-runner +├── main.go +├── main_test.go +├── plugins +└── version.go + +1 directory, 4 files +``` + +Please remember the path `apisix-go-plugin-runner/cmd/go-runner/go-runner`, we will use it later. + +### Build Docker Image + +The image is built here in preparation for installing APISIX later using `helm`. + +#### Write Dockerfile + +Return to the path `/home/chever/api7/cloud_native/tasks/plugin-runner` and create a Dockerfile in that directory, a demonstration of which is given here. + +We can write the Dockerfile by referring to examples in this [repository](https://github.com/apache/apisix-docker). Here I recommend adding the following line of code to this [Dockerfile file](https://github.com/apache/apisix-docker/blob/master/alpine/Dockerfile). + +```bash +ARG ENABLE_PROXY=false + +# Build Apache APISIX +FROM api7/apisix-base:1.19.9.1.5 + +# That is the line being added +ADD ./apisix-go-plugin-runner /usr/local/apisix-go-plugin-runner + +ARG APISIX_VERSION=2.13.1 +LABEL apisix_version="${APISIX_VERSION}" + +ARG ENABLE_PROXY + +``` Review Comment: ```suggestion ```Dockerfile FROM apache/apisix:2.13.1 COPY <Your go-plugin-runner static binary> /usr/local/apisix-go-plugin-runner ``` ``` we can just base on APISIX image, then copy go-plugin-runner static binary -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
