Skip to content

Commit 941332a

Browse files
Vladimir Kotalahornace
authored andcommitted
introduce check_incoming configuration property
allow to specify mirror configuration in Docker
1 parent 53caaf2 commit 941332a

File tree

5 files changed

+61
-18
lines changed

5 files changed

+61
-18
lines changed

docker/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ The container exports ports 8080 for OpenGrok.
7171

7272
The volume mounted to `/opengrok/src` should contain the projects you want to make searchable (in sub directories). You can use common revision control checkouts (git, svn, etc...) and OpenGrok will make history and blame information available.
7373

74+
## Directories
75+
76+
The image contains these directories:
77+
78+
| Directory | Description |
79+
| --------- | ----------- |
80+
`/opengrok/etc` | stores the configuration for both web app and indexer
81+
`/opengrok/data` | data root - index data
82+
`/opengrok/src` | source root - input data
83+
`/scripts` | startup script and top level configuration. Do not override unless debugging.
84+
7485
## Environment Variables
7586

7687
| Docker Environment Var. | Default value | Description |
@@ -80,7 +91,7 @@ The volume mounted to `/opengrok/src` should contain the projects you want to ma
8091
`NOMIRROR` | empty | To avoid the mirroring step, set the variable to non-empty value.
8192
`URL_ROOT` | `/` | Override the sub-URL that OpenGrok should run on.
8293
`WORKERS` | number of CPUs in the container | number of workers to use for syncing (applies only to setup with projects enabled)
83-
`AVOID_PROJECTS` | empty | run in project less configuration. Set to non empty value disables projects.
94+
`AVOID_PROJECTS` | empty | run in project less configuration. Set to non empty value disables projects. Also disables repository synchronization.
8495
`REST_PORT` | 5000 | TCP port where simple REST app listens for GET requests on `/reindex` to trigger manual reindex.
8596
`REST_TOKEN` | None | if set, the REST app will require this token as Bearer token in order to trigger reindex.
8697
`READONLY_CONFIG_FILE` | None | if set, the configuration will be merged with configuration from this file. This is run when the container starts.

docker/start.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
OPENGROK_DATA_ROOT = os.path.join(OPENGROK_BASE_DIR, "data")
6565
OPENGROK_SRC_ROOT = os.path.join(OPENGROK_BASE_DIR, "src")
6666
BODY_INCLUDE_FILE = os.path.join(OPENGROK_DATA_ROOT, "body_include")
67-
OPENGROK_CONFIG_FILE = os.path.join(OPENGROK_BASE_DIR, "etc",
67+
OPENGROK_CONFIG_DIR = os.path.join(OPENGROK_BASE_DIR, "etc")
68+
OPENGROK_CONFIG_FILE = os.path.join(OPENGROK_CONFIG_DIR,
6869
"configuration.xml")
6970
OPENGROK_WEBAPPS_DIR = os.path.join(tomcat_root, "webapps")
7071
OPENGROK_JAR = os.path.join(OPENGROK_LIB_DIR, 'opengrok.jar')
@@ -532,6 +533,11 @@ def main():
532533
multiprocessing.cpu_count())
533534
logger.info('Number of sync workers: {}'.format(num_workers))
534535

