Skip to content

Commit 8d0d7bc

Browse files
zeripathtechknowlogick
authored andcommitted
Make CustomPath, CustomConf and AppWorkPath configurable at build (#6631)
1 parent ccf4783 commit 8d0d7bc

File tree

17 files changed

+184
-193
lines changed

17 files changed

+184
-193
lines changed

Makefile

+3-9
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ SHASUM ?= shasum -a 256
99
export PATH := $($(GO) env GOPATH)/bin:$(PATH)
1010

1111
ifeq ($(OS), Windows_NT)
12-
EXECUTABLE := gitea.exe
12+
EXECUTABLE ?= gitea.exe
1313
else
14-
EXECUTABLE := gitea
14+
EXECUTABLE ?= gitea
1515
UNAME_S := $(shell uname -s)
1616
ifeq ($(UNAME_S),Darwin)
1717
SED_INPLACE := sed -i ''
@@ -39,7 +39,7 @@ else
3939
GITEA_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
4040
endif
4141

42-
LDFLAGS := -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(GITEA_VERSION)" -X "main.Tags=$(TAGS)"
42+
LDFLAGS := $(LDFLAGS) -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(GITEA_VERSION)" -X "main.Tags=$(TAGS)"
4343

4444
PACKAGES ?= $(filter-out code.gitea.io/gitea/integrations/migration-test,$(filter-out code.gitea.io/gitea/integrations,$(shell $(GO) list ./... | grep -v /vendor/)))
4545
SOURCES ?= $(shell find . -name "*.go" -type f)
@@ -70,12 +70,6 @@ TEST_MSSQL_DBNAME ?= gitea
7070
TEST_MSSQL_USERNAME ?= sa
7171
TEST_MSSQL_PASSWORD ?= MwantsaSecurePassword1
7272

73-
ifeq ($(OS), Windows_NT)
74-
EXECUTABLE := gitea.exe
75-
else
76-
EXECUTABLE := gitea
77-
endif
78-
7973
# $(call strip-suffix,filename)
8074
strip-suffix = $(firstword $(subst ., ,$(1)))
8175

cmd/admin.go

-76
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ var (
6060
Name: "admin",
6161
Usage: "User is an admin",
6262
},
63-
cli.StringFlag{
64-
Name: "config, c",
65-
Value: "custom/conf/app.ini",
66-
Usage: "Custom configuration file path",
67-
},
6863
cli.BoolFlag{
6964
Name: "random-password",
7065
Usage: "Generate a random password for the user",
@@ -96,11 +91,6 @@ var (
9691
Value: "",
9792
Usage: "New password to set for user",
9893
},
99-
cli.StringFlag{
100-
Name: "config, c",
101-
Value: "custom/conf/app.ini",
102-
Usage: "Custom configuration file path",
103-
},
10494
},
10595
}
10696

@@ -123,26 +113,12 @@ var (
123113
Name: "hooks",
124114
Usage: "Regenerate git-hooks",
125115
Action: runRegenerateHooks,
126-
Flags: []cli.Flag{
127-
cli.StringFlag{
128-
Name: "config, c",
129-
Value: "custom/conf/app.ini",
130-
Usage: "Custom configuration file path",
131-
},
132-
},
133116
}
134117

135118
microcmdRegenKeys = cli.Command{
136119
Name: "keys",
137120
Usage: "Regenerate authorized_keys file",
138121
Action: runRegenerateKeys,
139-
Flags: []cli.Flag{
140-
cli.StringFlag{
141-
Name: "config, c",
142-
Value: "custom/conf/app.ini",
143-
Usage: "Custom configuration file path",
144-
},
145-
},
146122
}
147123

