Skip to content

Commit 653c171

Browse files
committed
Merge branch 'master' of https://github.com/go-gitea/gitea
2 parents 36fc363 + d151503 commit 653c171

File tree

728 files changed

+19310
-5459
lines changed

Some content is hidden

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

728 files changed

+19310
-5459
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ fmt-check:
168168
test:
169169
GO111MODULE=on $(GO) test -mod=vendor -tags='sqlite sqlite_unlock_notify' $(PACKAGES)
170170

171+
.PHONY: test\#%
172+
test\#%:
173+
GO111MODULE=on $(GO) test -mod=vendor -tags='sqlite sqlite_unlock_notify' -run $* $(PACKAGES)
174+
171175
.PHONY: coverage
172176
coverage:
173177
@hash gocovmerge > /dev/null 2>&1; if [ $$? -ne 0 ]; then \

cmd/web.go

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,13 @@ func runLetsEncrypt(listenAddr, domain, directory, email string, m http.Handler)
7575
}
7676
go func() {
7777
log.Info("Running Let's Encrypt handler on %s", setting.HTTPAddr+":"+setting.PortToRedirect)
78-
var err = http.ListenAndServe(setting.HTTPAddr+":"+setting.PortToRedirect, certManager.HTTPHandler(http.HandlerFunc(runLetsEncryptFallbackHandler))) // all traffic coming into HTTP will be redirect to HTTPS automatically (LE HTTP-01 validation happens here)
78+
// all traffic coming into HTTP will be redirect to HTTPS automatically (LE HTTP-01 validation happens here)
79+
var err = runHTTP(setting.HTTPAddr+":"+setting.PortToRedirect, certManager.HTTPHandler(http.HandlerFunc(runLetsEncryptFallbackHandler)))
7980
if err != nil {
8081
log.Fatal("Failed to start the Let's Encrypt handler on port %s: %v", setting.PortToRedirect, err)
8182
}
8283
}()
83-
server := &http.Server{
84-
Addr: listenAddr,
85-
Handler: m,
86-
TLSConfig: certManager.TLSConfig(),
87-
}
88-
return server.ListenAndServeTLS("", "")
84+
return runHTTPSWithTLSConfig(listenAddr, certManager.TLSConfig(), context2.ClearHandler(m))
8985
}
9086

