Apisix-dashboard: ManagerAPI should support -c to set the config file.

Created on 1 Feb 2021  ·  13Comments  ·  Source: apache/apisix-dashboard

Feature request

Please describe your feature

Now the manager API use cobra to manage CLI interactions.So I think we can support "-c" to set the config file.

Describe the solution you'd like

Support "-c" to set the config file.

enhancement good first issue

Most helpful comment

Can you guide me on how can i interact with the cli?

Hi @vinayaksh42 , the command go run ./cmd/manager under ./api directory would start the manager-api locally. If additional flag -h is specified, it will provide with more detailed usage on the manager-api command. Please see the following example.

➜  api git:(master) go run ./cmd/manager
The manager-api is running successfully!

Version :
GitHash :
Listen  : 127.0.0.1:9000
Loglevel: warn
Logfile : /Users/imjoey/Work/apache-apisix/apisix-dashboard/api/logs/error.log
➜  api git:(master) go run ./cmd/manager -h
APISIX Manager API

Usage:
  manager-api [flags]
  manager-api [command]

Available Commands:
  help        Help about any command
  stop

Flags:
  -h, --help              help for manager-api
  -p, --work-dir string   current work directory (default ".")

Use "manager-api [command] --help" for more information about a command.

All 13 comments

Hey, can I give this issue a try?

@vinayaksh42 absolutely,thanks!

Hey, can I give this issue a try?

Pretty good. I am so glad to hear that.
If you encounter any problems, please contact us.

@starsz is this the file in which I am supposed to make the changes?

@starsz is this the file in which I am supposed to make the changes?

Yes, you are right.
First, you should be familiar with this lib cobra.
And then add -c flag like this: https://github.com/apache/apisix-dashboard/blob/0a0a42ae1c81f21a03c98a991b707dba6b724364/api/cmd/managerapi.go#L134

to set the config path which is used in
https://github.com/apache/apisix-dashboard/blob/0a0a42ae1c81f21a03c98a991b707dba6b724364/api/internal/conf/conf.go#L127.

Much appreciated.

@starsz
i am getting the following output on running the make api-run command:

vinayak@vinayak-B150M-D3H:~/github/apisix-dashboard$ make api-run
api/build.sh --dry-run
The manager-api is running successfully!

Version : master
GitHash : 6e98820
Listen  : 127.0.0.1:9000
Loglevel: warn
Logfile : /home/vinayak/github/apisix-dashboard/api/logs/error.log

Can you guide me on how can i interact with the cli?

Can you guide me on how can i interact with the cli?

@vinayaksh42 .Of course.

First, make api-run is used for dry-run as you can see.
So we wouldn't use it in a production environment.
We should do ./api/build.sh to build the binary of manger-api. Like this:

./api/build.sh
+ export ENV=local
+ ENV=local
++ pwd
+ pwd=/Users/peter/Work/project/apisix-dashboard
+ rm -rf output
+ mkdir -p output/conf
+ mkdir -p output/dag-to-lua
+ [[ ! -f dag-to-lua-1.1/lib/dag-to-lua.lua ]]
....
+ cp -r /tmp/dag-to-lua-1.1/lib/cli.lua /tmp/dag-to-lua-1.1/lib/dag-to-lua.lua /tmp/dag-to-lua-1.1/lib/json.lua ./output/dag-to-lua
+ cd ./api
+ go build -o ../output/manager-api -ldflags '-X github.com/apisix/manager-api/cmd.Version=master -X github.com/apisix/manager-api/cmd.GitHash=0a0a42a' ./cmd/manager
+ cd ..
+ cp ./api/conf/schema.json ./output/conf/schema.json
+ cp ./api/conf/conf.yaml ./output/conf/conf.yaml
+ echo 'Build the Manager API successfully'
Build the Manager API successfully

Then we can get the binary of manager-api at the output directory.

➜ cd output && ls
conf        dag-to-lua  manager-api

We can do ./manger-api -h to see the help info.

./manager-api -h
APISIX Manager API

Usage:
  manager-api [flags]
  manager-api [command]

Available Commands:
  help        Help about any command
  stop

Flags:
  -h, --help              help for manager-api
  -p, --work-dir string   current work directory (default ".")

Use "manager-api [command] --help" for more information about a command.

The purpose of this issue is that we want to support "-c" command so that we can set the config path through the cli.

Can you guide me on how can i interact with the cli?

Hi @vinayaksh42 , the command go run ./cmd/manager under ./api directory would start the manager-api locally. If additional flag -h is specified, it will provide with more detailed usage on the manager-api command. Please see the following example.

➜  api git:(master) go run ./cmd/manager
The manager-api is running successfully!

Version :
GitHash :
Listen  : 127.0.0.1:9000
Loglevel: warn
Logfile : /Users/imjoey/Work/apache-apisix/apisix-dashboard/api/logs/error.log
➜  api git:(master) go run ./cmd/manager -h
APISIX Manager API

Usage:
  manager-api [flags]
  manager-api [command]

Available Commands:
  help        Help about any command
  stop

Flags:
  -h, --help              help for manager-api
  -p, --work-dir string   current work directory (default ".")

Use "manager-api [command] --help" for more information about a command.

i have added the following code in the managerapi.go

cmd.PersistentFlags().StringVarP(&conf.FilePath, "filepath","c", conf.FilePath, "Config file path")

upon running the command

./manager-api -c ./api/conf/test.yaml

i get the response

panic: couldn't open sink "/home/vinayak/github/apisix-dashboard/output/logs/error.log": open /home/vinayak/github/apisix-dashboard/output/logs/error.log: no such file or directory

even tho i have made a test.yaml file in the conf folder.

I am not sure if i am right or not but when i run

./manager-api -p ../

it returns the same error as the above one

panic: couldn't open sink "/home/vinayak/github/apisix-dashboard/output/logs/error.log": open /home/vinayak/github/apisix-dashboard/output/logs/error.log: no such file or directory

but when i run

./manager-api -p ../api/

the manager-api starts without any issue or error

The manager-api is running successfully!

Version : master
GitHash : 6e98820
Listen  : 127.0.0.1:9000
Loglevel: warn
Logfile : /home/vinayak/github/apisix-dashboard/api/logs/error.log

I think there is some fault with the working directory command cause ultimately we have the following line of code for the config file path

filePath := WorkDir + "/conf/conf.json"

I have added a filepath variable for collecting the new filepath which will be supplied by the flag. Should i make a Work-in-progress pr for this?

When we are running it from the output folder then we are one level below in the file structure because of which the "couldn't open sink" error is given.

When we are running it from the output folder then we are one level below in the file structure because of which the "couldn't open sink" error is given.

I think now we should provide the work_dir and conf path both.

Please have try like:

./output/manager-api -p ./api -c ./api/conf/conf.yaml

When we are running it from the output folder then we are one level below in the file structure because of which the "couldn't open sink" error is given.

I think now we should provide the work_dir and conf path both.

Please have try like:

./output/manager-api -p ./api -c ./api/conf/conf.yaml

Will give this a try

When we are running it from the output folder then we are one level below in the file structure because of which the "couldn't open sink" error is given.

I think now we should provide the work_dir and conf path both.

Please have try like:

./output/manager-api -p ./api -c ./api/conf/conf.yaml

This seems to be working perfectly

Was this page helpful?
0 / 5 - 0 ratings