Skip to content

Commit 8b10327

Browse files
author
Vladimir Kotal
authored
Merge pull request #3463 from vladak/docker_project_less
Docker project less
2 parents 7ee480e + 3a6a7f3 commit 8b10327

File tree

3 files changed

+89
-38
lines changed

3 files changed

+89
-38
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` | empty | 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: 77 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@
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):
6667
"""
6768
Set URL root and URI based on input
69+
:param logger: logger instance
6870
:param url_root: input
6971
:return: URI and URL root
7072
"""
@@ -108,6 +110,7 @@ def get_war_name(url_root):
108110
def deploy(logger, url_root):
109111
"""
110112
Deploy the web application
113+
:param logger: logger instance
111114
:param url_root: web app URL root
112115
"""
113116

@@ -190,6 +193,7 @@ def refresh_projects(logger, uri):
190193
def save_config(logger, uri, config_path):
191194
"""
192195
Retrieve configuration from the web app and write it to file.
196+
:param logger: logger instance
193197
:param uri: web app URI
194198
:param config_path: file path
195199
"""
@@ -218,7 +222,37 @@ def merge_commands_env(commands, env):
218222
return commands
219223

220224

221-
def syncer(logger, loglevel, uri, config_path, sync_period, numworkers, env):
225+
def indexer_no_projects(logger, uri, config_path, sync_period,
226+
extra_indexer_options):
227+
"""
228+
Project less indexer
229+
"""
230+
231+
wait_for_tomcat(logger, uri)
232+
233+
while True:
234+
indexer_options = ['-s', OPENGROK_SRC_ROOT,
235+
'-d', OPENGROK_DATA_ROOT,
236+
'-c', '/usr/local/bin/ctags',
237+
'--remote', 'on',
238+
'-H',
239+
'-W', config_path,
240+
'-U', uri]
241+
if extra_indexer_options:
242+
logger.debug("Adding extra indexer options: {}".
243+
format(extra_indexer_options))
244+
indexer_options.extend(extra_indexer_options.split())
245+
indexer = Indexer(indexer_options, logger=logger,
246+
jar=OPENGROK_JAR, doprint=True)
247+
indexer.execute()
248+
249+
sleep_seconds = sync_period * 60
250+
logger.info("Sleeping for {} seconds".format(sleep_seconds))
251+
time.sleep(sleep_seconds)
252+
253+
254+
def project_syncer(logger, loglevel, uri, config_path, sync_period,
255+
numworkers, env):
222256
"""
223257
Wrapper for running opengrok-sync.
224258
To be run in a thread/process in the background.
@@ -267,22 +301,25 @@ def syncer(logger, loglevel, uri, config_path, sync_period, numworkers, env):
267301
time.sleep(sleep_seconds)
268302

269303

270-
def create_bare_config(logger):
304+
def create_bare_config(logger, use_projects=True):
271305
"""
272306
Create bare configuration file with a few basic settings.
273307
"""
274308

275309
logger.info('Creating bare configuration in {}'.
276310
format(OPENGROK_CONFIG_FILE))
277-
indexer = Indexer(['-s', OPENGROK_SRC_ROOT,
311+
indexer_options = ['-s', OPENGROK_SRC_ROOT,
278312
'-d', OPENGROK_DATA_ROOT,
279313
'-c', '/usr/local/bin/ctags',
280314
'--remote', 'on',
281-
'-P', '-H',
315+
'-H',
282316
'-W', OPENGROK_CONFIG_FILE,
283-
'--noIndex'],
284-
jar=os.path.join(OPENGROK_LIB_DIR,
285-
'opengrok.jar'),
317+
'--noIndex']
318+
if use_projects:
319+
indexer_options.append('-P')
320+
321+
indexer = Indexer(indexer_options,
322+
jar=OPENGROK_JAR,
286323
logger=logger, doprint=True)
287324
indexer.execute()
288325
ret = indexer.getretcode()
@@ -329,39 +366,53 @@ def main():
329366
setup_redirect_source(logger, url_root)
330367

331368
env = {}
332-
if os.environ.get('INDEXER_OPT'):
333-
env['OPENGROK_INDEXER_OPTIONAL_ARGS'] = \
334-
os.environ.get('INDEXER_OPT')
369+
extra_indexer_options = os.environ.get('INDEXER_OPT')
370+
if extra_indexer_options:
371+
logger.info("extra indexer options: {}".format(extra_indexer_options))
372+
env['OPENGROK_INDEXER_OPTIONAL_ARGS'] = extra_indexer_options
335373
if os.environ.get('NOMIRROR'):
336374
env['OPENGROK_NO_MIRROR'] = os.environ.get('NOMIRROR')
337375
logger.debug('Extra environment: {}'.format(env))
338376

377+
use_projects = True
378+
if os.environ.get('AVOID_PROJECTS'):
379+
use_projects = False
380+
339381
#
340382
# Create empty configuration to avoid the non existent file exception
341383
# in the web app during the first web app startup.
342384
#
343385
if not os.path.exists(OPENGROK_CONFIG_FILE) or \
344386
os.path.getsize(OPENGROK_CONFIG_FILE) == 0:
345-
create_bare_config(logger)
387+
create_bare_config(logger, use_projects=use_projects)
346388

347389
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))
390+
if use_projects:
391+
num_workers = multiprocessing.cpu_count()
392+
workers_env = os.environ.get('WORKERS')
393+
if workers_env:
394+
try:
395+
n = int(workers_env)
396+
if n > 0:
397+
num_workers = n
398+
except ValueError:
399+
logger.error("WORKERS is not a number: {}".
400+
format(workers_env))
401+
402+
logger.info('Number of sync workers: {}'.format(num_workers))
403+
404+
worker_function = project_syncer
405+
syncer_args = (logger, log_level, uri,
406+
OPENGROK_CONFIG_FILE,
407+
sync_period, num_workers, env)
408+
else:
409+
worker_function = indexer_no_projects
410+
syncer_args = (logger, uri, OPENGROK_CONFIG_FILE, sync_period,
411+
extra_indexer_options)
359412

360413
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))
414+
thread = threading.Thread(target=worker_function, name="Sync thread",
415+
args=syncer_args)
365416
thread.start()
366417

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

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,13 @@ def main():
9494
help='Set response timeout in seconds for RESTful API calls')
9595

9696
cmd_args = sys.argv[1:]
97-
extra_opts = os.environ.get("OPENGROK_INDEXER_OPTIONAL_ARGS")
98-
if extra_opts:
99-
cmd_args.extend(extra_opts.split())
100-
10197
try:
10298
args = parser.parse_args(cmd_args)
10399
except ValueError as e:
104100
fatal(e)
105101

106102
logger = get_console_logger(get_class_basename(), args.loglevel)
107103

108-
logger.debug('Command arguments extended with {}'.format(extra_opts))
109-
110104
# Make sure the log directory exists.
111105
if args.directory:
112106
if not os.path.isdir(args.directory):
@@ -121,15 +115,19 @@ def main():
121115
args.project)
122116

123117
# Reindex with the modified logging.properties file and read-only config.
124-
command = ['-R', conf_file]
125-
command.extend(args.options)
118+
indexer_options = ['-R', conf_file] + args.options
119+
extra_options = os.environ.get("OPENGROK_INDEXER_OPTIONAL_ARGS")
120+
if extra_options:
121+
logger.debug('indexer arguments extended with {}'.format(extra_options))
122+
# Prepend the extra options because we want the arguments to end with a project.
123+
indexer_options = extra_options.split() + indexer_options
126124
java_opts = []
127125
if args.java_opts:
128126
java_opts.extend(args.java_opts)
129127
if logprop_file:
130128
java_opts.append("-Djava.util.logging.config.file={}".
131129
format(logprop_file))
132-
indexer = Indexer(command, logger=logger, jar=args.jar,
130+
indexer = Indexer(indexer_options, logger=logger, jar=args.jar,
133131
java=args.java, java_opts=java_opts,
134132
env_vars=args.environment, doprint=args.doprint)
135133
indexer.execute()

0 commit comments

Comments
 (0)