├── docker ├── scripts │ ├── ROOT.war │ ├── docker_config.py │ ├── migrate.sh │ ├── deploy.sh │ └── start.py └── Dockerfile ├── versions.txt ├── conf.d └── default.conf ├── README.md ├── docker-compose.yml └── html └── js └── branch.js /docker/scripts/ROOT.war: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aospapp/aospxref/HEAD/docker/scripts/ROOT.war -------------------------------------------------------------------------------- /docker/scripts/docker_config.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | INDEXER_JAVA_OPTS = os.environ.get("INDEXER_JAVA_OPTS") 5 | CHECK_INDEX = os.environ.get("CHECK_INDEX") 6 | OPENGROK_LOG_LEVEL = os.environ.get("OPENGROK_LOG_LEVEL") 7 | READONLY_CONFIG_FILE = os.environ.get("READONLY_CONFIG_FILE") 8 | TEST_MODE = os.environ.get("TEST_MODE") is not None 9 | -------------------------------------------------------------------------------- /versions.txt: -------------------------------------------------------------------------------- 1 | android-5.0.2_r3,21 2 | android-5.1.0_r1,22 3 | android-6.0.0_r1,23 4 | android-7.0.0_r1,24 5 | android-7.1.0_r4,25 6 | android-8.0.0_r4,26 7 | android-8.1.0_r1,27 8 | android-9.0.0_r3,28 9 | android-10.0.0_r2,29 10 | android-11.0.0_r1,30 11 | android-12.0.0_r2,31 12 | android-12.1.0_r1,32 13 | android-13.0.0_r3,33 14 | android-14.0.0_r2,34 15 | android-15.0.0_r3,35 -------------------------------------------------------------------------------- /docker/scripts/migrate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Run in /data/aospapp 4 | 5 | sudo cp -rp etc etc_one 6 | 7 | for version in `ls src`; do 8 | set -x 9 | sed -i "s|/opengrok/src|/opengrok/src/$version|" etc_one/$version/configuration.xml 10 | sed -i "s|/opengrok/data|/opengrok/data/$version|" etc_one/$version/configuration.xml 11 | done 12 | 13 | for version in `ls src`; do 14 | set -x 15 | cp -rp webapps/$version/$version webapps_one/ 16 | cp -rp webapps/$version/$version.war webapps_one/ 17 | sed -i "s|/opengrok/etc|/opengrok/etc/$version|" webapps_one/$version/WEB-INF/web.xml 18 | done -------------------------------------------------------------------------------- /conf.d/default.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | 4 | root /usr/local/openresty/nginx/html; 5 | index index.html; 6 | 7 | location /js/ { 8 | root /usr/local/openresty/nginx/html; 9 | try_files $uri =404; 10 | } 11 | 12 | location / { 13 | proxy_pass http://172.16.22.100:8080/; 14 | 15 | proxy_set_header Host $host; 16 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 17 | proxy_set_header X-Forwarded-Proto $scheme; 18 | 19 | sub_filter '' ''; 20 | sub_filter_once off; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # aospxref 2 | Deploy your own AOSPXRef 3 | 4 | ## Usage 5 | 6 | Clone aosp to /data/aospxref/src 7 | 8 | You can remove `.repo`, `prebuilts` to reduce size 9 | 10 | ``` 11 | /data/aospxref/src 12 | ├── android-10.0.0_r1 13 | ├── android-11.0.0_r1 14 | ├── android-12.0.0_r1 15 | ├── android-12.1.0_r1 16 | ├── android-13.0.0_r1 17 | ├── android-5.0.0_r1 18 | ├── android-5.1.0_r1 19 | ├── android-6.0.0_r1 20 | ├── android-7.0.0_r1 21 | ├── android-7.1.0_r1 22 | ├── android-8.0.0_r1 23 | ├── android-8.1.0_r1 24 | └── android-9.0.0_r1 25 | ``` 26 | 27 | Edit version.txt to your local versions 28 | 29 | then run gen.py to generate docker-compose.yml 30 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | aosp_openresty: 3 | container_name: aosp_openresty 4 | image: openresty/openresty:alpine 5 | ports: 6 | - 8080:80 7 | volumes: 8 | - ./conf.d:/etc/nginx/conf.d 9 | - ./html:/usr/local/openresty/nginx/html 10 | restart: unless-stopped 11 | networks: 12 | vpn: 13 | ipv4_address: 172.16.22.99 14 | 15 | aosp_opengrok: 16 | build: 17 | context: ./docker 18 | container_name: aosp_opengrok 19 | volumes: 20 | - '/data/aospapp/src:/opengrok/src:ro' 21 | - '/data/aospapp/data:/opengrok/data' 22 | - '/data/aospapp/etc_one:/opengrok/etc' 23 | - '/data/aospapp/webapps_one:/usr/local/tomcat/webapps' 24 | restart: unless-stopped 25 | networks: 26 | vpn: 27 | ipv4_address: 172.16.22.100 28 | 29 | networks: 30 | vpn: 31 | driver: bridge 32 | ipam: 33 | driver: default 34 | config: 35 | - subnet: 172.16.22.0/24 36 | gateway: 172.16.22.1 37 | -------------------------------------------------------------------------------- /docker/scripts/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | export JAVA_HOME=/usr/lib/jvm/default 4 | log_file="/var/log/aosp-indexer.log" 5 | echo "Versions to deploy:" 6 | for version in `ls /opengrok/src`; do 7 | echo $version 8 | done 9 | sleep 1 10 | echo "Task start:" 11 | for version in `ls /opengrok/src`; do 12 | ( 13 | set -x 14 | opengrok-deploy \ 15 | -c /opengrok/etc/$version/configuration.xml \ 16 | /opengrok/lib/source.war \ 17 | /usr/local/tomcat/webapps/$version.war 18 | sleep 20 19 | opengrok-indexer \ 20 | -J=-Djava.util.logging.config.file=/opengrok/etc/logging.properties \ 21 | -a /opengrok/lib/opengrok.jar -- \ 22 | -c /usr/local/bin/ctags \ 23 | -s /opengrok/src/$version \ 24 | -d /opengrok/data/$version \ 25 | -H -P -S -G \ 26 | -W /opengrok/etc/${version}/configuration.xml \ 27 | -U http://localhost:8080/$version 28 | ) 29 | if [ $? -eq 0 ]; then 30 | echo "$(date) $version success." 31 | else 32 | echo "$(date) $version failure." 33 | fi >> "$log_file" 34 | done -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM opengrok/docker:1.13.24 2 | 3 | # environment values 4 | ENV SRC_ROOT=/opengrok/src 5 | ENV DATA_ROOT=/opengrok/data 6 | ENV URL_ROOT=/ 7 | ENV CATALINA_HOME=/usr/local/tomcat 8 | ENV CATALINA_BASE=/usr/local/tomcat 9 | ENV CATALINA_TMPDIR=/usr/local/tomcat/temp 10 | ENV PATH=$CATALINA_HOME/bin:$PATH 11 | ENV CLASSPATH=/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar 12 | ENV JAVA_OPTS="--add-exports=java.base/jdk.internal.ref=ALL-UNNAMED --add-exports=java.base/sun.nio.ch=ALL-UNNAMED \ 13 | --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \ 14 | --add-opens=jdk.compiler/com.sun.tools.javac=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED \ 15 | --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED \ 16 | --add-opens=java.base/java.util=ALL-UNNAMED" 17 | 18 | # add our scripts and configuration 19 | RUN rm -rf /scripts 20 | COPY scripts /scripts 21 | RUN chmod -R +x /scripts 22 | 23 | # run 24 | WORKDIR $CATALINA_HOME 25 | EXPOSE 8080 26 | CMD ["/scripts/start.py"] -------------------------------------------------------------------------------- /html/js/branch.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function() { 2 | var selectLi = $('
  • '); 3 | var select = $(''); 4 | 5 | var branchOptions = [ 6 | "android-15.0.0_r3", 7 | "android-14.0.0_r2", 8 | "android-13.0.0_r3", 9 | "android-12.1.0_r1", 10 | "android-12.0.0_r2", 11 | "android-11.0.0_r1", 12 | "android-10.0.0_r2", 13 | "android-9.0.0_r3", 14 | "android-8.1.0_r1", 15 | "android-8.0.0_r4", 16 | "android-7.1.0_r4", 17 | "android-7.0.0_r1", 18 | "android-6.0.0_r1", 19 | "android-5.1.0_r1", 20 | "android-5.0.2_r3" 21 | ]; 22 | 23 | var currentBranch = window.location.pathname.match(/android-\d+\.\d+\.\d+_r\d+/); 24 | currentBranch = currentBranch ? currentBranch[0] : ""; 25 | 26 | for (var i = 0; i < branchOptions.length; i++) { 27 | var option = $('').attr('value', branchOptions[i]).text(branchOptions[i]); 28 | if (branchOptions[i] === currentBranch) { 29 | option.attr('selected', 'selected'); 30 | } 31 | select.append(option); 32 | } 33 | 34 | selectLi.append(select); 35 | 36 | select.on('change', function() { 37 | var selectedBranch = $(this).val(); 38 | var currentURL = window.location.href; 39 | var newURL = currentURL.replace(/android-\d+\.\d+\.\d+_r\d+/, selectedBranch); 40 | window.location.href = newURL; 41 | }); 42 | 43 | $('#bar ul').prepend(selectLi); 44 | }); 45 | -------------------------------------------------------------------------------- /docker/scripts/start.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import logging 4 | import os 5 | import queue 6 | import shutil 7 | import signal 8 | import subprocess 9 | import tempfile 10 | import threading 11 | import time 12 | 13 | from opengrok_tools.config_merge import merge_config_files 14 | from opengrok_tools.deploy import deploy_war 15 | from opengrok_tools.utils.commandsequence import COMMAND_PROPERTY, ENV_PROPERTY 16 | from opengrok_tools.utils.exitvals import SUCCESS_EXITVAL 17 | from opengrok_tools.utils.indexer import Indexer 18 | from opengrok_tools.utils.log import ( 19 | get_class_basename, 20 | get_console_logger, 21 | get_log_level, 22 | ) 23 | from opengrok_tools.utils.opengrok import ( 24 | add_project, 25 | delete_project, 26 | get_configuration, 27 | get_repos, 28 | list_projects, 29 | ) 30 | from requests import ConnectionError, get 31 | 32 | import docker_config 33 | 34 | fs_root = os.path.abspath(".").split(os.path.sep)[0] + os.path.sep 35 | tomcat_root = os.path.join(fs_root, "usr", "local", "tomcat") 36 | 37 | OPENGROK_BASE_DIR = os.path.join(fs_root, "opengrok") 38 | OPENGROK_LIB_DIR = os.path.join(OPENGROK_BASE_DIR, "lib") 39 | OPENGROK_DATA_ROOT = os.path.join(OPENGROK_BASE_DIR, "data") 40 | OPENGROK_SRC_ROOT = os.path.join(OPENGROK_BASE_DIR, "src") 41 | BODY_INCLUDE_FILE = os.path.join(OPENGROK_DATA_ROOT, "body_include") 42 | OPENGROK_CONFIG_DIR = os.path.join(OPENGROK_BASE_DIR, "etc") 43 | OPENGROK_WEBAPPS_DIR = os.path.join(tomcat_root, "webapps") 44 | OPENGROK_JAR = os.path.join(OPENGROK_LIB_DIR, "opengrok.jar") 45 | 46 | AOSPAPP_BASE_DIR = os.path.join(fs_root, "scripts") 47 | ROOT_WAR = os.path.join(AOSPAPP_BASE_DIR, "ROOT.war") 48 | 49 | task_queue = queue.Queue() 50 | 51 | 52 | def format_url_root(logger, url_root): 53 | """ 54 | Set URL root and URI based on input 55 | :param logger: logger instance 56 | :param url_root: input 57 | :return: URI and URL root 58 | """ 59 | if not url_root: 60 | url_root = "/" 61 | 62 | if " " in url_root: 63 | logger.warn("Deployment path contains spaces. Deploying to root") 64 | url_root = "/" 65 | 66 | # Remove leading and trailing slashes 67 | if url_root.startswith("/"): 68 | url_root = url_root[1:] 69 | if url_root.endswith("/"): 70 | url_root = url_root[:-1] 71 | 72 | uri = "http://localhost:8080/" + url_root 73 | # 74 | # Make sure URI ends with slash. This is important for the various API 75 | # calls, notably for those that check the HTTP error code. 76 | # Normally accessing the URI without the terminating slash results in 77 | # HTTP redirect (code 302) instead of success (200). 78 | # 79 | if not uri.endswith("/"): 80 | uri = uri + "/" 81 | 82 | return uri, url_root 83 | 84 | 85 | def deploy_opengrok(logger, url_root, config_file): 86 | """ 87 | Deploy the web application, will regenerate webapps dir 88 | :param logger: logger instance 89 | :param url_root: web app URL root 90 | :param config_file: config file path 91 | """ 92 | 93 | logger.info("Deploying web application for {}".format(url_root)) 94 | webapps_dir = os.path.join(tomcat_root, "webapps") 95 | if not os.path.isdir(webapps_dir): 96 | raise Exception("{} is not a directory".format(webapps_dir)) 97 | 98 | for item in os.listdir(webapps_dir): 99 | subdir = os.path.join(webapps_dir, item) 100 | if os.path.isdir(subdir): 101 | logger.debug("Removing '{}' directory recursively".format(subdir)) 102 | shutil.rmtree(subdir) 103 | 104 | deploy_war( 105 | logger, 106 | os.path.join(OPENGROK_LIB_DIR, "source.war"), 107 | os.path.join(OPENGROK_WEBAPPS_DIR, url_root + ".war"), 108 | config_file, 109 | None, 110 | ) 111 | 112 | 113 | def wait_for_tomcat(logger, uri): 114 | """ 115 | Active/busy waiting for Tomcat to come up. 116 | Currently, there is no upper time bound. 117 | """ 118 | logger.info("Waiting for Tomcat to start") 119 | 120 | while True: 121 | try: 122 | ret = get(uri) 123 | status = ret.status_code 124 | except ConnectionError: 125 | status = 0 126 | 127 | if status != 200: 128 | logger.debug( 129 | "Got status {} for {}, sleeping for 1 second".format(status, uri) 130 | ) 131 | time.sleep(1) 132 | else: 133 | break 134 | 135 | logger.info("Tomcat is ready") 136 | 137 | 138 | def refresh_projects(logger, uri, api_timeout): 139 | """ 140 | Ensure each immediate source root subdirectory is a project. 141 | """ 142 | webapp_projects = list_projects(logger, uri, timeout=api_timeout) 143 | if webapp_projects is None: 144 | return 145 | 146 | logger.debug("Projects from the web app: {}".format(webapp_projects)) 147 | src_root = OPENGROK_SRC_ROOT 148 | 149 | # Add projects for top-level directories under source root. 150 | for item in os.listdir(src_root): 151 | logger.debug("Got item {}".format(item)) 152 | if os.path.isdir(os.path.join(src_root, item)): 153 | if item in webapp_projects: 154 | action = "Refreshing" 155 | else: 156 | action = "Adding" 157 | logger.info(f"{action} project {item}") 158 | add_project(logger, item, uri, timeout=api_timeout) 159 | 160 | if logger.level == logging.DEBUG: 161 | repos = get_repos(logger, item, uri) 162 | if repos: 163 | logger.debug( 164 | "Project {} has these repositories: {}".format(item, repos) 165 | ) 166 | 167 | # Remove projects that no longer have source. 168 | for item in webapp_projects: 169 | if not os.path.isdir(os.path.join(src_root, item)): 170 | logger.info("Deleting project {}".format(item)) 171 | delete_project(logger, item, uri, timeout=api_timeout) 172 | 173 | 174 | def save_config(logger, uri, config_path, api_timeout): 175 | """ 176 | Retrieve configuration from the web app and write it to file. 177 | :param logger: logger instance 178 | :param uri: web app URI 179 | :param config_path: file path 180 | """ 181 | 182 | config = get_configuration(logger, uri, timeout=api_timeout) 183 | if config is None: 184 | return 185 | 186 | logger.info("Saving configuration to {}".format(config_path)) 187 | with open(config_path, "w+") as config_file: 188 | config_file.write(config) 189 | 190 | 191 | def merge_commands_env(commands, env): 192 | """ 193 | Merge environment into command structure. If any of the commands has 194 | an environment already set, the env is merged in. 195 | :param commands: commands structure 196 | :param env: environment dictionary 197 | :return: updated commands structure 198 | """ 199 | for entry in commands: 200 | cmd = entry.get(COMMAND_PROPERTY) 201 | if cmd: 202 | cmd_env = cmd.get(ENV_PROPERTY) 203 | if cmd_env: 204 | cmd_env.update(env) 205 | else: 206 | cmd[ENV_PROPERTY] = env 207 | 208 | return commands 209 | 210 | 211 | def project_indexer(logger, project, uri, config_path): 212 | """ 213 | Wrapper for running opengrok-sync. 214 | To be run in a thread/process in the background. 215 | """ 216 | 217 | wait_for_tomcat(logger, uri) 218 | 219 | logger.info("Index starting: " + project) 220 | 221 | indexer_java_opts = docker_config.INDEXER_JAVA_OPTS 222 | if indexer_java_opts: 223 | indexer_java_opts = indexer_java_opts.split() 224 | 225 | indexer_options = [ 226 | "-s", 227 | os.path.join(OPENGROK_SRC_ROOT, project), 228 | "-d", 229 | os.path.join(OPENGROK_DATA_ROOT, project), 230 | "-c", 231 | "/usr/local/bin/ctags", 232 | "-H", 233 | "-P", 234 | "-S", 235 | "-G", 236 | "-W", 237 | config_path, 238 | "-U", 239 | "http://localhost:8080/" + project, 240 | ] 241 | 242 | indexer = Indexer( 243 | indexer_options, 244 | java_opts=indexer_java_opts, 245 | jar=OPENGROK_JAR, 246 | logger=logger, 247 | doprint=True, 248 | ) 249 | indexer.execute() 250 | ret = indexer.getretcode() 251 | if ret != SUCCESS_EXITVAL: 252 | logger.error(f"Command returned {ret}") 253 | logger.error(indexer.geterroutput()) 254 | raise Exception("Failed to index") 255 | logger.info("Index done: " + project) 256 | 257 | 258 | def create_bare_config(logger, aosp_project, config_file): 259 | """ 260 | Create bare configuration file with a few basic settings. 261 | """ 262 | 263 | indexer_java_opts = docker_config.INDEXER_JAVA_OPTS 264 | if indexer_java_opts: 265 | indexer_java_opts = indexer_java_opts.split() 266 | 267 | logger.info("Creating bare configuration in {}".format(config_file)) 268 | indexer_options = [ 269 | "-s", 270 | os.path.join(OPENGROK_SRC_ROOT, aosp_project), 271 | "-d", 272 | os.path.join(OPENGROK_DATA_ROOT, aosp_project), 273 | "-c", 274 | "/usr/local/bin/ctags", 275 | "--remote", 276 | "on", 277 | "-H", 278 | "-S", 279 | "-W", 280 | "-P", 281 | config_file, 282 | "--noIndex", 283 | ] 284 | 285 | indexer = Indexer( 286 | indexer_options, 287 | java_opts=indexer_java_opts, 288 | jar=OPENGROK_JAR, 289 | logger=logger, 290 | doprint=True, 291 | ) 292 | indexer.execute() 293 | ret = indexer.getretcode() 294 | if ret != SUCCESS_EXITVAL: 295 | logger.error(f"Command returned {ret}") 296 | logger.error(indexer.geterroutput()) 297 | raise Exception("Failed to create bare configuration") 298 | 299 | 300 | def check_index_and_wipe_out(logger, project, config_file): 301 | """ 302 | Check index by running the indexer. If the index does not match 303 | currently running version and the CHECK_INDEX environment variable 304 | is non-empty, wipe out the directories under data root. 305 | """ 306 | indexer_java_opts = docker_config.INDEXER_JAVA_OPTS 307 | if indexer_java_opts: 308 | indexer_java_opts = indexer_java_opts.split() 309 | 310 | if docker_config.CHECK_INDEX and os.path.exists(config_file): 311 | logger.info("Checking if index matches current version") 312 | indexer_options = ["-R", config_file, "--checkIndex", "version"] 313 | indexer = Indexer( 314 | indexer_options, 315 | java_opts=indexer_java_opts, 316 | logger=logger, 317 | jar=OPENGROK_JAR, 318 | doprint=True, 319 | ) 320 | indexer.execute() 321 | if indexer.getretcode() == 1: 322 | if not docker_config.TEST_MODE: 323 | logger.info("Wiping out data root") 324 | root = os.path.join(OPENGROK_DATA_ROOT, project) 325 | for entry in os.listdir(root): 326 | path = os.path.join(root, entry) 327 | if os.path.isdir(path): 328 | try: 329 | logger.info(f"Removing '{path}'") 330 | shutil.rmtree(path) 331 | except Exception as exc: 332 | logger.error("cannot delete '{}': {}".format(path, exc)) 333 | return True 334 | else: 335 | print("[TEST] ignore wiping data") 336 | return False 337 | 338 | 339 | def get_all_aosp_projects(): 340 | return [entry for entry in os.listdir(OPENGROK_SRC_ROOT) if os.path.isdir(os.path.join(OPENGROK_SRC_ROOT, entry))] 341 | 342 | 343 | def process_project(logger, log_level, project): 344 | logger.debug("AOSP_PROJECT = {}".format(project)) 345 | uri, url_root = format_url_root(logger, project) 346 | logger.debug("\tURL_ROOT = {}".format(url_root)) 347 | logger.debug("\tURI = {}".format(uri)) 348 | config_file_path = os.path.join(OPENGROK_CONFIG_DIR, project, "configuration.xml") 349 | deploy_opengrok(logger, url_root, config_file_path) 350 | if not os.path.exists(config_file_path) or os.path.getsize(config_file_path) == 0: 351 | create_bare_config(logger, project, config_file_path) 352 | 353 | need_index = check_index_and_wipe_out(logger, project, config_file_path) 354 | 355 | # 356 | # If there is read-only configuration file, merge it with current 357 | # configuration. 358 | # 359 | read_only_config_file = docker_config.READONLY_CONFIG_FILE 360 | if read_only_config_file and os.path.exists(read_only_config_file): 361 | logger.info( 362 | "Merging read-only configuration from '{}' with current " 363 | "configuration in '{}'".format(read_only_config_file, config_file_path) 364 | ) 365 | out_file_path = None 366 | with tempfile.NamedTemporaryFile( 367 | mode="w+", delete=False, prefix="merged_config" 368 | ) as tmp_out_fobj: 369 | out_file_path = tmp_out_fobj.name 370 | merge_config_files( 371 | read_only_config_file, 372 | config_file_path, 373 | out_file_path, 374 | jar=OPENGROK_JAR, 375 | loglevel=log_level, 376 | ) 377 | 378 | if out_file_path and os.path.getsize(out_file_path) > 0: 379 | shutil.move(out_file_path, config_file_path) 380 | else: 381 | logger.warning( 382 | "Failed to merge read-only configuration, " 383 | "leaving the original in place" 384 | ) 385 | if out_file_path: 386 | os.remove(out_file_path) 387 | 388 | if need_index: 389 | indexer_args = ( 390 | logger, 391 | project, 392 | uri, 393 | config_file_path, 394 | ) 395 | 396 | logger.info("Queue index thread for " + project) 397 | index_thread = threading.Thread( 398 | target=project_indexer, name="Indexer thread for " + project, args=indexer_args, daemon=True 399 | ) 400 | task_queue.put(index_thread) 401 | 402 | 403 | def indexer_worker(): 404 | while not task_queue.empty(): 405 | task = task_queue.get() 406 | task.start() 407 | task.join() 408 | 409 | 410 | def main(): 411 | log_level = docker_config.OPENGROK_LOG_LEVEL 412 | if log_level: 413 | log_level = get_log_level(log_level) 414 | else: 415 | log_level = logging.INFO 416 | 417 | logger = get_console_logger(get_class_basename(), log_level) 418 | 419 | logger.info("Welcome to opengrok env for aosp.app") 420 | 421 | try: 422 | with open(os.path.join(OPENGROK_BASE_DIR, "VERSION"), "r") as f: 423 | version = f.read() 424 | logger.info("Running version {}".format(version)) 425 | except Exception: 426 | pass 427 | 428 | # Deploy ROOT.war 429 | deploy_war( 430 | logger, 431 | ROOT_WAR, 432 | os.path.join(OPENGROK_WEBAPPS_DIR, "ROOT.war"), 433 | None, 434 | None, 435 | ) 436 | 437 | # Deploy opengrok for each aosp project 438 | aosp_projects = get_all_aosp_projects() 439 | for project in aosp_projects: 440 | if project.startswith("android-"): 441 | process_project(logger, log_level, project) 442 | 443 | task_thread = threading.Thread( 444 | target=indexer_worker, name="Indexer Worker thread", daemon=True 445 | ) 446 | task_thread.start() 447 | 448 | # Start Tomcat last. 449 | logger.info("Starting Tomcat") 450 | tomcat_temp = os.path.join(OPENGROK_DATA_ROOT, "tomcat_temp") 451 | os.makedirs(tomcat_temp, exist_ok=True) 452 | tomcat_env = dict(os.environ) 453 | tomcat_env["CATALINA_TMPDIR"] = tomcat_temp 454 | tomcat_popen = subprocess.Popen( 455 | [os.path.join(tomcat_root, "bin", "catalina.sh"), "run"], env=tomcat_env 456 | ) 457 | 458 | sigset = set() 459 | sigset.add(signal.SIGTERM) 460 | sigset.add(signal.SIGINT) 461 | signum = signal.sigwait(sigset) 462 | logger.info("Received signal {}".format(signum)) 463 | if tomcat_popen: 464 | logger.info("Terminating Tomcat {}".format(tomcat_popen)) 465 | tomcat_popen.terminate() 466 | 467 | 468 | if __name__ == "__main__": 469 | main() --------------------------------------------------------------------------------