Skip to content

Commit

Permalink
Make CustomPath, CustomConf and AppWorkPath configurable at build (#6631
Browse files Browse the repository at this point in the history
)
  • Loading branch information
zeripath authored and techknowlogick committed Apr 29, 2019
1 parent ccf4783 commit 8d0d7bc
Show file tree
Hide file tree
Showing 17 changed files with 184 additions and 193 deletions.
12 changes: 3 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ SHASUM ?= shasum -a 256
export PATH := $($(GO) env GOPATH)/bin:$(PATH)

ifeq ($(OS), Windows_NT)
EXECUTABLE := gitea.exe
EXECUTABLE ?= gitea.exe
else
EXECUTABLE := gitea
EXECUTABLE ?= gitea
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
SED_INPLACE := sed -i ''
Expand Down Expand Up @@ -39,7 +39,7 @@ else
GITEA_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
endif

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

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

ifeq ($(OS), Windows_NT)
EXECUTABLE := gitea.exe
else
EXECUTABLE := gitea
endif

# $(call strip-suffix,filename)
strip-suffix = $(firstword $(subst ., ,$(1)))

Expand Down
76 changes: 0 additions & 76 deletions cmd/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ var (
Name: "admin",
Usage: "User is an admin",
},
cli.StringFlag{
Name: "config, c",
Value: "custom/conf/app.ini",
Usage: "Custom configuration file path",
},
cli.BoolFlag{
Name: "random-password",
Usage: "Generate a random password for the user",
Expand Down Expand Up @@ -96,11 +91,6 @@ var (
Value: "",
Usage: "New password to set for user",
},
cli.StringFlag{
Name: "config, c",
Value: "custom/conf/app.ini",
Usage: "Custom configuration file path",
},
},
}

Expand All @@ -123,26 +113,12 @@ var (
Name: "hooks",
Usage: "Regenerate git-hooks",
Action: runRegenerateHooks,
Flags: []cli.Flag{
cli.StringFlag{
Name: "config, c",
Value: "custom/conf/app.ini",
Usage: "Custom configuration file path",
},
},
}

microcmdRegenKeys = cli.Command{
Name: "keys",
Usage: "Regenerate authorized_keys file",
Action: runRegenerateKeys,
Flags: []cli.Flag{
cli.StringFlag{
Name: "config, c",
Value: "custom/conf/app.ini",
Usage: "Custom configuration file path",
},
},
}

