Skip to content

Commit

Permalink
chore: remove Lua dependency (#1083)
Browse files Browse the repository at this point in the history
* chore: remove Lua dependency
  • Loading branch information
nic-chen authored Dec 21, 2020
1 parent 013e1d0 commit 565de4d
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 21 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/backend-unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ jobs:
with:
go-version: '1.13'

- name: setup lua
run: |
sudo apt-get update
sudo apt-get install lua5.1
- name: run test
run: |
make api-test
Expand Down
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ ARG ENABLE_PROXY=false

RUN if [ "$ENABLE_PROXY" = "true" ] ; then sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories ; fi

RUN apk add lua5.1

WORKDIR /usr/local/apisix-dashboard

COPY --from=api-builder /usr/local/apisix-dashboard/output/ ./
Expand Down
1 change: 1 addition & 0 deletions api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require (
github.com/stretchr/testify v1.6.1
github.com/tidwall/gjson v1.6.1
github.com/xeipuuv/gojsonschema v1.2.0
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da
go.etcd.io/etcd v3.3.25+incompatible
go.uber.org/zap v1.16.0
gopkg.in/yaml.v2 v2.3.0
Expand Down
6 changes: 6 additions & 0 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff/go.mod h1:+RTT1BOk5P
github.com/bradfitz/gomemcache v0.0.0-20190329173943-551aad21a668/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
github.com/bradleypeabody/gorilla-sessions-memcache v0.0.0-20181103040241-659414f458e1/go.mod h1:dkChI7Tbtx7H1Tj7TqGSZMOeGpMP5gLHtjroHd4agiI=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/coreos/etcd v3.3.25+incompatible h1:0GQEw6h3YnuOVdtwygkIfJ+Omx0tZ8/QkVyXI4LkbeY=
github.com/coreos/etcd v3.3.25+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
Expand Down Expand Up @@ -153,6 +156,8 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da h1:NimzV1aGyq29m5ukMK0AMWEhFaL/lrEOaephfuoiARg=
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da/go.mod h1:E1AXubJBdNmFERAOucpDIxNzeGfLzg0mYh+UfMWdChA=
go.etcd.io/etcd v3.3.25+incompatible h1:V1RzkZJj9LqsJRy+TUBgpWSbZXITLB819lstuTFoZOY=
go.etcd.io/etcd v3.3.25+incompatible/go.mod h1:yaeTdrJi5lOmYerz05bd8+V7KubZs8YSFZfzsF9A6aI=
go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk=
Expand All @@ -178,6 +183,7 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
38 changes: 27 additions & 11 deletions api/internal/handler/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package route
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os/exec"
"os"
"path/filepath"
"reflect"
"strings"

Expand All @@ -30,6 +30,7 @@ import (
"github.com/shiningrush/droplet/data"
"github.com/shiningrush/droplet/wrapper"
wgin "github.com/shiningrush/droplet/wrapper/gin"
"github.com/yuin/gopher-lua"

"github.com/apisix/manager-api/conf"
"github.com/apisix/manager-api/internal/core/entity"
Expand Down Expand Up @@ -224,21 +225,36 @@ func generateLuaCode(script map[string]interface{}) (string, error) {
if err != nil {
return "", err
}
workDir, err := filepath.Abs(conf.WorkDir)
if err != nil {
return "", err
}
libDir := filepath.Join(workDir, "dag-to-lua/")
if err := os.Chdir(libDir); err != nil {
log.Errorf("Chdir to libDir failed: %s", err)
return "", err
}

defer func() {
if err := os.Chdir(workDir); err != nil {
log.Errorf("Chdir to workDir failed: %s", err)
}
}()

cmd := exec.Command("sh", "-c",
"cd "+conf.WorkDir+"/dag-to-lua && lua cli.lua "+
"'"+string(scriptString)+"'")
L := lua.NewState()
defer L.Close()

stdout, _ := cmd.StdoutPipe()
defer stdout.Close()
if err := cmd.Start(); err != nil {
if err := L.DoString(`
local dag_to_lua = require 'dag-to-lua'
local conf = [==[` + string(scriptString) + `]==]
code = dag_to_lua.generate(conf)
`); err != nil {
return "", err
}

result, _ := ioutil.ReadAll(stdout)
resData := string(result)
code := L.GetGlobal("code")

return resData, nil
return code.String(), nil
}

func (h *Handler) Create(c droplet.Context) (interface{}, error) {
Expand Down
1 change: 0 additions & 1 deletion api/test/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ RUN mkdir -p /go/manager-api \
&& echo "hosts: files dns" > /etc/nsswitch.conf \
&& rm -rf /var/cache/apk/*

RUN apk add lua5.1

WORKDIR /go/manager-api
COPY --from=build-env /go/manager-api/ /go/manager-api/
Expand Down
2 changes: 0 additions & 2 deletions docs/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ Before using source codes to build, make sure that the following dependencies ar
$ go env -w GOPROXY=https://goproxy.cn,direct
```

2. [Lua](https://www.lua.org/download.html) 5.1+: This dependency needs to be installed only when using the **Plugin Orchestration** feature. In subsequent versions, this section will be optimized to remove the dependency.

### web

1. [Node.js](https://nodejs.org/en/download/) 10.23.0+
Expand Down

0 comments on commit 565de4d

Please sign in to comment.