Skip to content

Commit

Permalink
Don't install locales-all, generate only necessary locales
Browse files Browse the repository at this point in the history
to reduce image size 654MB -> 462MB.
  • Loading branch information
Al2Klimov committed Dec 22, 2022
1 parent b8ee700 commit 8ead644
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
16 changes: 15 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@ WORKDIR /entrypoint
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

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 entrypoint/db-init /entrypoint-db-init
Expand Down Expand Up @@ -38,6 +49,9 @@ COPY icinga-php /usr/share/icinga-php
COPY icinga-L10n /usr/share/icinga-L10n
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/bin/icingacli", "/usr/local/bin/"]

Expand Down
2 changes: 1 addition & 1 deletion build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ cd /iw2cp
/bldctx/composer.bash
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 .
EOF
26 changes: 26 additions & 0 deletions uncomment-locales.pl
Original file line number Diff line number Diff line change
@@ -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 $!
}

0 comments on commit 8ead644

Please sign in to comment.