Skip to content

Commit bf0d887

Browse files
committed
Initial commit
0 parents  commit bf0d887

File tree

9 files changed

+311
-0
lines changed

9 files changed

+311
-0
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Makefile
2+
.travis.yml

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
- 'docker'
3+
4+
script:
5+
- if [[ "$TRAVIS_BRANCH" == "master" ]]; then
6+
make release ;
7+
else
8+
make build ;
9+
fi

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM tomcat:8.5.35-jre8-slim
2+
3+
LABEL Maintaner JamfDevops <[email protected]>
4+
5+
RUN adduser --disabled-password --gecos '' tomcat && \
6+
rm -rf /usr/local/tomcat/webapps && \
7+
mkdir -p /usr/local/tomcat/webapps
8+
9+
COPY startup.sh /startup.sh
10+
COPY log4j.stdout.replace /log4j.stdout.replace
11+
COPY configuration.sh /configuration.sh
12+
13+
CMD ["/startup.sh"]
14+
15+
VOLUME /usr/local/tomcat/logs
16+
17+
EXPOSE 8080

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) 2010-2018 Google, Inc. http://angularjs.org
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

Makefile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# HELP
2+
# This will output the help for each task
3+
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
4+
.PHONY: help
5+
6+
help: ## This help.
7+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
8+
9+
.DEFAULT_GOAL := help
10+
11+
DOCKER_IMAGE_BASE := jamfdevops
12+
DOCKER_ORG :=
13+
DOCKER_IMAGE := jamfpro
14+
15+
VERSION=$(shell git --no-pager describe --tags --always)
16+
SHA=$(shell git rev-parse --verify HEAD)
17+
BUILD_URL=$(TRAVIS_JOB_WEB_URL)
18+
BUILD_TIMESTAMP=$(shell date +%s)
19+
20+
# DOCKER TASKS
21+
# Build the image
22+
build: ## Build the image
23+
docker build -t $(DOCKER_IMAGE) .
24+
25+
build-nc: ## Build the image without caching
26+
docker build --no-cache \
27+
--label "GIT_SHA=$(SHA)" \
28+
--label "BUILD_URL=$(BUILD_URL)" \
29+
--label "BUILD_TIMESTAMP=$(BUILD_TIMESTAMP)" \
30+
-t $(DOCKER_IMAGE) .
31+
32+
release: build-nc tag publish ## Make a release by building and publishing the `{version}` tagged image
33+
34+
# Docker publish
35+
publish: repo-login publish-version ## Publish the `{version}` tagged image
36+
37+
publish-latest: tag-latest ## Publish the `latest` taged container
38+
@echo 'Publish latest to $(DOCKER_IMAGE_BASE)$(DOCKER_ORG)'
39+
docker push $(DOCKER_IMAGE_BASE)$(DOCKER_ORG)/$(DOCKER_IMAGE):latest
40+
41+
publish-version: tag-version ## Publish the `{version}` tagged container
42+
@echo 'Publish $(VERSION) to $(DOCKER_IMAGE_BASE)$(DOCKER_ORG)'
43+
docker push $(DOCKER_IMAGE_BASE)$(DOCKER_ORG)/$(DOCKER_IMAGE):$(VERSION)
44+
45+
# Docker tagging
46+
tag: tag-latest tag-version ## Generate image tags for the `{version}` and `latest`
47+
48+
tag-latest: ## Generate image `{version}` tag
49+
@echo 'Create tag latest'
50+
docker tag $(DOCKER_IMAGE) $(DOCKER_IMAGE_BASE)$(DOCKER_ORG)/$(DOCKER_IMAGE):latest
51+
52+
tag-version: ## Generate image `latest` tag
53+
@echo 'Create tag $(VERSION)'
54+
docker tag $(DOCKER_IMAGE) $(DOCKER_IMAGE_BASE)$(DOCKER_ORG)/$(DOCKER_IMAGE):$(VERSION)
55+
56+
repo-login: ## Login to docker repo
57+
@echo 'Logging into DockerHub'
58+
docker login -u $(DOCKER_USERNAME) -p $(DOCKER_PASSWORD)
59+
60+
version: ## Output the current version
61+
@echo $(VERSION)

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# JamfPro Tomcat Docker image
2+
3+
## Description
4+
Basic Docker image based upon upstream Tomcat image to run a manually downloaded JamfPro ROOT.war from JamfNation
5+
6+
## Features
7+
* Creates and runs Tomcat as user:group tomcat (non-root)
8+
* Correct pathing for JamfPro file logs
9+
* Logs to stdout of JamfPro logs in addtion to catalina logs
10+
* JMX connection information
11+
* Remote database connection in DataBase.xml
12+
13+
## Environment Variable Options
14+
```
15+
STDOUT_LOGGING [ true ] / false
16+
17+
DATABASE_HOST [ localhost ]
18+
DATABASE_NAME [ jamfsoftware ]
19+
DATABASE_USERNAME [ jamfsoftware ]
20+
DATABASE_PASSWORD [ jamfsw03 ]
21+
DATABASE_PORT [ 3306 ]
22+
23+
JMXREMOTE true / [ false ]
24+
JMXREMOTE_PORT
25+
JMXREMOTE_RMI_PORT
26+
JMXREMOTE_SSL
27+
JMXREMOTE_AUTHENTICATE
28+
RMI_SERVER_HOSTNAME
29+
JMXREMOTE_PASSWORD_FILE
30+
31+
CATALINA_OPTS
32+
JAVA_OPTS [ -Djava.awt.headless=true ]
33+
34+
```
35+
36+
## Data Persistence
37+
This image requires that either a `/data/ROOT.war` be bind-mounted and exist, or the `/usr/bin/tomcat/webapps/ROOT` directory exist.
38+
A ROOT.war will be auto-unpacked and configured based upon the above environment variables, or if the ROOT directory already exists, nothing will be unpacked but logging paths, database information, JMX, and Java opts will be set.
39+
40+
## Example
41+
Run a basic JamfPro instance with port 8080 exposed locally on port 8080, setup remote database, bind-mounted ROOT.war, and bind-mounted webapps directory
42+
43+
```
44+
docker run -p 8080:8080 -d \
45+
-e DATABASE_USERNAME=root \
46+
-e DATABASE_PASSWORD=jamfsw03 \
47+
-e DATABASE_HOST=host.docker.internal \
48+
-v $(pwd)/ROOT.war:/data/ROOT.war \
49+
-v $(pwd)/webapps:/usr/local/tomcat/webapps \
50+
jamfpro
51+
```

