Skip to content

Commit d7b49f5

Browse files
maximthomasvharseko
authored andcommitted
OpenDJ Openshift Template
1 parent 0d7d085 commit d7b49f5

File tree

9 files changed

+496
-33
lines changed

9 files changed

+496
-33
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ matrix:
3636
- "opendj-packages/opendj-rpm/opendj-rpm-standard/target/rpm/opendj/RPMS/noarch/*.rpm"
3737
- "opendj-packages/opendj-msi/opendj-msi-standard/target/*.msi"
3838
- "opendj-packages/opendj-docker/target/Dockerfile"
39+
- "opendj-packages/opendj-openshift-template/*.yaml"
3940
- "opendj-doc-generated-ref/target/*.zip"
4041
- "opendj-dsml-servlet/target/*.war"
4142
- "opendj-rest2ldap-servlet/target/*.war"
@@ -94,4 +95,4 @@ install:
9495
- mvn -q -B -V -DskipTests -Dmaven.javadoc.skip=true install -f forgerock-parent
9596
script:
9697
- echo "mvn -B install $INSTALL_SUFFIX"
97-
- eval "mvn -B install $INSTALL_SUFFIX"
98+
- eval "mvn -B install $INSTALL_SUFFIX"

opendj-packages/opendj-docker/Dockerfile

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,51 @@ FROM java:8
22

33
MAINTAINER Open Identity Platform Community <open-identity-platform-opendj@googlegroups.com>
44

5-
ARG ADD_BASE_ENTRY="--addBaseEntry"
5+
ENV ADD_BASE_ENTRY="--addBaseEntry"
66

7-
ARG PORT=1389
7+
ENV PORT=1389
88

9-
ARG LDAPS_PORT=1636
9+
ENV LDAPS_PORT=1636
1010

11-
ARG BASE_DN="dc=example,dc=com"
11+
ENV BASE_DN=${BASE_DN:-"dc=example,dc=com"}
1212

13-
ARG ROOT_USER_DN="cn=Directory Manager"
13+
ENV ROOT_USER_DN=${ROOT_USER_DN:-"cn=Directory Manager"}
1414

15-
ARG ROOT_PASSWORD=password
15+
ENV ROOT_PASSWORD=${ROOT_PASSWORD:-"password"}
1616

17-
ARG VERSION=@project_version@
17+
ENV SECRET_VOLUME=${SECRET_VOLUME}
1818

19-
ARG OPENDJ_USER="opendj"
19+
ENV MASTER_SERVER=${MASTER_SERVER}
2020

21-
WORKDIR /opt
21+
ENV OPENDJ_REPLICATION_TYPE=${OPENDJ_REPLICATION_TYPE}
22+
23+
ENV VERSION=@project_version@
24+
25+
#ENV VERSION=4.3.1
2226

23-
RUN apt-get install -y wget unzip
27+
ENV OPENDJ_USER="opendj"
2428

25-
RUN wget --quiet \
29+
WORKDIR /opt
30+
31+
RUN wget --show-progress --progress=bar:force:noscroll --quiet \
2632
https://github.com/OpenIdentityPlatform/OpenDJ/releases/download/$VERSION/opendj-$VERSION.zip && \
2733
unzip opendj-$VERSION.zip && \
2834
rm -r opendj-$VERSION.zip
2935

30-
RUN useradd -m -r -u 1001 -g root $OPENDJ_USER
36+
RUN echo "/opt/opendj/data" > /opt/opendj/instance.loc && \
37+
mkdir -p /opt/opendj/data/lib/extensions
3138

32-
RUN chgrp -R 0 /opt/opendj && \
33-
chmod -R g=u /opt/opendj
39+
ADD bootstrap/ /opt/opendj/bootstrap/
3440

35-
USER $OPENDJ_USER
41+
ADD run.sh /opt/opendj/run.sh
42+
43+
RUN useradd -m -r -u 1001 -G root,sudo $OPENDJ_USER
3644

37-
RUN /opt/opendj/setup --cli -p $PORT --ldapsPort $LDAPS_PORT --enableStartTLS \
38-
--generateSelfSignedCertificate --baseDN "$BASE_DN" -h localhost --rootUserDN "$ROOT_USER_DN" \
39-
--rootUserPassword "$ROOT_PASSWORD" --acceptLicense --no-prompt --doNotStart $ADD_BASE_ENTRY
45+
RUN chgrp -R 0 /opt/opendj && \
46+
chmod -R g=u /opt/opendj
4047

