From 4f353a47d9f2193a4c8843d7c9e900066e56d7b6 Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 20 Jan 2022 09:53:06 +0100 Subject: [PATCH] Add docker files --- .gitlab-ci.yml | 25 +++++++++++++++++++++++++ Dockerfile | 19 +++++++++++++++++++ start.sh | 18 ++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100644 Dockerfile create mode 100644 start.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..0a4f3ec --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,25 @@ +docker-build: + image: docker:latest + stage: build + services: + - docker:dind + before_script: + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY + # Default branch leaves tag empty (= latest tag) + # All other branches are tagged with the escaped branch name (commit ref slug) + script: + - | + if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then + tag="" + echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'" + else + tag=":$CI_COMMIT_REF_SLUG" + echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag" + fi + - docker build --pull -t "$CI_REGISTRY_IMAGE${tag}" . + - docker push "$CI_REGISTRY_IMAGE${tag}" + # Run this job in a branch where a Dockerfile exists + rules: + - if: $CI_COMMIT_BRANCH + exists: + - Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..95007fc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM debian:bullseye-slim + +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update && apt-get install --no-install-recommends -y slapd fusiondirectory-schema fusiondirectory-plugin-mail-schema ldap-utils +ENV DEBIAN_FRONTEND=readline +RUN rm -rf /etc/ldap/slapd.d/* /var/lib/ldap/* + + +EXPOSE 389 636 + +ENV URL="ldap:/// ldapi:///" +ENV CONF_DIR="/etc/ldap/slapd.d" +ENV DB_DIR="/var/lib/ldap" +ENV DEBUG_LEVEL="0" + +COPY ./start.sh /root/start.sh +RUN chmod +x /root/start.sh + +ENTRYPOINT ["/root/start.sh"] diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..4648998 --- /dev/null +++ b/start.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +if [ -z "$(ls -A "$CONF_DIR")" ] || [ -z "$(ls -A "$DB_DIR")" ]; then + echo "Reconfigure slapd" + dpkg-reconfigure -plow slapd + + echo "Insert fusiondirectory schema" + slapd -F "$CONF_DIR" -u openldap -g openldap -h "$URL" -d "$DEBUG_LEVEL" & + slapd_pid=$! + sleep 2 + fusiondirectory-insert-schema + kill -9 "$slapd_pid" + sleep 2 +fi + +echo "Starting slapd" +slapd -F "$CONF_DIR" -u openldap -g openldap -h "$URL" -d "$DEBUG_LEVEL" +echo "Slapd exited with code $?"