subcmdAuth = cli.Command{
Expand All @@ -160,13 +136,6 @@ var (
Name: "list",
Usage: "List auth sources",
Action: runListAuth,
Flags: []cli.Flag{
cli.StringFlag{
Name: "config, c",
Value: "custom/conf/app.ini",
Usage: "Custom configuration file path",
},
},
}

idFlag = cli.Int64Flag{
Expand All @@ -178,22 +147,9 @@ var (
Name: "delete",
Usage: "Delete specific auth source",
Action: runDeleteAuth,
Flags: []cli.Flag{
cli.StringFlag{
Name: "config, c",
Value: "custom/conf/app.ini",
Usage: "Custom configuration file path",
},
idFlag,
},
}

oauthCLIFlags = []cli.Flag{
cli.StringFlag{
Name: "config, c",
Value: "custom/conf/app.ini",
Usage: "Custom configuration file path",
},
cli.StringFlag{
Name: "name",
Value: "",
Expand Down Expand Up @@ -266,10 +222,6 @@ func runChangePassword(c *cli.Context) error {
return err
}

if c.IsSet("config") {
setting.CustomConf = c.String("config")
}

if err := initDB(); err != nil {
return err
}
Expand Down Expand Up @@ -331,10 +283,6 @@ func runCreateUser(c *cli.Context) error {
return errors.New("must set either password or random-password flag")
}

if c.IsSet("config") {
setting.CustomConf = c.String("config")
}

if err := initDB(); err != nil {
return err
}
Expand Down Expand Up @@ -430,21 +378,13 @@ func getReleaseCount(id int64) (int64, error) {
}

func runRegenerateHooks(c *cli.Context) error {
if c.IsSet("config") {
setting.CustomConf = c.String("config")
}

if err := initDB(); err != nil {
return err
}
return models.SyncRepositoryHooks()
}

func runRegenerateKeys(c *cli.Context) error {
if c.IsSet("config") {
setting.CustomConf = c.String("config")
}

if err := initDB(); err != nil {
return err
}
Expand Down Expand Up @@ -473,10 +413,6 @@ func parseOAuth2Config(c *cli.Context) *models.OAuth2Config {
}

func runAddOauth(c *cli.Context) error {
if c.IsSet("config") {
setting.CustomConf = c.String("config")
}

if err := initDB(); err != nil {
return err
}
Expand All @@ -490,10 +426,6 @@ func runAddOauth(c *cli.Context) error {
}

func runUpdateOauth(c *cli.Context) error {
if c.IsSet("config") {
setting.CustomConf = c.String("config")
}

if !c.IsSet("id") {
return fmt.Errorf("--id flag is missing")
}
Expand Down Expand Up @@ -561,10 +493,6 @@ func runUpdateOauth(c *cli.Context) error {
}

func runListAuth(c *cli.Context) error {
if c.IsSet("config") {
setting.CustomConf = c.String("config")
}

if err := initDB(); err != nil {
return err
}
Expand All @@ -587,10 +515,6 @@ func runListAuth(c *cli.Context) error {
}

func runDeleteAuth(c *cli.Context) error {
if c.IsSet("config") {
setting.CustomConf = c.String("config")
}

if !c.IsSet("id") {
return fmt.Errorf("--id flag is missing")
}
Expand Down
8 changes: 0 additions & 8 deletions cmd/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ var CmdDump = cli.Command{
It can be used for backup and capture Gitea server image to send to maintainer`,
Action: runDump,
Flags: []cli.Flag{
cli.StringFlag{
Name: "config, c",
Value: "custom/conf/app.ini",
Usage: "Custom configuration file path",
},
cli.StringFlag{
Name: "file, f",
Value: fmt.Sprintf("gitea-dump-%d.zip", time.Now().Unix()),
Expand All @@ -61,9 +56,6 @@ It can be used for backup and capture Gitea server image to send to maintainer`,
}

func runDump(ctx *cli.Context) error {
if ctx.IsSet("config") {
setting.CustomConf = ctx.String("config")
}
setting.NewContext()
setting.NewServices() // cannot access session settings otherwise
models.LoadConfigs()
Expand Down
26 changes: 0 additions & 26 deletions cmd/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/private"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"

"github.com/urfave/cli"
Expand All @@ -28,13 +27,6 @@ var (
Name: "hook",
Usage: "Delegate commands to corresponding Git hooks",
Description: "This should only be called by Git",
Flags: []cli.Flag{
cli.StringFlag{
Name: "config, c",
Value: "custom/conf/app.ini",
Usage: "Custom configuration file path",
},
},
Subcommands: []cli.Command{
subcmdHookPreReceive,
subcmdHookUpdate,
Expand Down Expand Up @@ -67,12 +59,6 @@ func runHookPreReceive(c *cli.Context) error {
return nil
}

if c.IsSet("config") {
setting.CustomConf = c.String("config")
} else if c.GlobalIsSet("config") {
setting.CustomConf = c.GlobalString("config")
}

setup("hooks/pre-receive.log")

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

if c.IsSet("config") {
setting.CustomConf = c.String("config")
} else if c.GlobalIsSet("config") {
setting.CustomConf = c.GlobalString("config")
}

setup("hooks/update.log")

return nil
Expand All @@ -159,12 +139,6 @@ func runHookPostReceive(c *cli.Context) error {
return nil
}

if c.IsSet("config") {
setting.CustomConf = c.String("config")
} else if c.GlobalIsSet("config") {
setting.CustomConf = c.GlobalString("config")
}

setup("hooks/post-receive.log")

// the environment setted on serv command
Expand Down
10 changes: 0 additions & 10 deletions cmd/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"strings"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/setting"

"github.com/urfave/cli"
)
Expand Down Expand Up @@ -41,19 +40,10 @@ var CmdKeys = cli.Command{
Value: "",
Usage: "Base64 encoded content of the SSH key provided to the SSH Server (requires type to be provided too)",
},
cli.StringFlag{
Name: "config, c",
Value: "custom/conf/app.ini",
Usage: "Custom configuration file path",
},
},
}

func runKeys(c *cli.Context) error {
if c.IsSet("config") {
setting.CustomConf = c.String("config")
}

if !c.IsSet("username") {
return errors.New("No username provided")
}
Expand Down
11 changes: 0 additions & 11 deletions cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,9 @@ var CmdMigrate = cli.Command{
Usage: "Migrate the database",
Description: "This is a command for migrating the database, so that you can run gitea admin create-user before starting the server.",
Action: runMigrate,
Flags: []cli.Flag{
cli.StringFlag{
Name: "config, c",
Value: "custom/conf/app.ini",
Usage: "Custom configuration file path",
},
},
}

func runMigrate(ctx *cli.Context) error {
if ctx.IsSet("config") {
setting.CustomConf = ctx.String("config")
}

if err := initDB(); err != nil {
return err
}
Expand Down
8 changes: 0 additions & 8 deletions cmd/serv.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ var CmdServ = cli.Command{
Description: `Serv provide access auth for repositories`,
Action: runServ,
Flags: []cli.Flag{
cli.StringFlag{
Name: "config, c",
Value: "custom/conf/app.ini",
Usage: "Custom configuration file path",
},
cli.BoolFlag{
Name: "enable-pprof",
},
Expand Down Expand Up @@ -109,9 +104,6 @@ func fail(userMessage, logMessage string, args ...interface{}) {
}

func runServ(c *cli.Context) error {
if c.IsSet("config") {
setting.CustomConf = c.String("config")
}
setup("serv.log")

if setting.SSH.Disabled {
Expand Down
9 changes: 0 additions & 9 deletions cmd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ and it takes care of all the other things for you`,
Value: "3000",
Usage: "Temporary port number to prevent conflict",
},
cli.StringFlag{
Name: "config, c",
Value: "custom/conf/app.ini",
Usage: "Custom configuration file path",
},
cli.StringFlag{
Name: "pid, P",
Value: "/var/run/gitea.pid",
Expand Down Expand Up @@ -110,10 +105,6 @@ func runLetsEncryptFallbackHandler(w http.ResponseWriter, r *http.Request) {
}

func runWeb(ctx *cli.Context) error {
if ctx.IsSet("config") {
setting.CustomConf = ctx.String("config")
}

if ctx.IsSet("pid") {
setting.CustomPID = ctx.String("pid")
}
Expand Down
1 change: 1 addition & 0 deletions contrib/pr/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func runPR() {
if err != nil {
log.Fatal(err)
}
setting.SetCustomPathAndConf("", "")
setting.NewContext()

setting.RepoRootPath, err = ioutil.TempDir(os.TempDir(), "repos")
Expand Down
Loading

0 comments on commit 8d0d7bc

Please sign in to comment.