536+
mirror_config = os.path.join(OPENGROK_CONFIG_DIR, "mirror.yml")
537+
if not os.path.exists(mirror_config):
538+
with open(mirror_config, 'w') as fp:
539+
pass
540+
535541
worker_function = project_syncer
536542
syncer_args = (logger, log_level, uri,
537543
OPENGROK_CONFIG_FILE,

docker/sync.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ commands:
66
duration: PT1H
77
tags: ['%PROJECT%']
88
text: resync + reindex in progress
9-
- command: [opengrok-mirror, -I, -U, '%URL%', '%PROJECT%']
9+
- command: [opengrok-mirror, -c, '/opengrok/etc/mirror.yml', -I, -U, '%URL%', '%PROJECT%']
1010
- command: [opengrok-reindex-project, --printoutput,
1111
--jar, /opengrok/lib/opengrok.jar, -U, '%URL%', -P, '%PROJECT%', --,
1212
-r, dirbased, -G, -m, '256', --leadingWildCards, 'on',

tools/src/main/python/opengrok_tools/utils/mirror.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
SUCCESS_EXITVAL
3737
)
3838
from .patterns import PROJECT_SUBST, COMMAND_PROPERTY
39-
from .utils import is_exe, check_create_dir, get_int, is_web_uri
39+
from .utils import is_exe, check_create_dir, get_int, is_web_uri, get_bool
4040
from .opengrok import get_repos, get_repo_type, get_uri
4141
from .hook import run_hook
4242
from .command import Command
@@ -51,6 +51,7 @@
5151
CMD_TIMEOUT_PROPERTY = 'command_timeout'
5252
IGNORED_REPOS_PROPERTY = 'ignored_repos'
5353
PROXY_PROPERTY = 'proxy'
54+
INCOMING_PROPERTY = 'incoming_check'
5455
COMMANDS_PROPERTY = 'commands'
5556
DISABLED_PROPERTY = 'disabled'
5657
DISABLED_REASON_PROPERTY = 'disabled-reason'
@@ -158,7 +159,7 @@ def get_project_properties(project_config, project_name, hookdir):
158159
:param project_name: name of the project
159160
:param hookdir: directory with hooks
160161
:return: list of properties: prehook, posthook, hook_timeout,
161-
command_timeout, use_proxy, ignored_repos
162+
command_timeout, use_proxy, ignored_repos, check_changes
162163
"""
163164

164165
prehook = None
@@ -167,6 +168,7 @@ def get_project_properties(project_config, project_name, hookdir):
167168
command_timeout = None
168169
use_proxy = False
169170
ignored_repos = None
171+
check_changes = None
170172

171173
logger = logging.getLogger(__name__)
172174

@@ -213,11 +215,17 @@ def get_project_properties(project_config, project_name, hookdir):
213215
logger.debug("will use proxy")
214216
use_proxy = True
215217

218+
if project_config.get(INCOMING_PROPERTY):
219+
check_changes = get_bool(logger, ("incoming check for project {}".
220+
format(project_name)),
221+
project_config.get(INCOMING_PROPERTY))
222+
logger.debug("incoming check = {}".format(check_changes))
223+
216224
if not ignored_repos:
217225
ignored_repos = []
218226

219227
return prehook, posthook, hook_timeout, command_timeout, \
220-
use_proxy, ignored_repos
228+
use_proxy, ignored_repos, check_changes
221229

222230

223231
def process_hook(hook_ident, hook, source_root, project_name, proxy,
@@ -361,7 +369,7 @@ def mirror_project(config, project_name, check_changes, uri,
361369
:param uri
362370
:param source_root
363371
:param headers: optional dictionary of HTTP headers
364-
:param timeout: optional timeount in seconds for API call response
372+
:param timeout: optional timeout in seconds for API call response
365373
:return exit code
366374
"""
367375

@@ -371,7 +379,8 @@ def mirror_project(config, project_name, check_changes, uri,
371379

372380
project_config = get_project_config(config, project_name)
373381
prehook, posthook, hook_timeout, command_timeout, use_proxy, \
374-
ignored_repos = get_project_properties(project_config,
382+
ignored_repos, \
383+
check_changes_proj = get_project_properties(project_config,
375384
project_name,
376385
config.get(HOOKDIR_PROPERTY))
377386

@@ -385,16 +394,15 @@ def mirror_project(config, project_name, check_changes, uri,
385394
proxy = config.get(PROXY_PROPERTY)
386395

387396
# We want this to be logged to the log file (if any).
388-
if project_config:
389-
if project_config.get(DISABLED_PROPERTY):
390-
handle_disabled_project(config, project_name,
391-
project_config.
392-
get(DISABLED_REASON_PROPERTY),
393-
headers=headers,
394-
timeout=timeout)
395-
logger.info("Project '{}' disabled, exiting".
396-
format(project_name))
397-
return CONTINUE_EXITVAL
397+
if project_config and project_config.get(DISABLED_PROPERTY):
398+
handle_disabled_project(config, project_name,
399+
project_config.
400+
get(DISABLED_REASON_PROPERTY),
401+
headers=headers,
402+
timeout=timeout)
403+
logger.info("Project '{}' disabled, exiting".
404+
format(project_name))
405+
return CONTINUE_EXITVAL
398406

399407
#
400408
# Cache the repositories first. This way it will be known that
@@ -415,6 +423,9 @@ def mirror_project(config, project_name, check_changes, uri,
415423
format(project_name))
416424
return CONTINUE_EXITVAL
417425

426+
if check_changes_proj is not None:
427+
check_changes = check_changes_proj
428+
418429
# Check if the project or any of its repositories have changed.
419430
if check_changes:
420431
r = process_changes(repos, project_name, uri, headers=headers)

tools/src/main/python/opengrok_tools/utils/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import logging
2828
import sys
2929
from urllib.parse import urlparse
30+
from distutils import util
3031
from .exitvals import (
3132
FAILURE_EXITVAL,
3233
)
@@ -97,6 +98,20 @@ def get_int(logger, name, value):
9798
return None
9899

99100

101+
def get_bool(logger, name, value):
102+
"""
103+
If the supplied value is bool, return it. Otherwise return None.
104+
"""
105+
if value is None:
106+
return None
107+
108+
try:
109+
return bool(util.strtobool(value))
110+
except ValueError:
111+
logger.error("'{}' is not a number: {}".format(name, value))
112+
return None
113+
114+
100115
def is_web_uri(url):
101116
"""
102117
Check if given string is web URL.

0 commit comments

Comments
 (0)