4148
EXPOSE $PORT $LDAPS_PORT 4444
4249

43-
CMD ["/opt/opendj/bin/start-ds", "--nodetach"
50+
USER $OPENDJ_USER
51+
52+
ENTRYPOINT ["/opt/opendj/run.sh"]
Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
# How-to:
22
Build docker image:
3-
4-
docker build . -t openidentityplatform/opendj
5-
3+
```bash
4+
docker build . -t openidentityplatform/opendj
5+
```
66
Run image
7+
```bash
8+
docker run -d -p 1389:1389 -p 1636:1636 -p 4444:4444 --name opendj openidentityplatform/opendj
9+
```
10+
11+
## Environment Variables
712

8-
docker run -d -p 1389:1389 -p 1636:1636 -p 4444:4444 --name opendj openidentityplatform/opendj
13+
|Variable|Default Value|Description|
14+
|--------|-------------|-----------|
15+
|ADD_BASE_ENTRY|--addBaseEntry|if set, creates base DN entry|
16+
|PORT|1389|LDAP Listener Port|
17+
|LDAPS_PORT|1636|LDAPS Listener Port|
18+
|BASE_DN|dc=example,dc=com|OpenDJ Base DN |
19+
|ROOT_USER_DN|cn=Directory Manager|Initial root user DN|
20+
|ROOT_PASSWORD|password|Initial root user password|
21+
|SECRET_VOLUME|-|Mounted keystore volume, if present copies keystore over|
22+
|MASTER_SERVER|-|Replication master server|
23+
|VERSION|4.3.1|OpenDJ version|
24+
|OPENDJ_USER|-|user which runs OpenDJ|
25+
|OPENDJ_REPLICATION_TYPE|-|OpenDJ Replication type, valid values are: <ul><li>simple - standart replication</li><li>srs - standalone replication servers</li><li>sdsr - Standalone Directory Server Replicas</li><li>rg - Replication Groups</li></ul>Other values will be ignored|
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#!/usr/bin/env bash
2+
# Replicate to the master server hostname defined in $1
3+
# If that server is ourself this is a no-op
4+
5+
# This is a bit kludgy.
6+
# The hostname has to be a fully resolvable DNS name in the cluster
7+
# If the service is called
8+
9+
MYHOSTNAME=${MYHOSTNAME:-`hostname -f`}
10+
11+
echo "Setting up replication from $MYHOSTNAME to $MASTER_SERVER"
12+
13+
# For debug
14+
15+
# K8s puts the service name in /etc/hosts
16+
if grep ${MASTER_SERVER} /etc/hosts; then
17+
echo "We are the master. Skipping replication setup to ourself"
18+
exit 0
19+
fi
20+
21+
# Comment out
22+
echo "replicate ENV vars:"
23+
env
24+
25+
# todo: Replace with command to test for master being reachable and up
26+
# This is hacky....
27+
echo "Will sleep for a bit to ensure master is up"
28+
29+
sleep 5
30+
31+
if [ "$OPENDJ_REPLICATION_TYPE" == "simple" ] then
32+
echo "Enabling Standart Replication..."
33+
/opt/opendj/bin/dsreplication enable --host1 $MYHOSTNAME --port1 4444 \
34+
--bindDN1 "$ROOT_USER_DN" \
35+
--bindPassword1 $ROOT_PASSWORD --replicationPort1 8989 \
36+
--host2 $MASTER_SERVER --port2 4444 --bindDN2 "$ROOT_USER_DN" \
37+
--bindPassword2 $ROOT_PASSWORD --replicationPort2 8989 \
38+
--adminUID admin --adminPassword $ROOT_PASSWORD --baseDN $BASE_DN -X -n
39+
40+
echo "initializing replication"
41+
42+
/opt/opendj/bin/dsreplication initialize --baseDN $BASE_DN \
43+
--adminUID admin --adminPassword $ROOT_PASSWORD \
44+
--hostSource $MYHOSTNAME --portSource 4444 \
45+
--hostDestination $MASTER_SERVER --portDestination 4444 -X -n
46+
47+
elif [ "$OPENDJ_REPLICATION_TYPE" == "srs" ] then
48+
echo "Enabling Standalone Replication Servers..."
49+
dsreplication enable \
50+
--adminUID admin \
51+
--adminPassword $ROOT_PASSWORD \
52+
--baseDN $BASE_DN \
53+
--host1 $MYHOSTNAME \
54+
--port1 4444 \
55+
--bindDN1 "$ROOT_USER_DN" \
56+
--bindPassword1 $ROOT_PASSWORD \
57+
--noReplicationServer1 \
58+
--host2 $MASTER_SERVER \
59+
--port2 4444 \
60+
--bindDN2 "$ROOT_USER_DN" \
61+
--bindPassword2 $ROOT_PASSWORD \
62+
--replicationPort2 8989 \
63+
--onlyReplicationServer2 \
64+
--trustAll \
65+
--no-prompt;
66+
67+
echo "initializing replication"
68+
69+
dsreplication \
70+
initialize-all \
71+
--adminUID admin \
72+
--adminPassword $ROOT_PASSWORD \
73+
--baseDN $BASE_DN \
74+
--hostname $MYHOSTNAME \
75+
--port 4444 \
76+
--trustAll \
77+
--no-prompt
78+
79+
elif [ "$OPENDJ_REPLICATION_TYPE" == "sdsr" ] then
80+
echo "Enabling Standalone Directory Server Replicas...."
81+
dsreplication \
82+
enable \
83+
--adminUID admin \
84+
--adminPassword $ROOT_PASSWORD \
85+
--baseDN $BASE_DN \
86+
--host1 $MASTER_SERVER \
87+
--port1 4444 \
88+
--bindDN1 "$ROOT_USER_DN" \
89+
--bindPassword1 $ROOT_PASSWORD \
90+
--host2 $MYHOSTNAME \
91+
--port2 4444 \
92+
--bindDN2 "$ROOT_USER_DN" \
93+
--bindPassword2 ROOT_PASSWORD \
94+
--noReplicationServer2 \
95+
--trustAll \
96+
--no-prompt
97+
98+
echo "initializing replication"
99+
100+
dsreplication \
101+
initialize \
102+
--adminUID admin \
103+
--adminPassword $ROOT_PASSWORD \
104+
--baseDN $BASE_DN \
105+
--hostSource $MASTER_SERVER \
106+
--portSource 4444 \
107+
--hostDestination $MYHOSTNAME \
108+
--portDestination 4444 \
109+
--trustAll \
110+
--no-prompt
111+
112+
elif [ "$OPENDJ_REPLICATION_TYPE" == "rg" ] then
113+
echo "Enabling Replication Groups..."
114+
115+
dsconfig \
116+
set-replication-domain-prop \
117+
--port 4444 \
118+
--hostname $MYHOSTNAME \
119+
--bindDN "$ROOT_USER_DN" \
120+
--bindPassword $ROOT_PASSWORD \
121+
--provider-name "Multimaster Synchronization" \
122+
--domain-name $BASE_DN \
123+
--set group-id:$OPENDJ_REPLICATION_GROUP_ID \
124+
--trustAll \
125+
--no-prompt
126+
127+
dsconfig \
128+
set-replication-server-prop \
129+
--port 4444 \
130+
--hostname $MASTER_SERVER \
131+
--bindDN "$ROOT_USER_DN" \
132+
--bindPassword $ROOT_PASSWORD \
133+
--provider-name "Multimaster Synchronization" \
134+
--set group-id:$OPENDJ_REPLICATION_GROUP_ID \
135+
--trustAll \
136+
--no-prompt
137+
138+
else
139+
echo "Unknown replication type, skiping replication..."
140+
fi
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
# Default setup script
3+
4+
echo "Setting up default OpenDJ instance"
5+
6+
# If any optional LDIF files are present load them
7+
8+
/opt/opendj/setup --cli -p $PORT --ldapsPort $LDAPS_PORT --enableStartTLS --generateSelfSignedCertificate \
9+
--baseDN $BASE_DN -h localhost --rootUserPassword "$ROOT_PASSWORD" \
10+
--acceptLicense --no-prompt $ADD_BASE_ENTRY #--sampleData 1
11+
12+
13+
if [ -d /opt/opendj/bootstrap/schema/ ]; then
14+
echo "Loading initial schema:"
15+
for file in /opt/opendj/bootstrap/schema/*; do
16+
echo "Loading $file ..."
17+
/opt/opendj/bin/ldapmodify -D "$ROOT_USER_DN" -h localhost -p $PORT -w $ROOT_PASSWORD -f $file
18+
done
19+
fi
20+
21+
if [ -d /opt/opendj/bootstrap/data/ ]; then
22+
echo "Loading initial data:"
23+
for file in /opt/opendj/bootstrap/data/*; do
24+
echo "Loading $file ..."
25+
/opt/opendj/bin/ldapmodify -D "$ROOT_USER_DN" -h localhost -p $PORT -w $ROOT_PASSWORD -f $file
26+
done
27+
fi

opendj-packages/opendj-docker/pom.xml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Header, with the fields enclosed by brackets [] replaced by your own identifying
1313
information: "Portions Copyright [year] [name of copyright owner]".
1414
15-
Copyright 2015-2016 ForgeRock AS.
15+
Copyright 2018-2019 Open Identity Platform Community.
1616
-->
1717
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1818
<modelVersion>4.0.0</modelVersion>
@@ -40,20 +40,22 @@
4040
</description>
4141

4242
<build>
43-
<plugins>
44-
<plugin>
43+
<plugins>
44+
<plugin>
4545
<artifactId>maven-antrun-plugin</artifactId>
4646
<executions>
4747
<execution>
4848
<phase>prepare-package</phase>
4949
<configuration>
5050
<tasks>
5151
<copy todir="${project.build.directory}">
52-
<fileset dir="${basedir}">
53-
<include name="Dockerfile" /> <!--NOTE DIFFERENCE HERE-->
54-
</fileset>
55-
</copy>
56-
<replace token="@project_version@" value="${project.version}" dir="target/">
52+
<fileset dir="${basedir}">
53+
<include name="Dockerfile" /> <!--NOTE DIFFERENCE HERE-->
54+
<include name="bootstrap/**" />
55+
<include name="run.sh" />
56+
</fileset>
57+
</copy>
58+
<replace token="@project_version@" value="${project.version}" dir="target/">
5759
<include name="Dockerfile" />
5860
</replace>
5961
</tasks>
@@ -64,6 +66,6 @@
6466
</execution>
6567
</executions>
6668
</plugin>
67-
</plugins>
69+
</plugins>
6870
</build>
6971
</project>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env bash
2+
# Run the OpenDJ server
3+
# The idea is to consolidate all of the writable DJ directories to
4+
# a single instance directory root, and update DJ's instance.loc file to point to that root
5+
# This allows us to to mount a data volume on that root which gives us
6+
# persistence across restarts of OpenDJ.
7+
# For Docker - mount a data volume on /opt/opendj/data
8+
# For Kubernetes mount a PV
9+
10+
11+
cd /opt/opendj
12+
13+
14+
# Instance dir does not exist? Then we need to run setup
15+
if [ ! -d ./data/config ] ; then
16+
17+
echo "Instance data Directory is empty. Creating new DJ instance"
18+
19+
BOOTSTRAP=${BOOTSTRAP:-/opt/opendj/bootstrap/setup.sh}
20+
21+
export BASE_DN=${BASE_DN:-"dc=example,dc=com"}
22+
echo "BASE DN is ${BASE_DN}"
23+
24+
export PASSWORD=${ROOT_PASSWORD:-password}
25+
26+
echo "Password set to $PASSWORD"
27+
28+
echo "Running $BOOTSTRAP"
29+
sh "${BOOTSTRAP}"
30+
31+
# Check if OPENDJ_REPLICATION_TYPE var is set. If it is - replicate to that server
32+
if [ ! -z ${MASTER_SERVER} ] && [ ! -z ${OPENDJ_REPLICATION_TYPE} ]; then
33+
/opt/opendj/bootstrap/replicate.sh
34+
fi
35+
else
36+
exec ./bin/start-ds --nodetach
37+
return
38+
fi
39+
40+
# Check if keystores are mounted as a volume, and if so
41+
# Copy any keystores over
42+
SECRET_VOLUME=${SECRET_VOLUME:-/var/secrets/opendj}
43+
44+
if [ -d "${SECRET_VOLUME}" ]; then
45+
echo "Secret volume is present. Will copy any keystores and truststore"
46+
# We send errors to /dev/null in case no data exists.
47+
cp -f ${SECRET_VOLUME}/key* ${SECRET_VOLUME}/trust* ./data/config 2>/dev/null
48+
fi
49+
50+
# todo: Check /opt/opendj/data/config/buildinfo
51+
# Run upgrade if the server is older
52+
53+
if (bin/status -n | grep Started) ; then
54+
echo "OpenDJ is started"
55+
# We cant exit because we are pid 1
56+
while true; do sleep 100000; done
57+
fi
58+
59+
60+
echo "Starting OpenDJ"
61+
62+
#
63+
64+
exec ./bin/start-ds --nodetach

0 commit comments

Comments
 (0)