Skip to content

check mirror config in Docker #3676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions docker/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
add_project, delete_project, get_configuration
from opengrok_tools.utils.readconfig import read_config
from opengrok_tools.utils.exitvals import SUCCESS_EXITVAL
from opengrok_tools.utils.mirror import check_configuration


fs_root = os.path.abspath('.').split(os.path.sep)[0] + os.path.sep
Expand All @@ -70,6 +71,8 @@
OPENGROK_WEBAPPS_DIR = os.path.join(tomcat_root, "webapps")
OPENGROK_JAR = os.path.join(OPENGROK_LIB_DIR, 'opengrok.jar')

NOMIRROR_ENV_NAME = 'NOMIRROR'

expected_token = None

sleep_event = threading.Event()
Expand Down Expand Up @@ -485,8 +488,8 @@ def main():
if extra_indexer_options:
logger.info("extra indexer options: {}".format(extra_indexer_options))
env['OPENGROK_INDEXER_OPTIONAL_ARGS'] = extra_indexer_options
if os.environ.get('NOMIRROR'):
env['OPENGROK_NO_MIRROR'] = os.environ.get('NOMIRROR')
if os.environ.get(NOMIRROR_ENV_NAME):
env['OPENGROK_NO_MIRROR'] = os.environ.get(NOMIRROR_ENV_NAME)
logger.debug('Extra environment: {}'.format(env))

use_projects = True
Expand Down Expand Up @@ -531,15 +534,25 @@ def main():
if out_file:
os.remove(out_file)

sync_enabled = True
if use_projects:
num_workers = get_num_from_env(logger, 'WORKERS',
multiprocessing.cpu_count())
logger.info('Number of sync workers: {}'.format(num_workers))

mirror_config = os.path.join(OPENGROK_CONFIG_DIR, "mirror.yml")
if not os.path.exists(mirror_config):
with open(mirror_config, 'w') as fp:
fp.write("# Empty config file for opengrok-mirror\n")
if not os.environ.get(NOMIRROR_ENV_NAME):
mirror_config = os.path.join(OPENGROK_CONFIG_DIR, "mirror.yml")
if not os.path.exists(mirror_config):
with open(mirror_config, 'w') as fp:
fp.write("# Empty config file for opengrok-mirror\n")
else:
conf = read_config(logger, mirror_config)
logger.info("Checking mirror configuration in '{}'".
format(mirror_config))
if not check_configuration(conf):
logger.error("Mirror configuration in '{}' is invalid, "
"disabling sync".format(mirror_config))
sync_enabled = False

worker_function = project_syncer
syncer_args = (logger, log_level, uri,
Expand All @@ -550,14 +563,16 @@ def main():
syncer_args = (logger, uri, OPENGROK_CONFIG_FILE,
extra_indexer_options)

logger.debug("Starting sync thread")
sync_thread = threading.Thread(target=worker_function, name="Sync thread",
args=syncer_args, daemon=True)
sync_thread.start()
if sync_enabled:
logger.debug("Starting sync thread")
sync_thread = threading.Thread(target=worker_function,
name="Sync thread",
args=syncer_args, daemon=True)
sync_thread.start()

start_rest_thread(logger)
if sync_period > 0:
start_timeout_thread(logger, sync_period)
start_rest_thread(logger)
if sync_period > 0:
start_timeout_thread(logger, sync_period)

# Start Tomcat last. It will be the foreground process.
logger.info("Starting Tomcat")
Expand Down
29 changes: 18 additions & 11 deletions tools/src/main/python/opengrok_tools/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def main():
help='mirror all indexed projects', default=False)
parser.add_argument('-c', '--config',
help='config file in JSON/YAML format')
parser.add_argument('--check_config', action='store_true',
help='check configuration and exit')
parser.add_argument('-U', '--uri', default='http://localhost:8080/source',
help='uri of the webapp with context path')
parser.add_argument('-b', '--batch', action='store_true',
Expand All @@ -116,7 +118,21 @@ def main():

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

headers = get_headers(args.header)
if args.config:
config = read_config(logger, args.config)
if config is None:
return fatal("Cannot read config file from {}".
format(args.config), False)
else:
config = {}

if not check_configuration(config):
logger.error("Configuration check failed, exiting")
return 1

if args.check_config:
logger.debug("Configuration check passed, exiting")
return 0

nomirror = os.environ.get("OPENGROK_NO_MIRROR")
if nomirror and len(nomirror) > 0:
Expand All @@ -130,21 +146,12 @@ def main():
if not args.all and len(args.project) == 0:
return fatal("Need at least one project or --all", False)

if args.config:
config = read_config(logger, args.config)
if config is None:
return fatal("Cannot read config file from {}".
format(args.config), False)
else:
config = {}

uri = args.uri
if not is_web_uri(uri):
return fatal("Not a URI: {}".format(uri), False)
logger.debug("web application URI = {}".format(uri))

if not check_configuration(config):
return 1
headers = get_headers(args.header)

# Save the source root to avoid querying the web application.
source_root = get_config_value(logger, 'sourceRoot', uri,
Expand Down