Skip to content

Commit c92ac4e

Browse files
committed
Merge branch 'master' of git://github.com/go-gitea/gitea
2 parents 653c171 + 6aa3f8b commit c92ac4e

File tree

147 files changed

+2008
-1517
lines changed

Some content is hidden

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

147 files changed

+2008
-1517
lines changed

CONTRIBUTING.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- [Translation](#translation)
1212
- [Code review](#code-review)
1313
- [Styleguide](#styleguide)
14+
- [Design guideline](#design-guideline)
1415
- [Developer Certificate of Origin (DCO)](#developer-certificate-of-origin-dco)
1516
- [Release Cycle](#release-cycle)
1617
- [Maintainers](#maintainers)
@@ -71,13 +72,15 @@ Here's how to run the test suite:
7172

7273
- Install the correct version of the drone-cli package. As of this
7374
writing, the correct drone-cli version is
74-
[1.1.0](https://docs.drone.io/cli/install/).
75+
[1.2.0](https://docs.drone.io/cli/install/).
7576
- Ensure you have enough free disk space. You will need at least
7677
15-20 Gb of free disk space to hold all of the containers drone
7778
creates (a default AWS or GCE disk size won't work -- see
7879
[#6243](https://github.com/go-gitea/gitea/issues/6243)).
7980
- Change into the base directory of your copy of the gitea repository,
8081
and run `drone exec --event pull_request`.
82+
- At the moment `drone exec` doesn't support the Docker Toolbox on Windows 10
83+
(see [drone-cli#135](https://github.com/drone/drone-cli/issues/135))
8184

8285
The drone version, command line, and disk requirements do change over
8386
time (see [#4053](https://github.com/go-gitea/gitea/issues/4053) and
@@ -118,6 +121,8 @@ An exception are the tools to build the CSS and images.
118121
- To build Images: ImageMagick, inkscape and zopflipng binaries must be
119122
available in your `PATH` to run `make generate-images`.
120123

124+
For more details on how to generate files, build and test Gitea, see the [hacking instructions](https://docs.gitea.io/en-us/hacking-on-gitea/)
125+
121126
## Code review
122127

123128
Changes to Gitea must be reviewed before they are accepted—no matter who
@@ -157,6 +162,22 @@ import (
157162
)
158163
```
159164

165+
## Design guideline
166+
167+
To maintain understandable code and avoid circular dependencies it is important to have a good structure of the code. The gitea code is divided into the following parts:
168+
169+
- **integration:** Integrations tests
170+
- **models:** Contains the data structures used by xorm to construct database tables. It also contains supporting functions to query and update the database. Dependecies to other code in Gitea should be avoided although some modules might be needed (for example for logging).
171+
- **models/fixtures:** Sample model data used in integration tests.
172+
- **models/migrations:** Handling of database migrations between versions. PRs that changes a database structure shall also have a migration step.
173+
- **modules:** Different modules to handle specific functionality in Gitea.
174+
- **public:** Frontend files (javascript, images, css, etc.)
175+
- **routers:** Handling of server requests. As it uses other Gitea packages to serve the request, other packages (models, modules or services) shall not depend on routers
176+
- **services:** Support functions for common routing operations. Uses models and modules to handle the request.
177+
- **templates:** Golang templates for generating the html output.
178+
- **vendor:** External code that Gitea depends on.
179+
180+
160181
## Developer Certificate of Origin (DCO)
161182

162183
We consider the act of contributing to the code by submitting a Pull
@@ -283,7 +304,7 @@ be reviewed by two maintainers and must pass the automatic tests.
283304
* Add a tag as `git tag -s -F release.notes v$vmaj.$vmin.$`, release.notes file could be a temporary file to only include the changelog this version which you added to `CHANGELOG.md`.
284305
* And then push the tag as `git push origin v$vmaj.$vmin.$`. Drone CI will automatically created a release and upload all the compiled binary. (But currently it didn't add the release notes automatically. Maybe we should fix that.)
285306
* If needed send PR for changelog on branch `master`.
286-
* Send PR to [blog repository](https://github.com/go-gitea/blog) announcing the release.
307+
* Send PR to [blog repository](https://gitea.com/gitea/blog) announcing the release.
287308

288309
## Copyright
289310

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[简体中文](https://github.com/go-gitea/gitea/blob/master/README_ZH.md)
22

3-
# Gitea - Git with a cup of tea
3+
<h1> <img src="https://raw.githubusercontent.com/go-gitea/gitea/master/public/img/gitea-192.png" alt="logo" width="30" height="30"> Gitea - Git with a cup of tea</h1>
44

55
[![Build Status](https://drone.gitea.io/api/badges/go-gitea/gitea/status.svg)](https://drone.gitea.io/go-gitea/gitea)
66
[![Join the Discord chat at https://discord.gg/NsatcWJ](https://img.shields.io/discord/322538954119184384.svg)](https://discord.gg/NsatcWJ)

cmd/hook.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func runHookPreReceive(c *cli.Context) error {
6666
reponame := os.Getenv(models.EnvRepoName)
6767
userID, _ := strconv.ParseInt(os.Getenv(models.EnvPusherID), 10, 64)
6868
prID, _ := strconv.ParseInt(os.Getenv(models.ProtectedBranchPRID), 10, 64)
69+
isDeployKey, _ := strconv.ParseBool(os.Getenv(models.EnvIsDeployKey))
6970

7071
buf := bytes.NewBuffer(nil)
7172
scanner := bufio.NewScanner(os.Stdin)
@@ -98,6 +99,7 @@ func runHookPreReceive(c *cli.Context) error {
9899
GitObjectDirectory: os.Getenv(private.GitObjectDirectory),
99100
GitQuarantinePath: os.Getenv(private.GitQuarantinePath),
100101
ProtectedBranchID: prID,
102+
IsDeployKey: isDeployKey,
101103
})
102104
switch statusCode {
103105
case http.StatusInternalServerError:

cmd/serv.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ func runServ(c *cli.Context) error {
191191
os.Setenv(models.EnvPusherID, strconv.FormatInt(results.UserID, 10))
192192
os.Setenv(models.ProtectedBranchRepoID, strconv.FormatInt(results.RepoID, 10))
193193
os.Setenv(models.ProtectedBranchPRID, fmt.Sprintf("%d", 0))
194+
os.Setenv(models.EnvIsDeployKey, fmt.Sprintf("%t", results.IsDeployKey))
195+
os.Setenv(models.EnvKeyID, fmt.Sprintf("%d", results.KeyID))
194196

195197
//LFS token authentication
196198
if verb == lfsAuthenticateVerb {

cmd/web.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"os"
1414
"strings"
1515

16+
"code.gitea.io/gitea/modules/graceful"
1617
"code.gitea.io/gitea/modules/log"
1718
"code.gitea.io/gitea/modules/setting"
1819
"code.gitea.io/gitea/routers"
@@ -226,6 +227,7 @@ func runWeb(ctx *cli.Context) error {
226227
log.Critical("Failed to start server: %v", err)
227228
}
228229
log.Info("HTTP Listener: %s Closed", listenAddr)
230+
graceful.WaitForServers()
229231
log.Close()
230232
return nil
231233
}

custom/conf/app.ini.sample

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ FILE_EXTENSIONS = .md,.markdown,.mdown,.mkd
185185
PROTOCOL = http
186186
DOMAIN = localhost
187187
ROOT_URL = %(PROTOCOL)s://%(DOMAIN)s:%(HTTP_PORT)s/
188+
; when STATIC_URL_PREFIX is empty it will follow APP_URL
189+
STATIC_URL_PREFIX =
188190
; The address to listen on. Either a IPv4/IPv6 address or the path to a unix socket.
189191
HTTP_ADDR = 0.0.0.0
190192
HTTP_PORT = 3000
@@ -317,10 +319,12 @@ LOG_SQL = true
317319
DB_RETRIES = 10
318320
; Backoff time per DB retry (time.Duration)
319321
DB_RETRY_BACKOFF = 3s
320-
; Max idle database connections on connnection pool, default is 0
321-
MAX_IDLE_CONNS = 0
322-
; Database connection max life time, default is 3s
322+
; Max idle database connections on connnection pool, default is 2
323+
MAX_IDLE_CONNS = 2
324+
; Database connection max life time, default is 0 or 3s mysql (See #6804 & #7071 for reasoning)
323325
CONN_MAX_LIFETIME = 3s
326+
; Database maximum number of open connections, default is 0 meaning no maximum
327+
MAX_OPEN_CONNS = 0
324328

325329
[indexer]
326330
; Issue indexer type, currently support: bleve or db, default is bleve
@@ -436,6 +440,10 @@ ALLOW_ONLY_EXTERNAL_REGISTRATION = false
436440
REQUIRE_SIGNIN_VIEW = false
437441
; Mail notification
438442
ENABLE_NOTIFY_MAIL = false
443+
; This setting enables gitea to be signed in with HTTP BASIC Authentication using the user's password
444+
; If you set this to false you will not be able to access the tokens endpoints on the API with your password
445+
; Please note that setting this to false will not disable OAuth Basic or Basic authentication using a token
446+
ENABLE_BASIC_AUTHENTICATION = true
439447
; More detail: https://github.com/gogits/gogs/issues/165
440448
ENABLE_REVERSE_PROXY_AUTHENTICATION = false
441449
ENABLE_REVERSE_PROXY_AUTO_REGISTRATION = false
@@ -868,6 +876,6 @@ TOKEN =
868876
QUEUE_TYPE = channel
869877
; Task queue length, available only when `QUEUE_TYPE` is `channel`.
870878
QUEUE_LENGTH = 1000
871-
; Task queue connction string, available only when `QUEUE_TYPE` is `redis`.
879+
; Task queue connection string, available only when `QUEUE_TYPE` is `redis`.
872880
; If there is a password of redis, use `addrs=127.0.0.1:6379 password=123 db=0`.
873881
QUEUE_CONN_STR = "addrs=127.0.0.1:6379 db=0"

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
138138
- `ROOT_URL`: **%(PROTOCOL)s://%(DOMAIN)s:%(HTTP\_PORT)s/**:
139139
Overwrite the automatically generated public URL.
140140
This is useful if the internal and the external URL don't match (e.g. in Docker).
141+
- `STATIC_URL_PREFIX`: **\<empty\>**:
142+
Overwrite this option to request static resources from a different URL.
143+
This includes CSS files, images, JS files and web fonts.
144+
Avatar images are dynamic resources and still served by gitea.
145+
The option can be just a different path, as in `/static`, or another domain, as in `https://cdn.example.com`.
146+
Requests are then made as `%(ROOT_URL)s/static/css/index.css` and `https://cdn.example.com/css/index.css` respective.
147+
The static files are located in the `public/` directory of the gitea source repository.
141148
- `HTTP_ADDR`: **0.0.0.0**: HTTP listen address.
142149
- If `PROTOCOL` is set to `fcgi`, Gitea will listen for FastCGI requests on TCP socket
143150
defined by `HTTP_ADDR` and `HTTP_PORT` configuration settings.
@@ -192,8 +199,12 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
192199
- `LOG_SQL`: **true**: Log the executed SQL.
193200
- `DB_RETRIES`: **10**: How many ORM init / DB connect attempts allowed.
194201
- `DB_RETRY_BACKOFF`: **3s**: time.Duration to wait before trying another ORM init / DB connect attempt, if failure occured.
195-
- `MAX_IDLE_CONNS` **0**: Max idle database connections on connnection pool, default is 0
196-
- `CONN_MAX_LIFETIME` **3s**: Database connection max lifetime
202+
- `MAX_OPEN_CONNS` **0**: Database maximum open connections - default is 0, meaning there is no limit.
203+
- `MAX_IDLE_CONNS` **2**: Max idle database connections on connnection pool, default is 2 - this will be capped to `MAX_OPEN_CONNS`.
204+
- `CONN_MAX_LIFETIME` **0 or 3s**: Sets the maximum amount of time a DB connection may be reused - default is 0, meaning there is no limit (except on MySQL where it is 3s - see #6804 & #7071).
205+
206+
Please see #8540 & #8273 for further discussion of the appropriate values for `MAX_OPEN_CONNS`, `MAX_IDLE_CONNS` & `CONN_MAX_LIFETIME` and their
207+
relation to port exhaustion.
197208

198209
## Indexer (`indexer`)
199210

@@ -265,6 +276,10 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
265276
- `REQUIRE_SIGNIN_VIEW`: **false**: Enable this to force users to log in to view any page.
266277
- `ENABLE_NOTIFY_MAIL`: **false**: Enable this to send e-mail to watchers of a repository when
267278
something happens, like creating issues. Requires `Mailer` to be enabled.
279+
- `ENABLE_BASIC_AUTHENTICATION`: **true**: Disable this to disallow authenticaton using HTTP
280+
BASIC and the user's password. Please note if you disable this you will not be able to access the
281+
tokens API endpoints using a password. Further, this only disables BASIC authentication using the
282+
password - not tokens or OAuth Basic.
268283
- `ENABLE_REVERSE_PROXY_AUTHENTICATION`: **false**: Enable this to allow reverse proxy authentication.
269284
- `ENABLE_REVERSE_PROXY_AUTO_REGISTRATION`: **false**: Enable this to allow auto-registration
270285
for reverse authentication.

docs/content/doc/advanced/external-renderers.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ add one `[markup.XXXXX]` section per external renderer on your custom `app.ini`:
5151
[markup.asciidoc]
5252
ENABLED = true
5353
FILE_EXTENSIONS = .adoc,.asciidoc
54-
RENDER_COMMAND = "asciidoctor --out-file=- -"
54+
RENDER_COMMAND = "asciidoctor -e -a leveloffset=-1 --out-file=- -"
5555
; Input is not a standard input but a file
5656
IS_INPUT_FILE = false
5757

docs/content/doc/installation/from-source.en-us.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ launched manually from command line, it can be killed by pressing `Ctrl + C`.
118118
./gitea web
119119
```
120120

121-
## Changing the default CustomPath, CustomConf and AppWorkDir
121+
## Changing the default CustomPath, CustomConf and AppWorkPath
122122

123123
Gitea will search for a number of things from the `CustomPath`. By default this is
124124
the `custom/` directory in the current working directory when running Gitea. It will also
125125
look for its configuration file `CustomConf` in `$CustomPath/conf/app.ini`, and will use the
126-
current working directory as the relative base path `AppWorkDir` for a number configurable
126+
current working directory as the relative base path `AppWorkPath` for a number configurable
127127
values.
128128

129129
These values, although useful when developing, may conflict with downstream users preferences.
@@ -134,7 +134,7 @@ using the `LDFLAGS` environment variable for `make`. The appropriate settings ar
134134

135135
* To set the `CustomPath` use `LDFLAGS="-X \"code.gitea.io/gitea/modules/setting.CustomPath=custom-path\""`
136136
* For `CustomConf` you should use `-X \"code.gitea.io/gitea/modules/setting.CustomConf=conf.ini\"`
137-
* For `AppWorkDir` you should use `-X \"code.gitea.io/gitea/modules/setting.AppWorkDir=working-directory\"`
137+
* For `AppWorkPath` you should use `-X \"code.gitea.io/gitea/modules/setting.AppWorkPath=working-path\"`
138138

139139
Add as many of the strings with their preceding `-X` to the `LDFLAGS` variable and run `make build`
140140
with the appropriate `TAGS` as above.

docs/content/doc/usage/fail2ban-setup.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ on a bad authentication:
2626
2018/04/26 18:15:54 [I] Failed authentication attempt for user from xxx.xxx.xxx.xxx
2727
```
2828

29-
So we set our filter in `/etc/fail2ban/filter.d/gitea.conf`:
29+
Add our filter in `/etc/fail2ban/filter.d/gitea.conf`:
3030

3131
```ini
3232
# gitea.conf
@@ -35,12 +35,11 @@ failregex = .*Failed authentication attempt for .* from <HOST>
3535
ignoreregex =
3636
```
3737

38-
And configure it in `/etc/fail2ban/jail.d/jail.local`:
38+
Add our jail in `/etc/fail2ban/jail.d/gitea.conf`:
3939

4040
```ini
4141
[gitea]
4242
enabled = true
43-
port = http,https
4443
filter = gitea
4544
logpath = /home/git/gitea/log/gitea.log
4645
maxretry = 10
@@ -49,6 +48,23 @@ bantime = 900
4948
action = iptables-allports
5049
```
5150

51+
If you're using Docker, you'll also need to add an additional jail to handle the **FORWARD**
52+
chain in **iptables**. Configure it in `/etc/fail2ban/jail.d/gitea-docker.conf`:
53+
54+
```ini
55+
[gitea-docker]
56+
enabled = true
57+
filter = gitea
58+
logpath = /home/git/gitea/log/gitea.log
59+
maxretry = 10
60+
findtime = 3600
61+
bantime = 900
62+
action = iptables-allports[chain="FORWARD"]
63+
```
64+
65+
Then simply run `service fail2ban restart` to apply your changes. You can check to see if
66+
fail2ban has accepted your configuration using `service fail2ban status`.
67+
5268
Make sure and read up on fail2ban and configure it to your needs, this bans someone
5369
for **15 minutes** (from all ports) when they fail authentication 10 times in an hour.
5470

0 commit comments

Comments
 (0)