Skip to content

Commit 135f4ec

Browse files
committed
Merge branch 'dbck-gitlab-ci-service-seeding' into release-1.5.0
2 parents ef475dd + e0dbde9 commit 135f4ec

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,14 @@ docker run \
184184

185185
#### Seed from internal path
186186

187-
This image can load ldif and schema files at startup from an internal path. This is useful if a continuous integration service mounts automatically the working copy (sources) into a docker service, which has a relation to the ci job.
187+
This image can load ldif and schema files at startup from an internal path. Additionally, certificates can be copied from an internal path. This is useful if a continuous integration service mounts automatically the working copy (sources) into a docker service, which has a relation to the ci job.
188188

189189
For example: Gitlab is not capable of mounting custom paths into docker services of a ci job, but Gitlab automatically mounts the working copy in every service container. So the working copy (sources) are accessible under `/builds` in every services
190190
of a ci job. The path to the working copy can be obtained via `${CI_PROJECT_DIR}`. See also: https://docs.gitlab.com/runner/executors/docker.html#build-directory-in-service
191191

192192
This may also work with other CI services, if they automatically mount the working directory to the services of a ci job like Gitlab ci does.
193193

194-
In order to seed ldif or schema files from internal path you must set the specific environment variable `LDAP_SEED_INTERNAL_LDIF_PATH` and/or `LDAP_SEED_INTERNAL_SCHEMA_PATH`. If set this will copy any *.ldif or *.schema file into the default seeding
194+
In order to seed ldif or schema files from internal path you must set the specific environment variable `LDAP_SEED_INTERNAL_LDIF_PATH` and/or `LDAP_SEED_INTERNAL_SCHEMA_PATH`. If set this will copy any files in the specified directory into the default seeding
195195
directories of this image.
196196

197197
Example variables defined in gitlab-ci.yml:
@@ -202,6 +202,14 @@ variables:
202202
LDAP_SEED_INTERNAL_SCHEMA_PATH: "${CI_PROJECT_DIR}/docker/openldap/schema"
203203
```
204204
205+
Also, certificates can be used by the internal path. The file, specified in a variable, will be copied in the default certificate directory of this image. If desired, you can use these with the LDAP_TLS_CRT_FILENAME, LDAP_TLS_KEY_FILENAME, LDAP_TLS_CA_CRT_FILENAME and LDAP_TLS_DH_PARAM_FILENAME to set a different filename in the default certificate directory of the image.
206+
207+
variables:
208+
LDAP_SEED_INTERNAL_LDAP_TLS_CRT_FILE: "${CI_PROJECT_DIR}/docker/certificates/certs/cert.pem"
209+
LDAP_SEED_INTERNAL_LDAP_TLS_KEY_FILE: "${CI_PROJECT_DIR}/docker/certificates/certs/key.pem"
210+
LDAP_SEED_INTERNAL_LDAP_TLS_CA_CRT_FILE: "${CI_PROJECT_DIR}/docker/certificates/ca/ca.pem"
211+
LDAP_SEED_INTERNAL_LDAP_TLS_DH_PARAM_FILE: "${CI_PROJECT_DIR}/certificates/dhparam.pem"
212+
205213
### Use an existing ldap database
206214
207215
This can be achieved by mounting host directories as volume.

image/environment/default.startup.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,9 @@ LDAP_SSL_HELPER_PREFIX: ldap # ssl-helper first search config from LDAP_SSL_HELP
6363
SSL_HELPER_AUTO_RENEW_SERVICES_IMPACTED: slapd
6464

6565
# Internal seeding. For example, for services in Gitlab CI.
66+
LDAP_SEED_INTERNAL_LDAP_TLS_CRT_FILE:
67+
LDAP_SEED_INTERNAL_LDAP_TLS_KEY_FILE:
68+
LDAP_SEED_INTERNAL_LDAP_TLS_CA_CRT_FILE:
69+
LDAP_SEED_INTERNAL_LDAP_TLS_DH_PARAM_FILE:
6670
LDAP_SEED_INTERNAL_LDIF_PATH:
6771
LDAP_SEED_INTERNAL_SCHEMA_PATH:

image/service/slapd/startup.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,28 @@ LDAP_TLS_CRT_PATH="${CONTAINER_SERVICE_DIR}/slapd/assets/certs/$LDAP_TLS_CRT_FIL
104104
LDAP_TLS_KEY_PATH="${CONTAINER_SERVICE_DIR}/slapd/assets/certs/$LDAP_TLS_KEY_FILENAME"
105105
LDAP_TLS_DH_PARAM_PATH="${CONTAINER_SERVICE_DIR}/slapd/assets/certs/$LDAP_TLS_DH_PARAM_FILENAME"
106106

107+
copy_internal_seed_if_exists() {
108+
local src=$1
109+
local dest=$2
110+
if [ ! -z "${src}" ]; then
111+
echo -e "Copy from internal path ${src} to ${dest}"
112+
cp -R ${src} ${dest}
113+
fi
114+
}
115+
116+
# Copy seed files from internal path if specified
117+
file_env 'LDAP_SEED_INTERNAL_LDAP_TLS_CRT_FILE'
118+
copy_internal_seed_if_exists "${LDAP_SEED_INTERNAL_LDAP_TLS_CRT_FILE}" "${LDAP_TLS_CRT_PATH}"
119+
file_env 'LDAP_SEED_INTERNAL_LDAP_TLS_KEY_FILE'
120+
copy_internal_seed_if_exists "${LDAP_SEED_INTERNAL_LDAP_TLS_KEY_FILE}" "${LDAP_TLS_KEY_PATH}"
121+
file_env 'LDAP_SEED_INTERNAL_LDAP_TLS_CA_CRT_FILE'
122+
copy_internal_seed_if_exists "${LDAP_SEED_INTERNAL_LDAP_TLS_CA_CRT_FILE}" "${LDAP_TLS_CA_CRT_PATH}"
123+
file_env 'LDAP_SEED_INTERNAL_LDAP_TLS_DH_PARAM_FILE'
124+
copy_internal_seed_if_exists "${LDAP_SEED_INTERNAL_LDAP_TLS_DH_PARAM_FILE}" "${LDAP_TLS_DH_PARAM_PATH}"
125+
file_env 'LDAP_SEED_INTERNAL_SCHEMA_PATH'
126+
copy_internal_seed_if_exists "${LDAP_SEED_INTERNAL_SCHEMA_PATH}" "${CONTAINER_SERVICE_DIR}/slapd/assets/config/bootstrap/schema/custom"
127+
file_env 'LDAP_SEED_INTERNAL_LDIF_PATH'
128+
copy_internal_seed_if_exists "${LDAP_SEED_INTERNAL_LDIF_PATH}" "${CONTAINER_SERVICE_DIR}/slapd/assets/config/bootstrap/ldif/custom"
107129

108130
# CONTAINER_SERVICE_DIR and CONTAINER_STATE_DIR variables are set by
109131
# the baseimage run tool more info : https://github.com/osixia/docker-light-baseimage

0 commit comments

Comments
 (0)