Browse Source

Merge branch 'ldapadd' of https://github.com/bersace/docker-openldap into bersace-ldapadd

Bertrand Gouny 8 years ago
parent
commit
dc5fbb9de6
2 changed files with 22 additions and 1 deletions
  1. 17 0
      README.md
  2. 5 1
      image/service/slapd/startup.sh

+ 17 - 0
README.md

@@ -104,6 +104,23 @@ For more information about docker data volume, please refer to:
 
 Do not edit slapd.conf it's not used. To modify your server configuration use ldap utils: **ldapmodify / ldapadd / ldapdelete**
 
+#### Seed ldap database with ldif
+
+This image can load ldif files at startup with either `ldapadd` or `ldapmodify`.
+Mount `.ldif` in `/container/service/slapd/assets/config/bootstrap/ldif/`
+directory. Files containing `changeType:` attributes will be loaded with `ldapmodify`.
+
+The startup script provide some substitution in bootstrap ldif files: `{{
+LDAP_BASE_DN }}` and `{{ LDAP_BACKEND }}` values are supported. Other `{{ * }}`
+substitution are left as is.
+
+Since startup script modifies `ldif` files, you **must** add `--copy-service`
+argument to entrypoint.
+
+    docker run \
+      --volume ./bootstrap.ldif:/container/service/slapd/assets/config/bootstrap/ldif/50-bootstrap.ldif \
+      osixia/openldap:1.1.9 --copy-service
+
 ### Use an existing ldap database
 
 This can be achieved by mounting host directories as volume.

+ 5 - 1
image/service/slapd/startup.sh

@@ -229,7 +229,11 @@ EOF
         log-helper debug "Processing file ${f}"
         sed -i "s|{{ LDAP_BASE_DN }}|${LDAP_BASE_DN}|g" $f
         sed -i "s|{{ LDAP_BACKEND }}|${LDAP_BACKEND}|g" $f
-        ldapmodify -Y EXTERNAL -Q -H ldapi:/// -f $f 2>&1 | log-helper debug || ldapmodify -h localhost -p 389 -D cn=admin,$LDAP_BASE_DN -w $LDAP_ADMIN_PASSWORD -f $f 2>&1 | log-helper debug
+        if grep -iq changetype $f ; then
+            ldapmodify -Y EXTERNAL -Q -H ldapi:/// -f $f 2>&1 | log-helper debug || ldapmodify -h localhost -p 389 -D cn=admin,$LDAP_BASE_DN -w $LDAP_ADMIN_PASSWORD -f $f 2>&1 | log-helper debug
+        else
+            ldapadd -Y EXTERNAL -Q -H ldapi:/// -f $f |& log-helper debug
+        fi
       done
 
       # read only user