Skip to content

Commit 4810eb9

Browse files
author
Vladimir Kotal
committed
reintroduce project less config
fixes #3461
1 parent 599e8b3 commit 4810eb9

File tree

2 files changed

+85
-29
lines changed

2 files changed

+85
-29
lines changed

docker/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ The mirroring step works by going through all projects and attempting to
3636
synchronize all its repositories (e.g. it will do `git pull --ff-only` for Git
3737
repositories).
3838

39-
Projects are enabled in this setup and there is no way how to change that.
39+
Projects are enabled in this setup by default. See environment variables
40+
below on how to change that.
4041

4142
### Indexer logs
4243

@@ -52,7 +53,7 @@ is doing, use the `docker logs` command.
5253

5354
### Tags and versioning
5455

55-
Each OpenGrok release triggers creation of new Docker image.
56+
Each OpenGrok release triggers creation of new Docker image.
5657

5758
| Tag | Note |
5859
| -------- |:--------------------------------------------------------|
@@ -78,7 +79,8 @@ The volume mounted to `/opengrok/src` should contain the projects you want to ma
7879
`INDEXER_OPT` | empty | pass **extra** options to OpenGrok Indexer. The default set of indexer options is: `--remote on -P -H -W`. For example, `-i d:vendor` will remove all the `*/vendor/*` files from the index. You can check the indexer options on https://github.com/oracle/opengrok/wiki/Python-scripts-transition-guide
7980
`NOMIRROR` | empty | To avoid the mirroring step, set the variable to non-empty value.
8081
`URL_ROOT` | `/` | Override the sub-URL that OpenGrok should run on.
81-
`WORKERS` | number of CPUs in the container | number of workers to use for syncing
82+
`WORKERS` | number of CPUs in the container | number of workers to use for syncing (applies only to setup with projects enabled)
83+
`AVOID_PROJECTS` | False | run in project less configuration. Set to non empty value disables projects.
8284

8385
To specify environment variable for `docker run`, use the `-e` option, e.g. `-e SYNC_PERIOD_MINUTES=30`
8486

docker/start.py

Lines changed: 80 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
OPENGROK_CONFIG_FILE = os.path.join(OPENGROK_BASE_DIR, "etc",
6161
"configuration.xml")
6262
OPENGROK_WEBAPPS_DIR = os.path.join(tomcat_root, "webapps")
63+
OPENGROK_JAR = os.path.join(OPENGROK_LIB_DIR, 'opengrok.jar')
6364

6465

6566
def set_url_root(logger, url_root):
@@ -218,7 +219,43 @@ def merge_commands_env(commands, env):
218219
return commands
219220

220221

