Improve docker image to make it smaller

This commit is contained in:
Benjamin Renard 2024-02-22 16:57:18 +01:00
parent 753f47fa97
commit 15f67ef00d
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC
6 changed files with 61 additions and 39 deletions

View file

@ -1,37 +1,55 @@
# Update/upgrade ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get upgrade -y # Update/upgrade, configure LdapSaisie APT repo and install dependencies
# Install LdapSaisie APT repository RUN apt-get update && \
RUN apt-get install -y --force-yes wget gnupg lsb-release apt-get upgrade -y && \
RUN wget -O - http://ldapsaisie.org/debian/ldapsaisie.gpg.key | apt-key add - apt-get install -y --force-yes wget gnupg lsb-release && \
RUN echo "deb http://ldapsaisie.org/debian $( lsb_release -c -s ) main" > /etc/apt/sources.list.d/ldapsaisie.list wget -O - http://ldapsaisie.org/debian/ldapsaisie.gpg.key | apt-key add - && \
RUN apt-get update echo "deb http://ldapsaisie.org/debian $( lsb_release -c -s ) main" > /etc/apt/sources.list.d/ldapsaisie.list && \
# Install dependencies apt-get update && \
RUN DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt-get install -y git slapd apache2 php-ldap libapache2-mod-php php-cli smarty3 php-net-ldap2 php-net-ftp php-mail php-mail-mime php-console-table ldapvi locales sed bash-completion liquidprompt vim curl jq iproute2 net-tools composer php-cas php-zxcvbn php-phpseclib php-zip apt-get install -y \
# Add fr_FR* locales git \
RUN sed -i 's/^# fr_FR/fr_FR/' /etc/locale.gen slapd \
RUN locale-gen apache2 \
# Clone sources php-ldap \
RUN git clone https://gitlab.easter-eggs.com/ee/ldapsaisie.git /var/www/ldapsaisie libapache2-mod-php \
# Fix www-data permission on temporary directory php-cli \
RUN chown www-data: -R /var/www/ldapsaisie/src/tmp/ smarty3 \
# Configure slapd and load lsexample directory php-net-ldap2 \
RUN killall slapd || echo slapd is not running php-net-ftp \
RUN /var/www/ldapsaisie/lsexample/restore_lsexample -v php-mail \
# Configure and enable ldapsaisie VirtualHost (as default) php-mail-mime \
RUN a2dissite 000-default php-html2text \
COPY apache2.conf /etc/apache2/sites-available/ldapsaisie.conf php-console-table \
RUN a2ensite ldapsaisie ldapvi \
RUN a2enmod rewrite locales \
RUN service apache2 restart sed \
# Install ldapsaisie binary (with its bash-completion config) bash-completion \
RUN ln -s /var/www/ldapsaisie/src/bin/ldapsaisie.php /usr/local/sbin/ldapsaisie liquidprompt \
RUN ln -s /var/www/ldapsaisie/debian/ldapsaisie.bash-completion /usr/share/bash-completion/completions/ldapsaisie vim \
# Install vimrc.local file curl \
COPY vimrc.local /etc/vim/vimrc.local jq \
iproute2 \
net-tools \
composer \
php-cas \
php-zxcvbn \
php-phpseclib \
php-zip && \
apt-get clean && \
rm -fr rm -rf /var/lib/apt/lists/*
COPY rootfs /
# Install LdapSaisie from sources, configure slapd and load lsexample directory
RUN git clone https://gitlab.easter-eggs.com/ee/ldapsaisie.git /var/www/ldapsaisie && \
ln -s /var/www/ldapsaisie/src/bin/ldapsaisie.php /usr/local/sbin/ldapsaisie && \
ln -s /var/www/ldapsaisie/debian/ldapsaisie.bash-completion /usr/share/bash-completion/completions/ldapsaisie && \
chown www-data: -R /var/www/ldapsaisie/src/tmp/ && \
sed -i 's/^# fr_FR/fr_FR/' /etc/locale.gen && \
locale-gen && \
a2dissite 000-default && \
a2ensite ldapsaisie && \
a2enmod rewrite && \
/var/www/ldapsaisie/lsexample/restore_lsexample -v
# Install entrypoint # Install entrypoint
COPY bashrc /root/.bashrc ENTRYPOINT /entrypoint.sh
COPY entrypoint.sh /usr/local/sbin/entrypoint.sh
RUN echo "ldapsaisie-dev" > /etc/hostname
ENTRYPOINT /usr/local/sbin/entrypoint.sh
EXPOSE 80 389 EXPOSE 80 389

12
docker/build-and-push-all.sh Normal file → Executable file
View file

@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
cd $( dirname $0 ) cd $( dirname $0 )
DIST="$1"
# Need to use Dockerfile+ (https://github.com/edrevo/dockerfile-plus) # Need to use Dockerfile+ (https://github.com/edrevo/dockerfile-plus)
export DOCKER_BUILDKIT=1 export DOCKER_BUILDKIT=1
@ -10,9 +11,12 @@ LATEST_DIST=${DISTS[0]}
for dist in ${DISTS[@]} for dist in ${DISTS[@]}
do do
docker build -t brenard/ldapsaisie:$dist -f Dockerfile.$dist . [ -n "$DIST" -a "$DIST" != "$dist" ] && continue
[ $? -eq 0 ] && docker push brenard/ldapsaisie:$dist docker build -t docker.io/brenard/ldapsaisie:$dist -f Dockerfile.$dist .
[ $? -eq 0 ] && docker push docker.io/brenard/ldapsaisie:$dist
done done
docker build -t brenard/ldapsaisie:latest -f Dockerfile.$LATEST_DIST . [ -n "$DIST" -a "$DIST" != "latest" ] && exit
[ $? -eq 0 ] && docker push brenard/ldapsaisie:latest
docker build -t docker.io/brenard/ldapsaisie:latest -f Dockerfile.$LATEST_DIST .
[ $? -eq 0 ] && docker push docker.io/brenard/ldapsaisie:latest