Don't install locales-all, generate only necessary locales

to reduce image size 654MB -> 462MB.
This commit is contained in:
Alexander A. Klimov 2022-12-21 18:01:13 +01:00
parent b8ee7008d1
commit 8ead644260
3 changed files with 42 additions and 2 deletions

View File

@ -8,9 +8,20 @@ WORKDIR /entrypoint
RUN ["go", "build", "."] RUN ["go", "build", "."]
FROM debian:bullseye-slim as etc-locale-gen
RUN ["bash", "-exo", "pipefail", "-c", "export DEBIAN_FRONTEND=noninteractive; apt-get update; apt-get install --no-install-{recommends,suggests} -y locales; apt-get clean; rm -vrf /var/lib/apt/lists/*"]
COPY icingaweb2 /usr/share/icingaweb2
COPY icinga-L10n /usr/share/icinga-L10n
COPY uncomment-locales.pl /
RUN ["/uncomment-locales.pl", "/etc/locale.gen"]
FROM debian:bullseye-slim FROM debian:bullseye-slim
RUN ["bash", "-exo", "pipefail", "-c", "export DEBIAN_FRONTEND=noninteractive; apt-get update; apt-get install --no-install-{recommends,suggests} -y apache2 ca-certificates libapache2-mod-php7.4 libldap-common locales-all php-{imagick,redis} php7.4-{bcmath,bz2,common,curl,dba,enchant,gd,gmp,imap,interbase,intl,json,ldap,mbstring,mysql,odbc,opcache,pgsql,pspell,readline,snmp,soap,sqlite3,sybase,tidy,xml,xmlrpc,xsl,zip}; apt-get clean; rm -vrf /var/lib/apt/lists/*"] RUN ["bash", "-exo", "pipefail", "-c", "export DEBIAN_FRONTEND=noninteractive; apt-get update; apt-get install --no-install-{recommends,suggests} -y apache2 ca-certificates libapache2-mod-php7.4 libldap-common locales php-{imagick,redis} php7.4-{bcmath,bz2,common,curl,dba,enchant,gd,gmp,imap,interbase,intl,json,ldap,mbstring,mysql,odbc,opcache,pgsql,pspell,readline,snmp,soap,sqlite3,sybase,tidy,xml,xmlrpc,xsl,zip}; apt-get clean; rm -vrf /var/lib/apt/lists/*"]
COPY --from=entrypoint /entrypoint/entrypoint /entrypoint COPY --from=entrypoint /entrypoint/entrypoint /entrypoint
COPY entrypoint/db-init /entrypoint-db-init COPY entrypoint/db-init /entrypoint-db-init
@ -38,6 +49,9 @@ COPY icinga-php /usr/share/icinga-php
COPY icinga-L10n /usr/share/icinga-L10n COPY icinga-L10n /usr/share/icinga-L10n
COPY php.ini /etc/php/7.4/cli/conf.d/99-docker.ini COPY php.ini /etc/php/7.4/cli/conf.d/99-docker.ini
COPY --from=etc-locale-gen /etc/locale.gen /etc/
RUN ["locale-gen", "-j", "4"]
RUN ["ln", "-vs", "/usr/share/icingaweb2/packages/files/apache/icingaweb2.conf", "/etc/apache2/conf-enabled/"] RUN ["ln", "-vs", "/usr/share/icingaweb2/packages/files/apache/icingaweb2.conf", "/etc/apache2/conf-enabled/"]
RUN ["ln", "-vs", "/usr/share/icingaweb2/bin/icingacli", "/usr/local/bin/"] RUN ["ln", "-vs", "/usr/share/icingaweb2/bin/icingacli", "/usr/local/bin/"]

View File

@ -33,6 +33,6 @@ cd /iw2cp
/bldctx/composer.bash /bldctx/composer.bash
patch -d icingaweb2 -p0 < /bldctx/icingaweb2.patch patch -d icingaweb2 -p0 < /bldctx/icingaweb2.patch
cp -r /entrypoint /bldctx/php.ini . cp -r /entrypoint /bldctx/{php.ini,uncomment-locales.pl} .
docker build -f /bldctx/Dockerfile -t icinga/icingaweb2 . docker build -f /bldctx/Dockerfile -t icinga/icingaweb2 .
EOF EOF

26
uncomment-locales.pl Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/perl -i
my %uniqLocs = ();
for my $subDir ('icinga-L10n', 'icingaweb2/modules/*/application') {
for my $lcDir (glob "/usr/share/$subDir/locale/*_*") {
if ($lcDir =~ /(\w+)$/) {
$uniqLocs{$1} = 1
}
}
}
my @locs = keys %uniqLocs;
while (<>) {
if (/\bUTF-8\b/) {
for my $loc (@locs) {
if (/\b$loc\b/) {
s/^# *//;
last
}
}
}
} continue {
print or die $!
}