221-
def syncer(logger, loglevel, uri, config_path, sync_period, numworkers, env):
222+
def indexer_no_projects(logger, uri, config_path, sync_period,
223+
extra_indexer_options):
224+
"""
225+
Project less indexer
226+
"""
227+
228+
wait_for_tomcat(logger, uri)
229+
230+
while True:
231+
indexer_options = ['-s', OPENGROK_SRC_ROOT,
232+
'-d', OPENGROK_DATA_ROOT,
233+
'-c', '/usr/local/bin/ctags',
234+
'--remote', 'on',
235+
'-H',
236+
'-W', config_path,
237+
'-U', uri]
238+
if extra_indexer_options:
239+
logger.debug("Adding extra indexer options: {}".
240+
format(extra_indexer_options))
241+
indexer_options.extend(extra_indexer_options.split())
242+
indexer = Indexer(indexer_options, logger=logger,
243+
jar=OPENGROK_JAR)
244+
indexer.execute()
245+
ret = indexer.getretcode()
246+
if ret is None or ret != SUCCESS_EXITVAL:
247+
logger.error('Command returned {}'.format(ret))
248+
logger.error(indexer.geterroutputstr())
249+
else:
250+
logger.info(indexer.getoutputstr())
251+
252+
sleep_seconds = sync_period * 60
253+
logger.info("Sleeping for {} seconds".format(sleep_seconds))
254+
time.sleep(sleep_seconds)
255+
256+
257+
def project_syncer(logger, loglevel, uri, config_path, sync_period,
258+
numworkers, env):
222259
"""
223260
Wrapper for running opengrok-sync.
224261
To be run in a thread/process in the background.
@@ -267,22 +304,25 @@ def syncer(logger, loglevel, uri, config_path, sync_period, numworkers, env):
267304
time.sleep(sleep_seconds)
268305

269306

270-
def create_bare_config(logger):
307+
def create_bare_config(logger, use_projects=True):
271308
"""
272309
Create bare configuration file with a few basic settings.
273310
"""
274311

275312
logger.info('Creating bare configuration in {}'.
276313
format(OPENGROK_CONFIG_FILE))
277-
indexer = Indexer(['-s', OPENGROK_SRC_ROOT,
314+
indexer_options = ['-s', OPENGROK_SRC_ROOT,
278315
'-d', OPENGROK_DATA_ROOT,
279316
'-c', '/usr/local/bin/ctags',
280317
'--remote', 'on',
281-
'-P', '-H',
318+
'-H',
282319
'-W', OPENGROK_CONFIG_FILE,
283-
'--noIndex'],
284-
jar=os.path.join(OPENGROK_LIB_DIR,
285-
'opengrok.jar'),
320+
'--noIndex']
321+
if use_projects:
322+
indexer_options.append('-P')
323+
324+
indexer = Indexer(indexer_options,
325+
jar=OPENGROK_JAR,
286326
logger=logger, doprint=True)
287327
indexer.execute()
288328
ret = indexer.getretcode()
@@ -329,39 +369,53 @@ def main():
329369
setup_redirect_source(logger, url_root)
330370

331371
env = {}
332-
if os.environ.get('INDEXER_OPT'):
333-
env['OPENGROK_INDEXER_OPTIONAL_ARGS'] = \
334-
os.environ.get('INDEXER_OPT')
372+
extra_indexer_options = os.environ.get('INDEXER_OPT')
373+
if extra_indexer_options:
374+
logger.info("extra indexer options: {}".format(extra_indexer_options))
375+
env['OPENGROK_INDEXER_OPTIONAL_ARGS'] = extra_indexer_options
335376
if os.environ.get('NOMIRROR'):
336377
env['OPENGROK_NO_MIRROR'] = os.environ.get('NOMIRROR')
337378
logger.debug('Extra environment: {}'.format(env))
338379

380+
use_projects = True
381+
if os.environ.get('AVOID_PROJECTS'):
382+
use_projects = False
383+
339384
#
340385
# Create empty configuration to avoid the non existent file exception
341386
# in the web app during the first web app startup.
342387
#
343388
if not os.path.exists(OPENGROK_CONFIG_FILE) or \
344389
os.path.getsize(OPENGROK_CONFIG_FILE) == 0:
345-
create_bare_config(logger)
390+
create_bare_config(logger, use_projects=use_projects)
346391

347392
if sync_period > 0:
348-
num_workers = multiprocessing.cpu_count()
349-
workers_env = os.environ.get('WORKERS')
350-
if workers_env:
351-
try:
352-
n = int(workers_env)
353-
if n > 0:
354-
num_workers = n
355-
except ValueError:
356-
logger.error("WORKERS is not a number: {}".format(workers_env))
357-
358-
logger.info('Number of sync workers: {}'.format(num_workers))
393+
if use_projects:
394+
num_workers = multiprocessing.cpu_count()
395+
workers_env = os.environ.get('WORKERS')
396+
if workers_env:
397+
try:
398+
n = int(workers_env)
399+
if n > 0:
400+
num_workers = n
401+
except ValueError:
402+
logger.error("WORKERS is not a number: {}".
403+
format(workers_env))
404+
405+
logger.info('Number of sync workers: {}'.format(num_workers))
406+
407+
worker_function = project_syncer
408+
syncer_args = (logger, log_level, uri,
409+
OPENGROK_CONFIG_FILE,
410+
sync_period, num_workers, env)
411+
else:
412+
worker_function = indexer_no_projects
413+
syncer_args = (logger, uri, OPENGROK_CONFIG_FILE, sync_period,
414+
extra_indexer_options)
359415

360416
logger.debug("Starting sync thread")
361-
thread = threading.Thread(target=syncer, name="Sync thread",
362-
args=(logger, log_level, uri,
363-
OPENGROK_CONFIG_FILE,
364-
sync_period, num_workers, env))
417+
thread = threading.Thread(target=worker_function, name="Sync thread",
418+
args=syncer_args)
365419
thread.start()
366420

367421
# Start Tomcat last. It will be the foreground process.

0 commit comments

Comments
 (0)