9187
func runLetsEncryptFallbackHandler(w http.ResponseWriter, r *http.Request) {
@@ -101,12 +97,21 @@ func runLetsEncryptFallbackHandler(w http.ResponseWriter, r *http.Request) {
10197
}
10298

10399
func runWeb(ctx *cli.Context) error {
100+
if os.Getppid() > 1 && len(os.Getenv("LISTEN_FDS")) > 0 {
101+
log.Info("Restarting Gitea on PID: %d from parent PID: %d", os.Getpid(), os.Getppid())
102+
} else {
103+
log.Info("Starting Gitea on PID: %d", os.Getpid())
104+
}
105+
106+
// Set pid file setting
104107
if ctx.IsSet("pid") {
105108
setting.CustomPID = ctx.String("pid")
106109
}
107110

111+
// Perform global initialization
108112
routers.GlobalInit()
109113

114+
// Set up Macaron
110115
m := routes.NewMacaron()
111116
routes.RegisterRoutes(m)
112117

@@ -164,6 +169,7 @@ func runWeb(ctx *cli.Context) error {
164169
var err error
165170
switch setting.Protocol {
166171
case setting.HTTP:
172+
NoHTTPRedirector()
167173
err = runHTTP(listenAddr, context2.ClearHandler(m))
168174
case setting.HTTPS:
169175
if setting.EnableLetsEncrypt {
@@ -172,9 +178,15 @@ func runWeb(ctx *cli.Context) error {
172178
}
173179
if setting.RedirectOtherPort {
174180
go runHTTPRedirector()
181+
} else {
182+
NoHTTPRedirector()
175183
}
176184
err = runHTTPS(listenAddr, setting.CertFile, setting.KeyFile, context2.ClearHandler(m))
177185
case setting.FCGI:
186+
NoHTTPRedirector()
187+
// FCGI listeners are provided as stdin - this is orthogonal to the LISTEN_FDS approach
188+
// in graceful and systemD
189+
NoMainListener()
178190
var listener net.Listener
179191
listener, err = net.Listen("tcp", listenAddr)
180192
if err != nil {
@@ -187,6 +199,10 @@ func runWeb(ctx *cli.Context) error {
187199
}()
188200
err = fcgi.Serve(listener, context2.ClearHandler(m))
189201
case setting.UnixSocket:
202+
// This could potentially be inherited using LISTEN_FDS but currently
203+
// these cannot be inherited
204+
NoHTTPRedirector()
205+
NoMainListener()
190206
if err := os.Remove(listenAddr); err != nil && !os.IsNotExist(err) {
191207
log.Fatal("Failed to remove unix socket directory %s: %v", listenAddr, err)
192208
}
@@ -207,8 +223,9 @@ func runWeb(ctx *cli.Context) error {
207223
}
208224

209225
if err != nil {
210-
log.Fatal("Failed to start server: %v", err)
226+
log.Critical("Failed to start server: %v", err)
211227
}
212-
228+
log.Info("HTTP Listener: %s Closed", listenAddr)
229+
log.Close()
213230
return nil
214231
}

cmd/web_graceful.go

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,28 @@ import (
1010
"crypto/tls"
1111
"net/http"
1212

13-
"code.gitea.io/gitea/modules/log"
14-
15-
"github.com/facebookgo/grace/gracehttp"
13+
"code.gitea.io/gitea/modules/graceful"
1614
)
1715

1816
func runHTTP(listenAddr string, m http.Handler) error {
19-
return gracehttp.Serve(&http.Server{
20-
Addr: listenAddr,
21-
Handler: m,
22-
})
17+
return graceful.HTTPListenAndServe("tcp", listenAddr, m)
2318
}
2419

2520
func runHTTPS(listenAddr, certFile, keyFile string, m http.Handler) error {
26-
config := &tls.Config{
27-
MinVersion: tls.VersionTLS10,
28-
}
29-
if config.NextProtos == nil {
30-
config.NextProtos = []string{"http/1.1"}
31-
}
32-
33-
config.Certificates = make([]tls.Certificate, 1)
34-
var err error
35-
config.Certificates[0], err = tls.LoadX509KeyPair(certFile, keyFile)
36-
if err != nil {
37-
log.Fatal("Failed to load https cert file %s: %v", listenAddr, err)
38-
}
39-
40-
return gracehttp.Serve(&http.Server{
41-
Addr: listenAddr,
42-
Handler: m,
43-
TLSConfig: config,
44-
})
21+
return graceful.HTTPListenAndServeTLS("tcp", listenAddr, certFile, keyFile, m)
22+
}
23+
24+
func runHTTPSWithTLSConfig(listenAddr string, tlsConfig *tls.Config, m http.Handler) error {
25+
return graceful.HTTPListenAndServeTLSConfig("tcp", listenAddr, tlsConfig, m)
26+
}
27+
28+
// NoHTTPRedirector tells our cleanup routine that we will not be using a fallback http redirector
29+
func NoHTTPRedirector() {
30+
graceful.InformCleanup()
31+
}
32+
33+
// NoMainListener tells our cleanup routine that we will not be using a possibly provided listener
34+
// for our main HTTP/HTTPS service
35+
func NoMainListener() {
36+
graceful.InformCleanup()
4537
}

cmd/web_windows.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package cmd
88

99
import (
10+
"crypto/tls"
1011
"net/http"
1112
)
1213

@@ -17,3 +18,20 @@ func runHTTP(listenAddr string, m http.Handler) error {
1718
func runHTTPS(listenAddr, certFile, keyFile string, m http.Handler) error {
1819
return http.ListenAndServeTLS(listenAddr, certFile, keyFile, m)
1920
}
21+
22+
func runHTTPSWithTLSConfig(listenAddr string, tlsConfig *tls.Config, m http.Handler) error {
23+
server := &http.Server{
24+
Addr: listenAddr,
25+
Handler: m,
26+
TLSConfig: tlsConfig,
27+
}
28+
return server.ListenAndServeTLS("", "")
29+
}
30+
31+
// NoHTTPRedirector is a no-op on Windows
32+
func NoHTTPRedirector() {
33+
}
34+
35+
// NoMainListener is a no-op on Windows
36+
func NoMainListener() {
37+
}

contrib/pr/checkout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ import (
2727
"code.gitea.io/gitea/routers"
2828
"code.gitea.io/gitea/routers/routes"
2929

30-
"github.com/go-xorm/xorm"
3130
context2 "github.com/gorilla/context"
3231
"github.com/unknwon/com"
3332
"gopkg.in/src-d/go-git.v4"
3433
"gopkg.in/src-d/go-git.v4/config"
3534
"gopkg.in/src-d/go-git.v4/plumbing"
3635
"gopkg.in/testfixtures.v2"
36+
"xorm.io/xorm"
3737
)
3838

3939
var codeFilePath = "contrib/pr/checkout.go"

contrib/systemd/gitea.service

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,41 @@
22
Description=Gitea (Git with a cup of tea)
33
After=syslog.target
44
After=network.target
5+
###
6+
# Don't forget to add the database service requirements
7+
###
8+
#
59
#Requires=mysql.service
610
#Requires=mariadb.service
711
#Requires=postgresql.service
812
#Requires=memcached.service
913
#Requires=redis.service
14+
#
15+
###
16+
# If using socket activation for main http/s
17+
###
18+
#
19+
#After=gitea.main.socket
20+
#Requires=gitea.main.socket
21+
#
22+
###
23+
# (You can also provide gitea an http fallback and/or ssh socket too)
24+
#
25+
# An example of /etc/systemd/system/gitea.main.socket
26+
###
27+
##
28+
## [Unit]
29+
## Description=Gitea Web Socket
30+
## PartOf=gitea.service
31+
##
32+
## [Socket]
33+
## ListenStream=
34+
## NoDelay=true
35+
##
36+
## [Install]
37+
## WantedBy=sockets.target
38+
##
39+
###
1040

1141
[Service]
1242
# Modify these two values and uncomment them if you have
@@ -26,11 +56,12 @@ WorkingDirectory=/var/lib/gitea/
2656
ExecStart=/usr/local/bin/gitea web -c /etc/gitea/app.ini
2757
Restart=always
2858
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea
29-
# If you want to bind Gitea to a port below 1024 uncomment
30-
# the two values below
59+
# If you want to bind Gitea to a port below 1024, uncomment
60+
# the two values below, or use socket activation to pass Gitea its ports as above
3161
###
3262
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
3363
#AmbientCapabilities=CAP_NET_BIND_SERVICE
64+
###
3465

3566
[Install]
3667
WantedBy=multi-user.target

custom/conf/app.ini.sample

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,37 @@ WORK_IN_PROGRESS_PREFIXES=WIP:,[WIP]
7474
; List of reasons why a Pull Request or Issue can be locked
7575
LOCK_REASONS=Too heated,Off-topic,Resolved,Spam
7676

77+
[repository.signing]
78+
; GPG key to use to sign commits, Defaults to the default - that is the value of git config --get user.signingkey
79+
; run in the context of the RUN_USER
80+
; Switch to none to stop signing completely
81+
SIGNING_KEY = default
82+
; If a SIGNING_KEY ID is provided and is not set to default, use the provided Name and Email address as the signer.
83+
; These should match a publicized name and email address for the key. (When SIGNING_KEY is default these are set to
84+
; the results of git config --get user.name and git config --get user.email respectively and can only be overrided
85+
; by setting the SIGNING_KEY ID to the correct ID.)
86+
SIGNING_NAME =
87+
SIGNING_EMAIL =
88+
; Determines when gitea should sign the initial commit when creating a repository
89+
; Either:
90+
; - never
91+
; - pubkey: only sign if the user has a pubkey
92+
; - twofa: only sign if the user has logged in with twofa
93+
; - always
94+
; options other than none and always can be combined as comma separated list
95+
INITIAL_COMMIT = always
96+
; Determines when to sign for CRUD actions
97+
; - as above
98+
; - parentsigned: requires that the parent commit is signed.
99+
CRUD_ACTIONS = pubkey, twofa, parentsigned
100+
; Determines when to sign Wiki commits
101+
; - as above
102+
WIKI = never
103+
; Determines when to sign on merges
104+
; - basesigned: require that the parent of commit on the base repo is signed.
105+
; - commitssigned: require that all the commits in the head branch are signed.
106+
MERGES = pubkey, twofa, basesigned, commitssigned
107+
77108
[cors]
78109
; More information about CORS can be found here: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#The_HTTP_response_headers
79110
; enable cors headers (disabled by default)
@@ -141,8 +172,9 @@ KEYWORDS = go,git,self-hosted,gitea
141172
[markdown]
142173
; Enable hard line break extension
143174
ENABLE_HARD_LINE_BREAK = false
144-
; List of custom URL-Schemes that are allowed as links when rendering Markdown
145-
; for example git,magnet
175+
; Comma separated list of custom URL-Schemes that are allowed as links when rendering Markdown
176+
; for example git,magnet,ftp (more at https://en.wikipedia.org/wiki/List_of_URI_schemes)
177+
; URLs starting with http and https are always displayed, whatever is put in this entry.
146178
CUSTOM_URL_SCHEMES =
147179
; List of file extensions that should be rendered/edited as Markdown
148180
; Separate the extensions with a comma. To render files without any extension as markdown, just put a comma
@@ -243,6 +275,14 @@ LFS_CONTENT_PATH = data/lfs
243275
LFS_JWT_SECRET =
244276
; LFS authentication validity period (in time.Duration), pushes taking longer than this may fail.
245277
LFS_HTTP_AUTH_EXPIRY = 20m
278+
; Allow graceful restarts using SIGHUP to fork
279+
ALLOW_GRACEFUL_RESTARTS = true
280+
; After a restart the parent will finish ongoing requests before
281+
; shutting down. Force shutdown if this process takes longer than this delay.
282+
; set to a negative value to disable
283+
GRACEFUL_HAMMER_TIME = 60s
284+
; Static resources, includes resources on custom/, public/ and all uploaded avatars web browser cache time, default is 6h
285+
STATIC_CACHE_TIME = 6h
246286

247287
; Define allowed algorithms and their minimum key length (use -1 to disable a type)
248288
[ssh.minimum_key_sizes]
@@ -296,6 +336,9 @@ ISSUE_INDEXER_QUEUE_DIR = indexers/issues.queue
296336
ISSUE_INDEXER_QUEUE_CONN_STR = "addrs=127.0.0.1:6379 db=0"
297337
; Batch queue number, default is 20
298338
ISSUE_INDEXER_QUEUE_BATCH_NUMBER = 20
339+
; Timeout the indexer if it takes longer than this to start.
340+
; Set to zero to disable timeout.
341+
STARTUP_TIMEOUT=30s
299342

300343
; repo indexer by default disabled, since it uses a lot of disk space
301344
REPO_INDEXER_ENABLED = false
@@ -333,7 +376,8 @@ IMPORT_LOCAL_PATHS = false
333376
; Set to true to prevent all users (including admin) from creating custom git hooks
334377
DISABLE_GIT_HOOKS = false
335378
;Comma separated list of character classes required to pass minimum complexity.
336-
;If left empty or no valid values are specified, the default values (`lower,upper,digit,spec`) will be used.
379+
;If left empty or no valid values are specified, the default values ("lower,upper,digit,spec") will be used.
380+
;Use "off" to disable checking.
337381
PASSWORD_COMPLEXITY = lower,upper,digit,spec
338382
; Password Hash algorithm, either "pbkdf2", "argon2", "scrypt" or "bcrypt"
339383
PASSWORD_HASH_ALGO = pbkdf2
@@ -826,4 +870,4 @@ QUEUE_TYPE = channel
826870
QUEUE_LENGTH = 1000
827871
; Task queue connction string, available only when `QUEUE_TYPE` is `redis`.
828872
; If there is a password of redis, use `addrs=127.0.0.1:6379 password=123 db=0`.
829-
QUEUE_CONN_STR = "addrs=127.0.0.1:6379 db=0"
873+
QUEUE_CONN_STR = "addrs=127.0.0.1:6379 db=0"

0 commit comments

Comments
 (0)