Skip to content

Commit 6dce66a

Browse files
author
Vladimir Kotal
committed
Merge branch 'add-dockerfile2' of https://github.com/wy193777/opengrok into wy193777-add-dockerfile2
2 parents a8e7eea + b827320 commit 6dce66a

File tree

6 files changed

+276
-8
lines changed

6 files changed

+276
-8
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ Copyright (c) 2006, 2018 Oracle and/or its affiliates. All rights reserved.
1010
[![AppVeyor status](https://ci.appveyor.com/api/projects/status/8oqlk5yx2c5fnwqw/branch/master?svg=true)](https://ci.appveyor.com/project/vladak/opengrok-b5hnp/branch/master)
1111
[![License](https://img.shields.io/badge/License-CDDL%201.0-blue.svg)](https://opensource.org/licenses/CDDL-1.0)
1212

13-
1. [Introduction](#1-introduction)
14-
2. [OpenGrok setup](#2-opengrok-install-and-setup)
15-
3. [Information for developers](#3-information-for-developers)
16-
4. [Authors](#4-authors)
17-
5. [Contact us](#5-contact-us)
18-
7. [Demo](#6-demo)
13+
- [OpenGrok - a wicked fast source browser](#opengrok---a-wicked-fast-source-browser)
14+
- [1. Introduction](#1-introduction)
15+
- [2. OpenGrok install and setup](#2-opengrok-install-and-setup)
16+
- [3. Information for developers](#3-information-for-developers)
17+
- [4. Authors](#4-authors)
18+
- [5. Contact us](#5-contact-us)
19+
- [6. Run as container](#6-run-as-container)
1920

2021
## 1. Introduction
2122

@@ -53,6 +54,6 @@ To subscribe, send email to `<mailing_list_name>[email protected]`
5354

5455
There are also Slack channels on https://opengrok.slack.com/
5556

56-
## 6. Demo
57+
## 6. Run as container
5758

58-
Anyway, just demo it yourself - there are Docker images available on https://hub.docker.com/r/opengrok/docker/
59+
You can run opengrok as a docker container as described [here](docker/readme.md).

docker/docker.logging.properties

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2017 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed with
5+
# this work for additional information regarding copyright ownership.
6+
# The ASF licenses this file to You under the Apache License, Version 2.0
7+
# (the "License"); you may not use this file except in compliance with
8+
# the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
handlers = java.util.logging.ConsoleHandler
19+
20+
.handlers = java.util.logging.ConsoleHandler
21+
22+
############################################################
23+
# Handler specific properties.
24+
# Describes specific configuration info for Handlers.
25+
############################################################
26+
27+
java.util.logging.ConsoleHandler.level = FINE
28+
java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter
29+
30+
############################################################
31+
# Facility specific properties.
32+
# Provides extra control for each logger.
33+
############################################################
34+
35+
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
36+
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = java.util.logging.ConsoleHandler
37+
38+
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
39+
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = java.util.logging.ConsoleHandler
40+
41+
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = INFO
42+
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = java.util.logging.ConsoleHandler

docker/index.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
LOCKFILE=/var/run/opengrok-indexer
4+
URI="http://localhost:8080"
5+
# $OPTS an be overwriteb by environment variable
6+
OPS=${INDEXER_FLAGS:='-H -P -S -G'}
7+
8+
if [ -f "$LOCKFILE" ]; then
9+
date +"%F %T Indexer still locked, skipping indexing"
10+
exit 1
11+
fi
12+
13+
touch $LOCKFILE
14+
15+
if [ -z $NOMIRROR ]; then
16+
date +"%F %T Mirroring starting"
17+
opengrok-mirror --all --uri "$URI"
18+
date +"%F %T Mirroring finished"
19+
fi
20+
21+
date +"%F %T Indexing starting"
22+
opengrok-indexer \
23+
-a /opengrok/lib/opengrok.jar -- \
24+
-s /opengrok/src \
25+
-d /opengrok/data \
26+
--leadingWildCards on \
27+
-W /var/opengrok/etc/configuration.xml \
28+
-U "$URI" \
29+
$OPS \
30+
$INDEXER_OPT "$@"
31+
date +"%F %T Indexing finished"
32+
33+
rm -f $LOCKFILE

docker/readme.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
[![Travis status](https://travis-ci.com/OpenGrok/docker.svg?branch=master)](https://travis-ci.com/OpenGrok/docker)
2+
3+
# A Docker container for OpenGrok
4+
5+
## OpenGrok from official source
6+
7+
Directly downloaded from official source:
8+
https://github.com/oracle/opengrok/releases/
9+
10+
You can learn more about OpenGrok at http://oracle.github.io/opengrok/
11+
12+
The container is available from DockerHub at https://hub.docker.com/r/opengrok/docker/
13+
14+
## When not to use it
15+
16+
This image is simple wrapper around OpenGrok environment. The indexer and the web container are **not** tuned for large workloads. If you happen to have either large source data (e.g. [AOSP](https://en.wikipedia.org/wiki/Android_Open_Source_Project) or the like) or stable service or both, it is advisable to run the service standalone.
17+
18+
## Additional info about the container
19+
20+
* Tomcat 9
21+
* JRE 8 (Required for Opengrok 1.0+)
22+
* Configurable mirroring/reindexing (default every 10 min)
23+
24+
The mirroring step works by going through all projects and attempting to
25+
synchronize all its repositories (e.g. it will do `git pull` for Git
26+
repositories).
27+
28+
The indexer/mirroring is set so that it does not log into files.
29+
30+
## How to run
31+
32+
### From DockerHub
33+
34+
docker run -d -v <path/to/your/src>:/opengrok/src -p 8080:8080 opengrok/docker:latest
35+
36+
### Build image locally
37+
38+
docker build -t opengrok-dev .
39+
40+
Then run the container,
41+
42+
docker run -d -v <path/to/your/src>:/opengrok/src -p 8080:8080 opengrok-dev
43+
44+
The container exports ports 8080 for OpenGrok.
45+
46+
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.
47+
48+
By default, the index will be rebuild every ten minutes. You can adjust this
49+
time (in minutes) by passing the `REINDEX` environment variable:
50+
51+
docker run -d -e REINDEX=30 -v <path/to/your/src>:/opengrok/src -p 8080:8080 opengrok/docker:latest
52+
53+
Setting `REINDEX` to `0` will disable automatic indexing. You can manually trigger an reindex using docker exec:
54+
55+
docker exec <container> /scripts/index.sh
56+
57+
Setting `INDEXER_OPT` could pass extra options to opengrok-indexer. For example, you can run with:
58+
59+
docker run -d -e INDEXER_OPT="-i d:vendor" -v <path/to/your/src>:/opengrok/src -p 8080:8080 opengrok/docker:latest
60+
61+
To remove all the `*/vendor/*` files from the index. You can check the indexer options on
62+
63+
https://github.com/oracle/opengrok/wiki/Python-scripts-transition-guide
64+
65+
To avoid the mirroring step, set the `NOMIRROR` variable to non-empty value.
66+
67+
## OpenGrok Web-Interface
68+
69+
The container has OpenGrok as default web app installed (accessible directly from `/`). With the above container setup, you can find it running on
70+
71+
http://localhost:8080/
72+
73+
The first reindex will take some time to finish. Subsequent reindex will be incremental so will take signigicantly less time.
74+
75+
## Inspecting the container
76+
77+
You can get inside a container using the [command below](https://docs.docker.com/engine/reference/commandline/exec/):
78+
79+
```
80+
docker exec -it <container> bash
81+
```
82+
83+
Enjoy.

docker/start.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
# default period for reindexing (in minutes)
4+
if [ -z "$REINDEX" ]; then
5+
REINDEX=10
6+
fi
7+
8+
indexer(){
9+
# Wait for Tomcat startup.
10+
date +"%F %T Waiting for Tomcat startup..."
11+
while [ "`curl --silent --write-out '%{response_code}' -o /dev/null 'http://localhost:8080/'`" == "000" ]; do
12+
sleep 1;
13+
done
14+
date +"%F %T Startup finished"
15+
16+
if [[ ! -d /opengrok/data/index ]]; then
17+
# Populate the webapp with bare configuration.
18+
BODY_INCLUDE_FILE="/opengrok/data/body_include"
19+
if [[ -f $BODY_INCLUDE_FILE ]]; then
20+
mv "$BODY_INCLUDE_FILE" "$BODY_INCLUDE_FILE.orig"
21+
fi
22+
echo '<p><h1>Waiting on the initial reindex to finish.. Stay tuned !</h1></p>' > "$BODY_INCLUDE_FILE"
23+
/scripts/index.sh --noIndex
24+
rm -f "$BODY_INCLUDE_FILE"
25+
if [[ -f $BODY_INCLUDE_FILE.orig ]]; then
26+
mv "$BODY_INCLUDE_FILE.orig" "$BODY_INCLUDE_FILE"
27+
fi
28+
29+
# Perform initial indexing.
30+
NOMIRROR=1 /scripts/index.sh
31+
date +"%F %T Initial reindex finished"
32+
fi
33+
34+
# Continue to index every $REINDEX minutes.
35+
if [ "$REINDEX" == "0" ]; then
36+
date +"%F %T Automatic reindexing disabled"
37+
return
38+
else
39+
date +"%F %T Automatic reindexing in $REINDEX minutes..."
40+
fi
41+
while true; do
42+
sleep `expr 60 \* $REINDEX`
43+
/scripts/index.sh
44+
done
45+
}
46+
47+
# Start all necessary services.
48+
indexer &
49+
catalina.sh run

dockerfile

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
FROM maven:latest as builder
2+
3+
COPY ./ /opengrok-source
4+
WORKDIR /opengrok-source
5+
6+
RUN apt-get update && apt-get install -y python3 python3-venv
7+
RUN mvn -f pom.xml clean package -DskipTests=true
8+
# find most recent package file
9+
RUN cp `ls -t distribution/target/*.tar.gz | head -n1 |awk '{printf("%s",$0)}'` /opengrok.tar.gz
10+
11+
FROM tomcat:9-jre8
12+
LABEL maintainer "[email protected]"
13+
14+
# prepare OpenGrok binaries and directories
15+
COPY --from=builder opengrok.tar.gz /opengrok.tar.gz
16+
RUN mkdir -p /opengrok /var/opengrok/etc /opengrok/data /opengrok/src && \
17+
tar -zxvf /opengrok.tar.gz -C /opengrok --strip-components 1 && \
18+
rm -f /opengrok.tar.gz
19+
20+
# install dependencies
21+
RUN apt-get update && apt-get install -y git subversion mercurial unzip inotify-tools python3 python3-pip && \
22+
python3 -m pip install /opengrok/tools/opengrok-tools*
23+
# compile and install universal-ctags
24+
RUN apt-get install -y pkg-config autoconf build-essential && git clone https://github.com/universal-ctags/ctags /root/ctags && \
25+
cd /root/ctags && ./autogen.sh && ./configure && make && make install && \
26+
apt-get remove -y autoconf build-essential && apt-get -y autoremove && apt-get -y autoclean && \
27+
cd /root && rm -rf /root/ctags
28+
29+
# environment variables
30+
ENV SRC_ROOT /opengrok/src
31+
ENV DATA_ROOT /opengrok/data
32+
ENV OPENGROK_WEBAPP_CONTEXT /
33+
ENV OPENGROK_TOMCAT_BASE /usr/local/tomcat
34+
ENV CATALINA_HOME /usr/local/tomcat
35+
ENV PATH $CATALINA_HOME/bin:$PATH
36+
ENV CATALINA_BASE /usr/local/tomcat
37+
ENV CATALINA_HOME /usr/local/tomcat
38+
ENV CATALINA_TMPDIR /usr/local/tomcat/temp
39+
ENV JRE_HOME /usr
40+
ENV CLASSPATH /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
41+
42+
43+
# custom deployment to / with redirect from /source
44+
RUN rm -rf /usr/local/tomcat/webapps/* && \
45+
opengrok-deploy /opengrok/lib/source.war /usr/local/tomcat/webapps/ROOT.war && \
46+
mkdir "/usr/local/tomcat/webapps/source" && \
47+
echo '<% response.sendRedirect("/"); %>' > "/usr/local/tomcat/webapps/source/index.jsp"
48+
49+
# disable all file logging
50+
ADD docker/logging.properties /usr/local/tomcat/conf/logging.properties
51+
RUN sed -i -e 's/Valve/Disabled/' /usr/local/tomcat/conf/server.xml
52+
53+
# add our scripts
54+
ADD docker /scripts
55+
RUN chmod -R +x /scripts
56+
57+
# run
58+
WORKDIR $CATALINA_HOME
59+
EXPOSE 8080
60+
CMD ["/scripts/start.sh"]

0 commit comments

Comments
 (0)