Skip to content

Commit 91c60ee

Browse files
author
Vladimir Kotal
committed
Merge branch 'wy193777-add-dockerfile2'
2 parents a8e7eea + c641240 commit 91c60ee

File tree

8 files changed

+338
-8
lines changed

8 files changed

+338
-8
lines changed

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ jobs:
7777
on:
7878
condition: "$TRAVIS_TAG =~ ^[0-9\\.]+$"
7979
all_branches: true
80+
- stage: docker
81+
name: Docker image build
82+
dist: xenial
83+
jdk: openjdk8
84+
install: true
85+
if: repo = "oracle/opengrok" AND tag IS present
86+
before_script: mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -V package
87+
script: dev/docker.sh
8088
- stage: post_deploy
8189
name: Post deploy
8290
if: repo = "oracle/opengrok" AND tag IS present

Dockerfile

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

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).

dev/docker.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
#
4+
# Build and push new image to Docker hub.
5+
#
6+
# Uses the following Travis secure variables:
7+
# - DOCKER_USERNAME
8+
# - DOCKER_PASSWORD
9+
#
10+
# These are set via https://travis-ci.com/OpenGrok/docker/settings
11+
#
12+
13+
set -x
14+
set -e
15+
16+
# Travis can only work on master since it needs encrypted variables.
17+
if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then
18+
print "Not build docker image for pull requests"
19+
exit 0
20+
fi
21+
22+
# Build the image.
23+
docker build -t opengrok/docker:$VERSION -t opengrok/docker:latest .
24+
#
25+
# Run the image in container. This is not strictly needed however
26+
# serves as additional test in automatic builds.
27+
#
28+
docker run -d opengrok/docker
29+
docker ps -a
30+
31+
# Publish the image to Docker hub.
32+
if [ -n "$DOCKER_PASSWORD" -a -n "$DOCKER_USERNAME" -a -n "$VERSION" ]; then
33+
echo "Logging into docker"
34+
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
35+
36+
# All the tags need to be pushed individually:
37+
echo "Pushing docker image for tag $VERSION"
38+
docker push opengrok/docker:$VERSION
39+
echo "Pushing docker image for tag latest"
40+
docker push opengrok/docker:latest
41+
fi

docker/README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
Built from official source: https://github.com/oracle/opengrok/releases/
8+
9+
You can learn more about OpenGrok at http://oracle.github.io/opengrok/
10+
11+
The container is available from DockerHub at https://hub.docker.com/r/opengrok/docker/
12+
13+
## When not to use it
14+
15+
This image is simple wrapper around OpenGrok environment. The indexer and the web container are **not** tuned for large workloads.
16+
If you happen to have one of the following:
17+
- large source data (e.g. [AOSP](https://en.wikipedia.org/wiki/Android_Open_Source_Project) or the like)
18+
- stable service
19+
- Source Code Management systems not supported in the image (e.g. Perforce,
20+
Clearcase, etc.)
21+
then it is advisable to run OpenGrok standalone or construct your own docker
22+
image based on the official one.
23+
24+
## Additional info about the container
25+
26+
* Tomcat 9
27+
* JRE 8 (Required for Opengrok 1.0+)
28+
* Configurable mirroring/reindexing (default every 10 min)
29+
30+
The mirroring step works by going through all projects and attempting to
31+
synchronize all its repositories (e.g. it will do `git pull` for Git
32+
repositories).
33+
34+
The indexer/mirroring is set so that it does not log into files.
35+
Rather, everything goes to standard (error) output. To see how the indexer
36+
is doing, use the `docker logs` command.
37+
38+
## How to run
39+
40+
### From DockerHub
41+
42+
docker run -d -v <path/to/your/src>:/opengrok/src -p 8080:8080 opengrok/docker:latest
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+
### Build image locally
76+
77+
If you want to do your own development, you can build the image yourself:
78+
79+
mvn -DskipTests=true clean package && \
80+
docker build -t opengrok-dev .
81+
82+
Then run the container:
83+
84+
docker run -d -v <path/to/your/src>:/opengrok/src -p 8080:8080 opengrok-dev
85+
86+
## Inspecting the container
87+
88+
You can get inside a container using the [command below](https://docs.docker.com/engine/reference/commandline/exec/):
89+
90+
```
91+
docker exec -it <container> bash
92+
```
93+
94+
Enjoy.

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/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

0 commit comments

Comments
 (0)