configuration.sh

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/bin/bash -e
2+
3+
##########################################################
4+
####################### Functions ########################
5+
echo_time() {
6+
date +"%Y-%m-%d %T %z $(printf "%b " "$@" | sed 's/%/%%/g')"
7+
}
8+
9+
unpack_root_war() {
10+
if [ ! -f /data/ROOT.war ]; then
11+
echo_time "FATAL ERROR: No ROOT.war to unpack, cannot continue
12+
Mount ROOT.war to /data/ROOT.war"
13+
exit 1
14+
fi
15+
#Unpack the warfile
16+
echo_time "Unpacking ROOT.war to /usr/local/tomcat/webapps/ROOT \n"
17+
unzip -q /data/ROOT.war -d /usr/local/tomcat/webapps/ROOT
18+
}
19+
20+
setup_linux_logging_paths() {
21+
#Replace Mac logging paths with linux based paths
22+
echo_time "Set logging file paths to use linux file paths"
23+
sed -i s#/Library/JSS/Logs#/usr/local/tomcat/logs# /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j.properties
24+
}
25+
26+
setup_stdout_logging() {
27+
STDOUT_LOGGING=${STDOUT_LOGGING:-true}
28+
if [[ $STDOUT_LOGGING == "true" ]]; then
29+
#Add stdout output for Jamf specific log files while maintaining logging to the files
30+
echo_time "STDOUT_LOGGING is true, add stdout logging for all logfiles"
31+
sed -e '/log4j.rootLogger/ {r /log4j.stdout.replace
32+
d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j.properties
33+
fi
34+
}
35+
36+
setup_remote_database() {
37+
DATABASE_HOST=${DATABASE_HOST:-localhost}
38+
DATABASE_NAME=${DATABASE_NAME:-jamfsoftware}
39+
DATABASE_USERNAME=${DATABASE_USERNAME:-jamfsoftware}
40+
DATABASE_PASSWORD=${DATABASE_PASSWORD:-jamfsw03}
41+
DATABASE_PORT=${DATABASE_PORT:-3306}
42+
43+
echo_time "\n\nDatabase connection information: \n DATABASE_HOST: $DATABASE_HOST \n DATABASE_NAME: $DATABASE_NAME \n DATABASE_USERNAME: $DATABASE_USERNAME\n\n"
44+
45+
echo_time "Setting up the DataBase.xml file to use remote MySQL database"
46+
if [ ! -f "/usr/local/tomcat/webapps/ROOT/WEB-INF/xml/DataBase.xml" ]; then
47+
echo_time "FATAL ERROR: DataBase.xml not where expected, cannot continue"
48+
exit 1
49+
else
50+
sed -i s#\<ServerName.*#\<ServerName\>$DATABASE_HOST\</ServerName\># /usr/local/tomcat/webapps/ROOT/WEB-INF/xml/DataBase.xml
51+
sed -i s#\<DataBaseName.*#\<DataBaseName\>$DATABASE_NAME\</DataBaseName\># /usr/local/tomcat/webapps/ROOT/WEB-INF/xml/DataBase.xml
52+
sed -i s#\<DataBaseUser.*#\<DataBaseUser\>$DATABASE_USERNAME\</DataBaseUser\># /usr/local/tomcat/webapps/ROOT/WEB-INF/xml/DataBase.xml
53+
sed -i s#\<DataBasePassword.*#\<DataBasePassword\>$DATABASE_PASSWORD\</DataBasePassword\># /usr/local/tomcat/webapps/ROOT/WEB-INF/xml/DataBase.xml
54+
sed -i s#\<ServerPort.*#\<ServerPort\>$DATABASE_PORT\</ServerPort\># /usr/local/tomcat/webapps/ROOT/WEB-INF/xml/DataBase.xml
55+
fi
56+
}
57+
58+
setup_jmx_remote_opts() {
59+
JMXREMOTE_OPTS=${JMXREMOTE_OPTS:-}
60+
JMXREMOTE=${JMXREMOTE:-false}
61+
62+
if [[ $JMXREMOTE == "true" ]]; then
63+
echo_time "JMX is set to enabled, parsing environment variable settings"
64+
JMXREMOTE_PORT=${JMXREMOTE_PORT:-}
65+
JMXREMOTE_RMI_PORT=${JMXREMOTE_RMI_PORT:-}
66+
JMXREMOTE_SSL=${JMXREMOTE_SSL:-}
67+
JMXREMOTE_AUTHENTICATE=${JMXREMOTE_AUTHENTICATE:-}
68+
RMI_SERVER_HOSTNAME=${RMI_SERVER_HOSTNAME:-}
69+
JMXREMOTE_PASSWORD_FILE=${JMXREMOTE_PASSWORD_FILE:-}
70+
71+
echo_time "\n\nJMX connection information:\n JMXREMOTE: $JMXREMOTE \n JMXREMOTE_PORT: $JMXREMOTE_PORT \n JMXREMOTE_RMI_PORT: $JMXREMOTE_RMI_PORT \n JMXREMOTE_SSL: $JMXREMOTE_SSL \n JMXREMOTE_AUTHENTICATE: $JMXREMOTE_AUTHENTICATE \n RMI_SERVER_HOSTNAME: $RMI_SERVER_HOSTNAME \n JMXREMOTE_PASSWORD_FILE: $JMXREMOTE_PASSWORD_FILE \n\n"
72+
73+
JMXREMOTE_OPTS="${JMXREMOTE_OPTS} -Dcom.sun.management.jmxremote"
74+
JMXREMOTE_OPTS="${JMXREMOTE_OPTS} -Dcom.sun.management.jmxremote.port=${JMXREMOTE_PORT}"
75+
JMXREMOTE_OPTS="${JMXREMOTE_OPTS} -Dcom.sun.management.jmxremote.rmi.port=${JMXREMOTE_RMI_PORT}"
76+
JMXREMOTE_OPTS="${JMXREMOTE_OPTS} -Dcom.sun.management.jmxremote.ssl=${JMXREMOTE_SSL}"
77+
JMXREMOTE_OPTS="${JMXREMOTE_OPTS} -Dcom.sun.management.jmxremote.authenticate=${JMXREMOTE_AUTHENTICATE}"
78+
JMXREMOTE_OPTS="${JMXREMOTE_OPTS} -Djava.rmi.server.hostname=${RMI_SERVER_HOSTNAME}"
79+
JMXREMOTE_OPTS="${JMXREMOTE_OPTS} -Dcom.sun.management.jmxremote.password.file=${JMXREMOTE_PASSWORD_FILE}"
80+
fi
81+
}
82+
83+
setup_java_opts() {
84+
echo_time "Setting CATALINA_OPTS and JAVA_OPTS"
85+
86+
CATALINA_OPTS=${CATALINA_OPTS:-}
87+
JAVA_OPTS=${JAVA_OPTS:-"-Djava.awt.headless=true"}
88+
89+
export JAVA_OPTS="${JAVA_OPTS} ${CATALINA_OPTS} ${JMXREMOTE_OPTS}"
90+
91+
echo_time "\n\nJAVA_OPTS: $JAVA_OPTS \n\n"
92+
}
93+
94+
##########################################################
95+
####################### Executions #######################
96+
97+
echo_time "Check if Tomcat ROOT directory exists, will NOT overwrite if exists"
98+
if [ ! -d /usr/local/tomcat/webapps/ROOT ]; then
99+
echo_time "/usr/local/tomcat/webapps/ROOT directory does not exist, attempt to deploy ROOT.war from /data"
100+
unpack_root_war
101+
102+
setup_stdout_logging
103+
else
104+
echo_time "/usr/local/tomcat/webapps/ROOT exists, skipping ROOT.war deploy"
105+
fi
106+
107+
setup_linux_logging_paths
108+
109+
setup_remote_database
110+
111+
setup_jmx_remote_opts
112+
113+
setup_java_opts
114+
115+
116+
##########################################################