148124
subcmdAuth = cli.Command{
@@ -160,13 +136,6 @@ var (
160136
Name: "list",
161137
Usage: "List auth sources",
162138
Action: runListAuth,
163-
Flags: []cli.Flag{
164-
cli.StringFlag{
165-
Name: "config, c",
166-
Value: "custom/conf/app.ini",
167-
Usage: "Custom configuration file path",
168-
},
169-
},
170139
}
171140

172141
idFlag = cli.Int64Flag{
@@ -178,22 +147,9 @@ var (
178147
Name: "delete",
179148
Usage: "Delete specific auth source",
180149
Action: runDeleteAuth,
181-
Flags: []cli.Flag{
182-
cli.StringFlag{
183-
Name: "config, c",
184-
Value: "custom/conf/app.ini",
185-
Usage: "Custom configuration file path",
186-
},
187-
idFlag,
188-
},
189150
}
190151

191152
oauthCLIFlags = []cli.Flag{
192-
cli.StringFlag{
193-
Name: "config, c",
194-
Value: "custom/conf/app.ini",
195-
Usage: "Custom configuration file path",
196-
},
197153
cli.StringFlag{
198154
Name: "name",
199155
Value: "",
@@ -266,10 +222,6 @@ func runChangePassword(c *cli.Context) error {
266222
return err
267223
}
268224

269-
if c.IsSet("config") {
270-
setting.CustomConf = c.String("config")
271-
}
272-
273225
if err := initDB(); err != nil {
274226
return err
275227
}
@@ -331,10 +283,6 @@ func runCreateUser(c *cli.Context) error {
331283
return errors.New("must set either password or random-password flag")
332284
}
333285

334-
if c.IsSet("config") {
335-
setting.CustomConf = c.String("config")
336-
}
337-
338286
if err := initDB(); err != nil {
339287
return err
340288
}
@@ -430,21 +378,13 @@ func getReleaseCount(id int64) (int64, error) {
430378
}
431379

432380
func runRegenerateHooks(c *cli.Context) error {
433-
if c.IsSet("config") {
434-
setting.CustomConf = c.String("config")
435-
}
436-
437381
if err := initDB(); err != nil {
438382
return err
439383
}
440384
return models.SyncRepositoryHooks()
441385
}
442386

443387
func runRegenerateKeys(c *cli.Context) error {
444-
if c.IsSet("config") {
445-
setting.CustomConf = c.String("config")
446-
}
447-
448388
if err := initDB(); err != nil {
449389
return err
450390
}
@@ -473,10 +413,6 @@ func parseOAuth2Config(c *cli.Context) *models.OAuth2Config {
473413
}
474414

475415
func runAddOauth(c *cli.Context) error {
476-
if c.IsSet("config") {
477-
setting.CustomConf = c.String("config")
478-
}
479-
480416
if err := initDB(); err != nil {
481417
return err
482418
}
@@ -490,10 +426,6 @@ func runAddOauth(c *cli.Context) error {
490426
}
491427

492428
func runUpdateOauth(c *cli.Context) error {
493-
if c.IsSet("config") {
494-
setting.CustomConf = c.String("config")
495-
}
496-
497429
if !c.IsSet("id") {
498430
return fmt.Errorf("--id flag is missing")
499431
}
@@ -561,10 +493,6 @@ func runUpdateOauth(c *cli.Context) error {
561493
}
562494

563495
func runListAuth(c *cli.Context) error {
564-
if c.IsSet("config") {
565-
setting.CustomConf = c.String("config")
566-
}
567-
568496
if err := initDB(); err != nil {
569497
return err
570498
}
@@ -587,10 +515,6 @@ func runListAuth(c *cli.Context) error {
587515
}
588516

589517
func runDeleteAuth(c *cli.Context) error {
590-
if c.IsSet("config") {
591-
setting.CustomConf = c.String("config")
592-
}
593-
594518
if !c.IsSet("id") {
595519
return fmt.Errorf("--id flag is missing")
596520
}

cmd/dump.go

-8
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ var CmdDump = cli.Command{
3030
It can be used for backup and capture Gitea server image to send to maintainer`,
3131
Action: runDump,
3232
Flags: []cli.Flag{
33-
cli.StringFlag{
34-
Name: "config, c",
35-
Value: "custom/conf/app.ini",
36-
Usage: "Custom configuration file path",
37-
},
3833
cli.StringFlag{
3934
Name: "file, f",
4035
Value: fmt.Sprintf("gitea-dump-%d.zip", time.Now().Unix()),
@@ -61,9 +56,6 @@ It can be used for backup and capture Gitea server image to send to maintainer`,
6156
}
6257

6358
func runDump(ctx *cli.Context) error {
64-
if ctx.IsSet("config") {
65-
setting.CustomConf = ctx.String("config")
66-
}
6759
setting.NewContext()
6860
setting.NewServices() // cannot access session settings otherwise
6961
models.LoadConfigs()

cmd/hook.go

-26
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"code.gitea.io/gitea/modules/git"
1717
"code.gitea.io/gitea/modules/log"
1818
"code.gitea.io/gitea/modules/private"
19-
"code.gitea.io/gitea/modules/setting"
2019
"code.gitea.io/gitea/modules/util"
2120

2221
"github.com/urfave/cli"
@@ -28,13 +27,6 @@ var (
2827
Name: "hook",
2928
Usage: "Delegate commands to corresponding Git hooks",
3029
Description: "This should only be called by Git",
31-
Flags: []cli.Flag{
32-
cli.StringFlag{
33-
Name: "config, c",
34-
Value: "custom/conf/app.ini",
35-
Usage: "Custom configuration file path",
36-
},
37-
},
3830
Subcommands: []cli.Command{
3931
subcmdHookPreReceive,
4032
subcmdHookUpdate,
@@ -67,12 +59,6 @@ func runHookPreReceive(c *cli.Context) error {
6759
return nil
6860
}
6961

70-
if c.IsSet("config") {
71-
setting.CustomConf = c.String("config")
72-
} else if c.GlobalIsSet("config") {
73-
setting.CustomConf = c.GlobalString("config")
74-
}
75-
7662
setup("hooks/pre-receive.log")
7763

7864
// the environment setted on serv command
@@ -143,12 +129,6 @@ func runHookUpdate(c *cli.Context) error {
143129
return nil
144130
}
145131

146-
if c.IsSet("config") {
147-
setting.CustomConf = c.String("config")
148-
} else if c.GlobalIsSet("config") {
149-
setting.CustomConf = c.GlobalString("config")
150-
}
151-
152132
setup("hooks/update.log")
153133

154134
return nil
@@ -159,12 +139,6 @@ func runHookPostReceive(c *cli.Context) error {
159139
return nil
160140
}
161141

162-
if c.IsSet("config") {
163-
setting.CustomConf = c.String("config")
164-
} else if c.GlobalIsSet("config") {
165-
setting.CustomConf = c.GlobalString("config")
166-
}
167-
168142
setup("hooks/post-receive.log")
169143

170144
// the environment setted on serv command

cmd/keys.go

-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"strings"
1111

1212
"code.gitea.io/gitea/models"
13-
"code.gitea.io/gitea/modules/setting"
1413

1514
"github.com/urfave/cli"
1615
)
@@ -41,19 +40,10 @@ var CmdKeys = cli.Command{
4140
Value: "",
4241
Usage: "Base64 encoded content of the SSH key provided to the SSH Server (requires type to be provided too)",
4342
},
44-
cli.StringFlag{
45-
Name: "config, c",
46-
Value: "custom/conf/app.ini",
47-
Usage: "Custom configuration file path",
48-
},
4943
},
5044
}
5145

5246
func runKeys(c *cli.Context) error {
53-
if c.IsSet("config") {
54-
setting.CustomConf = c.String("config")
55-
}
56-
5747
if !c.IsSet("username") {
5848
return errors.New("No username provided")
5949
}

cmd/migrate.go

-11
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,9 @@ var CmdMigrate = cli.Command{
1919
Usage: "Migrate the database",
2020
Description: "This is a command for migrating the database, so that you can run gitea admin create-user before starting the server.",
2121
Action: runMigrate,
22-
Flags: []cli.Flag{
23-
cli.StringFlag{
24-
Name: "config, c",
25-
Value: "custom/conf/app.ini",
26-
Usage: "Custom configuration file path",
27-
},
28-
},
2922
}
3023

3124
func runMigrate(ctx *cli.Context) error {
32-
if ctx.IsSet("config") {
33-
setting.CustomConf = ctx.String("config")
34-
}
35-
3625
if err := initDB(); err != nil {
3726
return err
3827
}

cmd/serv.go

-8
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ var CmdServ = cli.Command{
3939
Description: `Serv provide access auth for repositories`,
4040
Action: runServ,
4141
Flags: []cli.Flag{
42-
cli.StringFlag{
43-
Name: "config, c",
44-
Value: "custom/conf/app.ini",
45-
Usage: "Custom configuration file path",
46-
},
4742
cli.BoolFlag{
4843
Name: "enable-pprof",
4944
},
@@ -109,9 +104,6 @@ func fail(userMessage, logMessage string, args ...interface{}) {
109104
}
110105

111106
func runServ(c *cli.Context) error {
112-
if c.IsSet("config") {
113-
setting.CustomConf = c.String("config")
114-
}
115107
setup("serv.log")
116108

117109
if setting.SSH.Disabled {

cmd/web.go

-9
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ and it takes care of all the other things for you`,
4040
Value: "3000",
4141
Usage: "Temporary port number to prevent conflict",
4242
},
43-
cli.StringFlag{
44-
Name: "config, c",
45-
Value: "custom/conf/app.ini",
46-
Usage: "Custom configuration file path",
47-
},
4843
cli.StringFlag{
4944
Name: "pid, P",
5045
Value: "/var/run/gitea.pid",
@@ -110,10 +105,6 @@ func runLetsEncryptFallbackHandler(w http.ResponseWriter, r *http.Request) {
110105
}
111106

112107
func runWeb(ctx *cli.Context) error {
113-
if ctx.IsSet("config") {
114-
setting.CustomConf = ctx.String("config")
115-
}
116-
117108
if ctx.IsSet("pid") {
118109
setting.CustomPID = ctx.String("pid")
119110
}

contrib/pr/checkout.go

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func runPR() {
4343
if err != nil {
4444
log.Fatal(err)
4545
}
46+
setting.SetCustomPathAndConf("", "")
4647
setting.NewContext()
4748

4849
setting.RepoRootPath, err = ioutil.TempDir(os.TempDir(), "repos")

0 commit comments

Comments
 (0)