Skip to content
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
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ jobs:
if: github.repository == 'apache/dubbo-admin'
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'yarn'
cache-dependency-path: ui-vue3/yarn.lock
- name: Build Frontend (Vue3)
working-directory: ui-vue3
run: |
yarn install --frozen-lockfile
yarn build
- name: Copy Dist Directory
run: cp -r ui-vue3/dist/ app/dubbo-ui/
- name: Setup Go ${{ matrix.go_version }}
uses: actions/setup-go@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ bin/
build/
vendor/


app/dubbo-ui/dist/
41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 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.

# Build the manager binary
FROM docker.io/golang:1.24 AS builder
ARG TARGETOS
ARG TARGETARCH

WORKDIR /app

COPY go.mod go.mod
COPY go.sum go.sum

ENV GOPROXY=https://goproxy.cn,direct

# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go env && go mod download

RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o dubbo-admin ./app/dubbo-admin/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /app/dubbo-admin .
USER 65532:65532

ENTRYPOINT ["./dubbo-admin","run"]
46 changes: 1 addition & 45 deletions app/dubbo-admin/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,68 +18,24 @@
package cmd

import (
"fmt"
"os"
"path/filepath"

"github.com/spf13/cobra"

dubbolog "github.com/apache/dubbo-admin/pkg/common/log"
"github.com/apache/dubbo-admin/pkg/core"
cmd2 "github.com/apache/dubbo-admin/pkg/core/cmd"
"github.com/apache/dubbo-admin/pkg/core/cmd/version"
)

// newRootCmd represents the base command when called without any subcommands.
func newRootCmd() *cobra.Command {
args := struct {
logLevel string
outputPath string
maxSize int
maxBackups int
maxAge int
}{}
cmd := &cobra.Command{
Use: "dubbo-admin",
Short: "Universal Admin for Dubbo Application",
Long: `Universal Admin for Dubbo Application`,
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
level, err := dubbolog.ParseLogLevel(args.logLevel)
if err != nil {
return err
}

if args.outputPath != "" {
output, err := filepath.Abs(args.outputPath)
if err != nil {
return err
}

fmt.Printf("%s: logs will be stored in %q\n", "dubbo-cp", output)
core.SetLogger(core.NewLoggerWithRotation(level, output, args.maxSize, args.maxBackups, args.maxAge))
} else {
core.SetLogger(core.NewLogger(level))
}

// once command line flags have been parsed,
// avoid printing usage instructions
cmd.SilenceUsage = true

return nil
},
}

cmd.SetOut(os.Stdout)

// root flags
cmd.PersistentFlags().StringVar(&args.logLevel, "log-level", dubbolog.InfoLevel.String(), cmd2.UsageOptions("log level", dubbolog.OffLevel, dubbolog.InfoLevel, dubbolog.DebugLevel))
cmd.PersistentFlags().StringVar(&args.outputPath, "log-output-path", args.outputPath, "path to the file that will be filled with logs. Example: if we set it to /tmp/dubbo.log then after the file is rotated we will have /tmp/dubbo-2021-06-07T09-15-18.265.log")
cmd.PersistentFlags().IntVar(&args.maxBackups, "log-max-retained-files", 1000, "maximum number of the old log files to retain")
cmd.PersistentFlags().IntVar(&args.maxSize, "log-max-size", 100, "maximum size in megabytes of a log file before it gets rotated")
cmd.PersistentFlags().IntVar(&args.maxAge, "log-max-age", 30, "maximum number of days to retain old log files based on the timestamp encoded in their filename")

// sub-commands
cmd.AddCommand(newRunCmdWithOpts(cmd2.DefaultRunCmdOpts))
cmd.AddCommand(newRunCmdWithOpts())
cmd.AddCommand(version.NewVersionCmd())

return cmd
Expand Down
41 changes: 29 additions & 12 deletions app/dubbo-admin/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,24 @@
package cmd

import (
"context"
"os"
"os/signal"
"syscall"
"time"

"github.com/spf13/cobra"

"github.com/apache/dubbo-admin/pkg/config"
"github.com/apache/dubbo-admin/pkg/config/app"
"github.com/apache/dubbo-admin/pkg/core/bootstrap"
dubbocmd "github.com/apache/dubbo-admin/pkg/core/cmd"
"github.com/apache/dubbo-admin/pkg/core/logger"
dubboversion "github.com/apache/dubbo-admin/pkg/version"
)

const gracefullyShutdownDuration = 3 * time.Second

// This is the open file limit below which the control plane may not
// reasonably have enough descriptors to accept all its clients.
const minOpenFileLimit = 4096

func newRunCmdWithOpts(opts dubbocmd.RunCmdOpts) *cobra.Command {
func newRunCmdWithOpts() *cobra.Command {
args := struct {
configPath string
}{}
Expand All @@ -49,10 +48,10 @@ func newRunCmdWithOpts(opts dubbocmd.RunCmdOpts) *cobra.Command {
cfg := app.DefaultAdminConfig()
err := config.Load(args.configPath, &cfg)
if err != nil {
logger.Errorf("could not load the configuration, cause: %s", err.Error())
return err

}
// 2. configure logger
logger.Init(cfg.Log)
cfgForDisplay, err := config.ConfigForDisplay(&cfg)
if err != nil {
logger.Errorf("unable to prepare config for display, cause: %s", err.Error())
Expand All @@ -63,11 +62,10 @@ func newRunCmdWithOpts(opts dubbocmd.RunCmdOpts) *cobra.Command {
logger.Errorf("unable to convert config to json, cause: %s", err.Error())
return err
}
logger.Infof("Current config %s", cfgBytes)
logger.Infof("Running in mode `%s`", cfg.Mode)
logger.Infof("current config:\n %s", cfgBytes)

// 2. build components
gracefulCtx, ctx := opts.SetupSignalHandler()
gracefulCtx, ctx := setupSignalHandler()
rt, err := bootstrap.Bootstrap(gracefulCtx, cfg)
if err != nil {
logger.Errorf("unable to bootstrap, cause: %s", err.Error())
Expand All @@ -91,6 +89,25 @@ func newRunCmdWithOpts(opts dubbocmd.RunCmdOpts) *cobra.Command {
},
}
// flags
cmd.PersistentFlags().StringVarP(&args.configPath, "config-file", "c", "", "configuration file")
cmd.PersistentFlags().StringVarP(&args.configPath, "config-file", "c", "./dubbo-admin.yaml", "configuration file")
return cmd
}

func setupSignalHandler() (context.Context, context.Context) {
gracefulCtx, gracefulCancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(context.Background())
c := make(chan os.Signal, 3)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
go func() {
s := <-c
logger.Warnf("received signal %s, stopping instance gracefully", s.String())
gracefulCancel()
s = <-c
logger.Warnf("received second signal %s, stopping instance", s.String())
cancel()
s = <-c
logger.Warnf("received third signal %s, force exit", s.String())
os.Exit(1)
}()
return gracefulCtx, ctx
}
61 changes: 0 additions & 61 deletions app/dubbo-admin/dubbo-admin-legacy.yaml

This file was deleted.

Loading
Loading