Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: some problems when server starting #735

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions .chglog/CHANGELOG.tpl.md

This file was deleted.

47 changes: 0 additions & 47 deletions .chglog/config.yml

This file was deleted.

1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ staticcheck.conf
.chglog/
justfile
Makefile
cliff.toml
*.md
21 changes: 12 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#

### BUILDER LAYER
FROM golang:1.18-alpine AS BE
FROM golang:1.20-alpine AS BE

WORKDIR /app

Expand All @@ -28,7 +28,7 @@ RUN go mod download
COPY . .

RUN mkdir ./bin && \
go build -ldflags "-X main.Version=`cat VERSION` -extldflags \"-static\" -s -w" -o ./bin/arana ./cmd
go build -ldflags "-X main.Version=`cat VERSION` -extldflags \"-static\" -s -w" -o ./bin/arana ./cmd/arana

### UI LAYER
FROM node:16-alpine as FE
Expand All @@ -47,19 +47,22 @@ RUN git clone -n https://github.com/arana-db/arana-ui.git /arana-ui && \
### RUNTIME LAYER
FROM alpine:3

ENV ARANA_LOG_NAME=arana.log \
ARANA_LOG_LEVEL=0 \
ARANA_LOG_MAX_SIZE=10 \
ARANA_LOG_MAX_BACKUPS=5 \
ARANA_LOG_MAX_AGE=30 \
ARANA_LOG_COMPRESS=false
ENV ARANA_LOG_PATH=/var/log/arana \
ARANA_LOG_LEVEL=INFO \
ARANA_LOG_MAX_SIZE=128MB \
ARANA_LOG_MAX_BACKUPS=3 \
ARANA_LOG_MAX_AGE=7 \
ARANA_LOG_COMPRESS=false \
ARANA_LOG_CONSOLE=true \
ARANA_LOG_SQL=false

WORKDIR /

RUN mkdir -p /etc/arana /var/www/arana
RUN mkdir -p /etc/arana /var/www/arana /var/log/arana

VOLUME /etc/arana
VOLUME /var/www/arana
VOLUME /var/log/arana

EXPOSE 13306
EXPOSE 8080
Expand Down
51 changes: 23 additions & 28 deletions cmd/admin/admin.go → cmd/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package admin
package cmd

