Skip to content

Commit

Permalink
Reduce Docker image size. resolves wallabag#269
Browse files Browse the repository at this point in the history
Size (uncompressed): Previous 573.1 MB  /  This PR 225.8 MB
Container startup time is faster. Ansible was slow
Build time is 3 times faster. Less packages and TAR download
No changes required by the user. Same env vars, same paths, same core packages ...

* Update Alpine 3.14. gnu-libiconv is already fixed in this version
* Remove heavy packages: ansible, git, make, bash ...
* Download Wallabag TAR. Is faster and git is not required
* Replace environment variables with envsubst
* Reorder steps to build faster and reduce image size
  • Loading branch information
ngosang committed Aug 29, 2021
1 parent 7873719 commit 251af33
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 259 deletions.
41 changes: 25 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
FROM alpine:3.12
FROM alpine:3.14

LABEL maintainer "Marvin Steadfast <[email protected]>"

ARG WALLABAG_VERSION=2.4.2

RUN apk add gnu-libiconv --update-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ --allow-untrusted
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php

# Install dependencies
RUN set -ex \
&& apk update \
&& apk upgrade --available \
&& apk add \
ansible \
curl \
git \
libwebp \
mariadb-client \
nginx \
pcre \
php7 \
Expand Down Expand Up @@ -49,24 +43,39 @@ RUN set -ex \
py-simplejson \
rabbitmq-c \
s6 \
tar \
tzdata \
make \
bash \
# make \
# bash \
&& rm -rf /var/cache/apk/* \
&& ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log

# Install composer
RUN set -ex \
&& curl -s https://getcomposer.org/installer | php \
&& mv composer.phar /usr/local/bin/composer \
&& composer selfupdate --1 \
&& git clone --branch $WALLABAG_VERSION --depth 1 https://github.com/wallabag/wallabag.git /var/www/wallabag
&& mv composer.phar /usr/local/bin/composer

# Install envsubst
RUN set -ex \
&& curl -L -o /usr/local/bin/envsubst https://github.com/a8m/envsubst/releases/download/v1.1.0/envsubst-`uname -s`-`uname -m` \
&& chmod +x /usr/local/bin/envsubst

# Download Wallabag
RUN set -ex \
&& curl -L -o /tmp/wallabag.tar.gz https://github.com/wallabag/wallabag/archive/$WALLABAG_VERSION.tar.gz \
&& tar xvf /tmp/wallabag.tar.gz -C /tmp \
&& mv /tmp/wallabag-*/ /var/www/wallabag \
&& chown -R nobody:nobody /var/www/wallabag \
&& rm -rf /tmp/wallabag*

# Copy resources
COPY root /

# Install Wallabag
RUN set -ex \
&& cd /var/www/wallabag \
&& SYMFONY_ENV=prod composer install --no-dev -o --prefer-dist --no-progress \
&& chown -R nobody:nobody /var/www/wallabag
&& rm -rf /root/.composer/* /var/www/wallabag/var/cache/prod

EXPOSE 80
ENTRYPOINT ["/entrypoint.sh"]
Expand Down
17 changes: 9 additions & 8 deletions root/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/bin/sh

provisioner () {
echo "Starting provisioner..."
if ! out=`ansible-playbook -i /etc/ansible/hosts /etc/ansible/entrypoint.yml -c local "$@"`;then
echo $out;
fi
echo "Provisioner finished."
echo "Setting up Wallabag..."

cd /var/www/wallabag
/usr/local/bin/envsubst < app/config/parameters.template > app/config/parameters.yml
SYMFONY_ENV=prod composer install --no-dev -o --prefer-dist --no-progress --quiet
chown -R nobody:nobody /var/www/wallabag

echo "Ready"
}

if [ "$1" = "wallabag" ];then
Expand All @@ -14,14 +17,12 @@ if [ "$1" = "wallabag" ];then
fi

if [ "$1" = "import" ];then
provisioner --skip-tags=firstrun
cd /var/www/wallabag/
provisioner
exec su -c "bin/console wallabag:import:redis-worker --env=prod $2 -vv" -s /bin/sh nobody
fi

if [ "$1" = "migrate" ];then
provisioner
cd /var/www/wallabag/
exec su -c "bin/console doctrine:migrations:migrate --env=prod --no-interaction" -s /bin/sh nobody
fi

Expand Down
170 changes: 0 additions & 170 deletions root/etc/ansible/entrypoint.yml

This file was deleted.

2 changes: 0 additions & 2 deletions root/etc/ansible/hosts

This file was deleted.

63 changes: 0 additions & 63 deletions root/etc/ansible/templates/parameters.yml.j2

This file was deleted.

Loading

0 comments on commit 251af33

Please sign in to comment.