Skip to content

Commit dacc27e

Browse files
committed
Merge branch 'beta/1.1.0' into beta.2/1.1.0
# Conflicts: # internal/migrations/migrations.go # internal/schema/user_schema.go # ui/src/common/interface.ts
2 parents 3a6439a + f0ddd30 commit dacc27e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+4018
-214
lines changed

.github/Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ ARG CGO_EXTRA_CFLAGS
2525
COPY . ${BUILD_DIR}
2626
WORKDIR ${BUILD_DIR}
2727
COPY --from=node-builder /tmp/build ${BUILD_DIR}/ui/build
28-
RUN apk --no-cache add build-base git \
29-
&& make clean build \
30-
&& cp answer /usr/bin/answer
28+
RUN apk --no-cache add build-base git bash \
29+
&& make clean build
30+
RUN chmod 755 answer
31+
RUN ["/bin/bash","-c","script/build_plugin.sh"]
32+
RUN cp answer /usr/bin/answer
3133

3234
RUN mkdir -p /data/uploads && chmod 777 /data/uploads \
3335
&& mkdir -p /data/i18n && cp -r i18n/*.yaml /data/i18n

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ tmp
2626
vendor/
2727
/answer-data/
2828
/answer
29+
/new_answer
2930

3031
dist/

Dockerfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ FROM golang:1.19-alpine AS golang-builder
1313
LABEL maintainer="[email protected]"
1414

1515
ARG GOPROXY
16-
ENV GOPROXY ${GOPROXY:-direct}
16+
# ENV GOPROXY ${GOPROXY:-direct}
17+
ENV GOPROXY=https://goproxy.io,direct
1718

1819
ENV GOPATH /go
1920
ENV GOROOT /usr/local/go
@@ -27,9 +28,11 @@ ARG CGO_EXTRA_CFLAGS
2728
COPY . ${BUILD_DIR}
2829
WORKDIR ${BUILD_DIR}
2930
COPY --from=node-builder /tmp/build ${BUILD_DIR}/ui/build
30-
RUN apk --no-cache add build-base git \
31-
&& make clean build \
32-
&& cp answer /usr/bin/answer
31+
RUN apk --no-cache add build-base git bash \
32+
&& make clean build
33+
RUN chmod 755 answer
34+
RUN ["/bin/bash","-c","script/build_plugin.sh"]
35+
RUN cp answer /usr/bin/answer
3336

3437
RUN mkdir -p /data/uploads && chmod 777 /data/uploads \
3538
&& mkdir -p /data/i18n && cp -r i18n/*.yaml /data/i18n

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
.PHONY: build clean ui
22

3-
VERSION=1.0.9
3+
VERSION=1.1.0
44
BIN=answer
55
DIR_SRC=./cmd/answer
66
DOCKER_CMD=docker
77

88
GO_ENV=CGO_ENABLED=0 GO111MODULE=on
99
Revision=$(shell git rev-parse --short HEAD)
10-
GO_FLAGS=-ldflags="-X main.Version=$(VERSION) -X 'main.Revision=$(Revision)' -X 'main.Time=`date`' -extldflags -static"
10+
GO_FLAGS=-ldflags="-X github.com/answerdev/answer/cmd.Version=$(VERSION) -X 'github.com/answerdev/answer/cmd.Revision=$(Revision)' -X 'github.com/answerdev/answer/cmd.Time=`date +%s`' -extldflags -static"
1111
GO=$(GO_ENV) $(shell which go)
1212

1313
build: generate

cmd/answer/main.go

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,12 @@
11
package main
22

33
import (
4-
"os"
5-
"time"
6-
7-
"github.com/answerdev/answer/internal/base/conf"
8-
"github.com/answerdev/answer/internal/base/constant"
9-
"github.com/answerdev/answer/internal/base/cron"
10-
"github.com/answerdev/answer/internal/cli"
11-
"github.com/answerdev/answer/internal/schema"
12-
"github.com/gin-gonic/gin"
13-
"github.com/segmentfault/pacman"
14-
"github.com/segmentfault/pacman/contrib/log/zap"
15-
"github.com/segmentfault/pacman/contrib/server/http"
16-
"github.com/segmentfault/pacman/log"
17-
)
18-
19-
// go build -ldflags "-X main.Version=x.y.z"
20-
var (
21-
// Name is the name of the project
22-
Name = "answer"
23-
// Version is the version of the project
24-
Version = "0.0.0"
25-
// Revision is the git short commit revision number
26-
Revision = ""
27-
// Time is the build time of the project
28-
Time = ""
29-
// log level
30-
logLevel = os.Getenv("LOG_LEVEL")
31-
// log path
32-
logPath = os.Getenv("LOG_PATH")
4+
answercmd "github.com/answerdev/answer/cmd"
335
)
346

357
// @securityDefinitions.apikey ApiKeyAuth
368
// @in header
379
// @name Authorization
3810
func main() {
39-
log.SetLogger(zap.NewLogger(
40-
log.ParseLevel(logLevel), zap.WithName("answer"), zap.WithPath(logPath), zap.WithCallerFullPath()))
41-
Execute()
42-
}
43-
44-
func runApp() {
45-
c, err := conf.ReadConfig(cli.GetConfigFilePath())
46-
if err != nil {
47-
panic(err)
48-
}
49-
conf.GetPathIgnoreList()
50-
app, cleanup, err := initApplication(
51-
c.Debug, c.Server, c.Data.Database, c.Data.Cache, c.I18n, c.Swaggerui, c.ServiceConfig, log.GetLogger())
52-
if err != nil {
53-
panic(err)
54-
}
55-
constant.Version = Version
56-
constant.Revision = Revision
57-
schema.AppStartTime = time.Now()
58-
59-
defer cleanup()
60-
if err := app.Run(); err != nil {
61-
panic(err)
62-
}
63-
}
64-
65-
func newApplication(serverConf *conf.Server, server *gin.Engine, manager *cron.ScheduledTaskManager) *pacman.Application {
66-
manager.Run()
67-
return pacman.NewApp(
68-
pacman.WithName(Name),
69-
pacman.WithVersion(Version),
70-
pacman.WithServer(http.NewServer(server, serverConf.HTTP.Addr)),
71-
)
11+
answercmd.Main()
7212
}

cmd/answer/command.go renamed to cmd/command.go

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
package main
1+
package answercmd
22

33
import (
44
"fmt"
55
"os"
6+
"strings"
67

78
"github.com/answerdev/answer/internal/base/conf"
89
"github.com/answerdev/answer/internal/cli"
910
"github.com/answerdev/answer/internal/install"
1011
"github.com/answerdev/answer/internal/migrations"
12+
"github.com/answerdev/answer/plugin"
1113
"github.com/spf13/cobra"
1214
)
1315

@@ -16,6 +18,10 @@ var (
1618
dataDirPath string
1719
// dumpDataPath dump data path
1820
dumpDataPath string
21+
// plugins needed to build in answer application
22+
buildWithPlugins []string
23+
// build output path
24+
buildOutput string
1925
)
2026

2127
func init() {
@@ -25,7 +31,11 @@ func init() {
2531

2632
dumpCmd.Flags().StringVarP(&dumpDataPath, "path", "p", "./", "dump data path, eg: -p ./dump/data/")
2733

28-
for _, cmd := range []*cobra.Command{initCmd, checkCmd, runCmd, dumpCmd, upgradeCmd} {
34+
buildCmd.Flags().StringSliceVarP(&buildWithPlugins, "with", "w", []string{}, "plugins needed to build")
35+
36+
buildCmd.Flags().StringVarP(&buildOutput, "output", "o", "", "build output path")
37+
38+
for _, cmd := range []*cobra.Command{initCmd, checkCmd, runCmd, dumpCmd, upgradeCmd, buildCmd, pluginCmd} {
2939
rootCmd.AddCommand(cmd)
3040
}
3141
}
@@ -160,10 +170,44 @@ To run answer, use:
160170
fmt.Println("check environment all done")
161171
},
162172
}
173+
174+
// buildCmd used to build another answer with plugins
175+
buildCmd = &cobra.Command{
176+
Use: "build",
177+
Short: "used to build answer with plugins",
178+
Long: `Build a new Answer with plugins that you need`,
179+
Run: func(_ *cobra.Command, _ []string) {
180+
fmt.Printf("try to build a new answer with plugins:\n%s\n", strings.Join(buildWithPlugins, "\n"))
181+
err := cli.BuildNewAnswer(buildOutput, buildWithPlugins, cli.OriginalAnswerInfo{
182+
Version: Version,
183+
Revision: Revision,
184+
Time: Time,
185+
})
186+
if err != nil {
187+
fmt.Printf("build failed %v", err)
188+
} else {
189+
fmt.Printf("build new answer successfully %s\n", buildOutput)
190+
}
191+
},
192+
}
193+
194+
// pluginCmd prints all plugins packed in the binary
195+
pluginCmd = &cobra.Command{
196+
Use: "plugin",
197+
Short: "prints all plugins packed in the binary",
198+
Long: `prints all plugins packed in the binary`,
199+
Run: func(_ *cobra.Command, _ []string) {
200+
_ = plugin.CallBase(func(base plugin.Base) error {
201+
info := base.Info()
202+
fmt.Printf("%s[%s] made by %s\n", info.SlugName, info.Version, info.Author)
203+
return nil
204+
})
205+
},
206+
}
163207
)
164208

165209
// Execute adds all child commands to the root command and sets flags appropriately.
166-
// This is called by main.main(). It only needs to happen once to the rootCmd.
210+
// This is called by main(). It only needs to happen once to the rootCmd.
167211
func Execute() {
168212
err := rootCmd.Execute()
169213
if err != nil {

cmd/main.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package answercmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"time"
7+
8+
"github.com/answerdev/answer/internal/base/conf"
9+
"github.com/answerdev/answer/internal/base/constant"
10+
"github.com/answerdev/answer/internal/base/cron"
11+
"github.com/answerdev/answer/internal/cli"
12+
"github.com/answerdev/answer/internal/schema"
13+
"github.com/gin-gonic/gin"
14+
"github.com/segmentfault/pacman"
15+
"github.com/segmentfault/pacman/contrib/log/zap"
16+
"github.com/segmentfault/pacman/contrib/server/http"
17+
"github.com/segmentfault/pacman/log"
18+
)
19+
20+
// go build -ldflags "-X github.com/answerdev/answer/cmd.Version=x.y.z"
21+
var (
22+
// Name is the name of the project
23+
Name = "answer"
24+
// Version is the version of the project
25+
Version = "0.0.0"
26+
// Revision is the git short commit revision number
27+
Revision = "-"
28+
// Time is the build time of the project
29+
Time = "-"
30+
// log level
31+
logLevel = os.Getenv("LOG_LEVEL")
32+
// log path
33+
logPath = os.Getenv("LOG_PATH")
34+
)
35+
36+
// Main
37+
// @securityDefinitions.apikey ApiKeyAuth
38+
// @in header
39+
// @name Authorization
40+
func Main() {
41+
log.SetLogger(zap.NewLogger(
42+
log.ParseLevel(logLevel), zap.WithName("answer"), zap.WithPath(logPath), zap.WithCallerFullPath()))
43+
Execute()
44+
}
45+
46+
func runApp() {
47+
c, err := conf.ReadConfig(cli.GetConfigFilePath())
48+
if err != nil {
49+
panic(err)
50+
}
51+
conf.GetPathIgnoreList()
52+
app, cleanup, err := initApplication(
53+
c.Debug, c.Server, c.Data.Database, c.Data.Cache, c.I18n, c.Swaggerui, c.ServiceConfig, log.GetLogger())
54+
if err != nil {
55+
panic(err)
56+
}
57+
constant.Version = Version
58+
constant.Revision = Revision
59+
schema.AppStartTime = time.Now()
60+
fmt.Println("answer Version:", constant.Version, " Revision:", constant.Revision)
61+
62+
defer cleanup()
63+
if err := app.Run(); err != nil {
64+
panic(err)
65+
}
66+
}
67+
68+
func newApplication(serverConf *conf.Server, server *gin.Engine, manager *cron.ScheduledTaskManager) *pacman.Application {
69+
manager.Run()
70+
return pacman.NewApp(
71+
pacman.WithName(Name),
72+
pacman.WithVersion(Version),
73+
pacman.WithServer(http.NewServer(server, serverConf.HTTP.Addr)),
74+
)
75+
}

cmd/answer/wire.go renamed to cmd/wire.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// The build tag makes sure the stub is not built in the final build.
55

6-
package main
6+
package answercmd
77

88
import (
99
"github.com/answerdev/answer/internal/base/conf"

cmd/answer/wire_gen.go renamed to cmd/wire_gen.go

Lines changed: 16 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)