log4j.stdout.replace

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
log4j.rootLogger=INFO,JAMF,stdout
2+
3+
# Direct log messages to stdout
4+
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
5+
log4j.appender.stdout.Target=System.out
6+
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
7+
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

startup.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
RUN_USER=${RUN_USER:=tomcat}
4+
RUN_GROUP=${RUN_GROUP:=tomcat}
5+
6+
source /configuration.sh
7+
8+
if [ $? -gt 0 ]; then
9+
exit $?
10+
fi
11+
12+
# Start Tomcat as the correct user.
13+
if [ "${UID}" -eq 0 ]; then
14+
echo "User is currently root. Will change directory ownership to ${RUN_USER}:${RUN_GROUP}, then downgrade permission to ${RUN_USER}"
15+
PERMISSIONS_SIGNATURE=$(stat -c "%u:%U:%a" "${CATALINA_HOME}")
16+
EXPECTED_PERMISSIONS=$(id -u ${RUN_USER}):${RUN_USER}:700
17+
if [ "${PERMISSIONS_SIGNATURE}" != "${EXPECTED_PERMISSIONS}" ]; then
18+
echo "Updating permissions for CATALINA_HOME"
19+
chmod -R 700 "${CATALINA_HOME}" &&
20+
chown -R "${RUN_USER}:${RUN_GROUP}" "${CATALINA_HOME}"
21+
fi
22+
# Now drop privileges
23+
exec su -s /bin/bash "${RUN_USER}" -c "/usr/local/tomcat/bin/catalina.sh run"
24+
else
25+
exec /usr/local/tomcat/bin/catalina.sh run
26+
fi
27+

0 commit comments

Comments
 (0)