import (
"context"
Expand All @@ -29,7 +29,6 @@ import (
)

import (
"github.com/arana-db/arana/cmd/cmds"
"github.com/arana-db/arana/pkg/admin"
_ "github.com/arana-db/arana/pkg/admin/router"
"github.com/arana-db/arana/pkg/boot"
Expand All @@ -53,19 +52,36 @@ func init() {
Use: "admin",
Short: "admin",
Example: "arana admin -c bootstrap.yaml -p 8080",
RunE: run,
RunE: runAdmin,
}
cmd.PersistentFlags().
StringP(constants.ConfigPathKey, "c", os.Getenv(constants.EnvBootstrapPath), "bootstrap configuration file path")
cmd.PersistentFlags().
Uint16P(_keyPort, "p", _defaultPort, "listen port")

cmds.Handle(func(root *cobra.Command) {
root.AddCommand(cmd)
})
RootCommand.AddCommand(cmd)
}

func Run(bootstrapPath string, addr string) error {
func runAdmin(cmd *cobra.Command, args []string) error {
_ = args
bootstrapPath, _ := cmd.PersistentFlags().GetString(constants.ConfigPathKey)
port, _ := cmd.PersistentFlags().GetUint16("port")
if len(bootstrapPath) < 1 {
// search bootstrap yaml
for _, path := range constants.GetConfigSearchPathList() {
bootstrapPath = filepath.Join(path, "bootstrap.yaml")
if _, err := os.Stat(bootstrapPath); err == nil {
break
}
bootstrapPath = filepath.Join(path, "bootstrap.yml")
if _, err := os.Stat(bootstrapPath); err == nil {
break
}
}
}

addr := fmt.Sprintf(":%d", port)

bootOptions, err := config.LoadBootOptions(bootstrapPath)
if err != nil {
return err
Expand Down Expand Up @@ -93,24 +109,3 @@ func Run(bootstrapPath string, addr string) error {
adminServer := admin.New(op, serviceDiscovery)
return adminServer.Listen(addr)
}

func run(cmd *cobra.Command, args []string) error {
_ = args
btPath, _ := cmd.PersistentFlags().GetString(constants.ConfigPathKey)
port, _ := cmd.PersistentFlags().GetUint16("port")
if len(btPath) < 1 {
// search bootstrap yaml
for _, path := range constants.GetConfigSearchPathList() {
btPath = filepath.Join(path, "bootstrap.yaml")
if _, err := os.Stat(btPath); err == nil {
break
}
btPath = filepath.Join(path, "bootstrap.yml")
if _, err := os.Stat(btPath); err == nil {
break
}
}
}

return Run(btPath, fmt.Sprintf(":%d", port))
}
22 changes: 2 additions & 20 deletions cmd/main.go → cmd/arana/arana.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,9 @@
package main

import (
"github.com/spf13/cobra"
"github.com/arana-db/arana/cmd"
)

import (
_ "github.com/arana-db/arana/cmd/admin"
"github.com/arana-db/arana/cmd/cmds"
_ "github.com/arana-db/arana/cmd/start"
_ "github.com/arana-db/arana/cmd/tools"
)

var Version = "0.1.0"

func main() {
rootCommand := &cobra.Command{
Use: "arana",
Short: "arana is a db proxy server",
Version: Version,
}

// initialize sub commands
cmds.Do(rootCommand)

_ = rootCommand.Execute()
cmd.Main()
}
23 changes: 10 additions & 13 deletions cmd/cmds/cmds.go → cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,22 @@
* limitations under the License.
*/

package cmds
package cmd

import (
"github.com/pkg/errors"

"github.com/spf13/cobra"
)

var _handlers []Handler

// Handler represents the command handler.
type Handler func(cmd *cobra.Command)
var Version = "0.1.0"

// Handle handles the main command.
func Handle(input Handler) {
_handlers = append(_handlers, input)
var RootCommand = &cobra.Command{
Use: "arana",
Short: "arana is a db proxy server",
Version: Version,
}

// Do process the root command with handlers.
func Do(cmd *cobra.Command) {
for _, it := range _handlers {
it(cmd)
}
func Main() error {
return errors.WithStack(RootCommand.Execute())
}
27 changes: 10 additions & 17 deletions cmd/tools/tools.go → cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package tools
package cmd

import (
"os"
Expand All @@ -26,39 +26,32 @@ import (
)

import (
"github.com/arana-db/arana/cmd/cmds"
"github.com/arana-db/arana/pkg/boot"
"github.com/arana-db/arana/pkg/constants"
)

var (
sourceConfigPath string
importBootConfPath string
_sourceConfigPath string
_importBootConfPath string
)

// init Init startCmd
func init() {
cmd := &cobra.Command{
Use: "import",
Short: "import arana config",
Example: "./arana import -c ../docker/conf/bootstrap.yaml -s ../docker/conf/config.yaml",
Run: run,
Example: "arana import -c ../docker/conf/bootstrap.yaml -s ../docker/conf/config.yaml",
Run: runTools,
}

cmd.PersistentFlags().
StringVarP(&importBootConfPath, constants.ConfigPathKey, "c", os.Getenv(constants.EnvBootstrapPath), "bootstrap configuration file path")
StringVarP(&_importBootConfPath, constants.ConfigPathKey, "c", os.Getenv(constants.EnvBootstrapPath), "bootstrap configuration file path")
cmd.PersistentFlags().
StringVarP(&sourceConfigPath, constants.ImportConfigPathKey, "s", "", "import configuration file path")
StringVarP(&_sourceConfigPath, constants.ImportConfigPathKey, "s", "", "import configuration file path")

cmds.Handle(func(root *cobra.Command) {
root.AddCommand(cmd)
})
RootCommand.AddCommand(cmd)
}

func run(_ *cobra.Command, _ []string) {
Run(importBootConfPath, sourceConfigPath)
}

func Run(importConfPath, configPath string) {
boot.RunImport(importConfPath, configPath)
func runTools(_ *cobra.Command, _ []string) {
boot.RunImport(_importBootConfPath, _sourceConfigPath)
}
Loading
Loading