Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert images to alpine #252

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apache/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM httpd:2.4
FROM httpd:2.4-alpine

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
RUN apk add --no-cache --update \
nano \
openssl \
gettext
Expand Down
2 changes: 1 addition & 1 deletion apache/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

# if there's no ssl certificate yet create it
if [ ! -f "/usr/local/apache2/conf/server.crt" ]; then
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
# docker-compose -f docker-compose.yml -f compose/nginx.yml -f compose/pgsql.yml -f compose/php.yml up -d pgsql php-7.3

nodejs:
image: node:16
image: node:16-alpine
container_name: totara_nodejs
environment:
TZ: ${TIME_ZONE}
Expand All @@ -28,7 +28,7 @@ services:
- totara

redis:
image: redis
image: redis:alpine
# activate persistency
command: "redis-server --appendonly yes"
environment:
Expand All @@ -39,7 +39,7 @@ services:
- totara

memcached:
image: memcached
image: memcached:alpine
environment:
TZ: ${TIME_ZONE}
networks:
Expand Down
9 changes: 6 additions & 3 deletions mssql/2017/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get install apt-transport-https && \
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-2017.list | tee /etc/apt/sources.list.d/mssql-server.list && \
apt-get update
rm -rf /var/lib/apt/lists/*

# Install SQL Server which a prerequisite for the optional packages below.
# Install full text search addons
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get install -y mssql-server mssql-server-ha mssql-server-fts
apt-get update && \
apt-get install -y mssql-server mssql-server-ha mssql-server-fts && \
rm -rf /var/lib/apt/lists/*

# we need en_US locales for MSSQL connection to work
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
Expand All @@ -33,7 +35,8 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | tee /etc/apt/sources.list.d/msprod.list && \
apt-get update && \
ACCEPT_EULA=Y apt-get install -y msodbcsql mssql-tools unixodbc-dev
ACCEPT_EULA=Y apt-get install -y msodbcsql mssql-tools unixodbc-dev && \
rm -rf /var/lib/apt/lists/*

RUN mkdir /custom
COPY custom /custom/
Expand Down
6 changes: 4 additions & 2 deletions mssql/2019/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-2019.list | tee /etc/apt/sources.list.d/mssql-server.list && \
apt-get update && \
export DEBIAN_FRONTEND=noninteractive && \
apt-get install -y mssql-server mssql-server-ha mssql-server-fts
apt-get install -y mssql-server mssql-server-ha mssql-server-fts && \
rm -rf /var/lib/apt/lists/*

# we need en_US locales for MSSQL connection to work
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
Expand All @@ -32,7 +33,8 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | tee /etc/apt/sources.list.d/msprod.list && \
apt-get update && \
ACCEPT_EULA=Y apt-get install -y msodbcsql mssql-tools unixodbc-dev
ACCEPT_EULA=Y apt-get install -y msodbcsql mssql-tools unixodbc-dev && \
rm -rf /var/lib/apt/lists/*

RUN mkdir /custom
COPY custom /custom/
Expand Down
4 changes: 2 additions & 2 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM nginx:1.20
FROM nginx:1.20-alpine

ENV REMOTE_DATA=${REMOTE_DATA}

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
RUN apk add --no-cache --update \
nano \
openssl \
gettext
Expand Down
2 changes: 1 addition & 1 deletion nginx/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

# if there's no ssl certificate yet create it
if [ ! -f "/etc/nginx/ssl/domain.crt" ]
Expand Down
181 changes: 106 additions & 75 deletions php/php80/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,56 @@
FROM php:8.0-fpm-bullseye
FROM php:8.0-fpm-alpine

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FROM php:8.0-fpm-alpine

ARG TARGETARCH
ARG TIME_ZONE=Pacific/Auckland

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
ENV LC_ALL en_US.UTF-8

RUN apk add --no-cache --update \
        linux-headers \
        aspell \
        autoconf \
        bash \
        bc \
        curl \
        icu \
        icu-data-full \
        freetds \
        freetype \
        ghostscript \
        git \
        gnupg \
        graphviz \
        libldap \
        libjpeg \
        libmcrypt \
        libmemcached \
        libpng \
        libpq \
        musl \
        musl-utils \
        musl-locales \
        musl-locales-lang \
        nano \
        openssl \
        tzdata \
        vim \
        wget \
        zip && \
    apk add --no-cache --virtual build-dependencies \
        curl-dev \
        freetype-dev \
        freetds-dev \
        libjpeg-turbo-dev \
        libmcrypt-dev \
        libmemcached-dev \
        libpng-dev \
        libpq-dev \
        libxml2-dev \
        libzip-dev \
        icu-dev \
        openldap-dev \
        gcc \
        make \
        g++ && \
    docker-php-ext-configure gd \
                --with-freetype=/usr/include/ \
                --with-jpeg=/usr/include/ && \
    docker-php-ext-configure ldap --with-libdir=lib/ && \
    docker-php-ext-install  \
        curl \
        exif \
        gd \
        intl \
        ldap \
        mysqli \
        opcache \
        pdo_dblib \
        pdo_pgsql \
        pdo_mysql \
        pgsql \
        soap \
        zip && \
  git clone https://github.com/tideways/php-profiler-extension.git \
    && cd php-profiler-extension \
    && phpize \
    && ./configure \
    && make && make install && \
  echo "extension=tideways_xhprof.so" >> /usr/local/etc/php/conf.d/tideways_xhprof.ini && \
  pecl install -o -f redis \
    &&  rm -rf /tmp/pear \
    &&  docker-php-ext-enable redis && \
  pecl install -o -f igbinary \
    &&  rm -rf /tmp/pear \
    &&  docker-php-ext-enable igbinary && \
  pecl install -o -f memcached \
    &&  rm -rf /tmp/pear \
    &&  docker-php-ext-enable memcached && \
# Taken from https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server
  curl -O https://download.microsoft.com/download/3/5/5/355d7943-a338-41a7-858d-53b259ea33f5/msodbcsql18_18.3.1.1-1_$TARGETARCH.apk && \
  curl -O https://download.microsoft.com/download/3/5/5/355d7943-a338-41a7-858d-53b259ea33f5/mssql-tools18_18.3.1.1-1_$TARGETARCH.apk && \
#(Optional) Verify signature, if 'gpg' is missing install it using 'apk add gnupg':
  curl -O https://download.microsoft.com/download/3/5/5/355d7943-a338-41a7-858d-53b259ea33f5/msodbcsql18_18.3.1.1-1_$TARGETARCH.sig && \
  curl -O https://download.microsoft.com/download/3/5/5/355d7943-a338-41a7-858d-53b259ea33f5/mssql-tools18_18.3.1.1-1_$TARGETARCH.sig && \
  curl https://packages.microsoft.com/keys/microsoft.asc  | gpg --import - && \
  gpg --verify msodbcsql18_18.3.1.1-1_$TARGETARCH.sig msodbcsql18_18.3.1.1-1_$TARGETARCH.apk && \
  gpg --verify mssql-tools18_18.3.1.1-1_$TARGETARCH.sig mssql-tools18_18.3.1.1-1_$TARGETARCH.apk && \
# Install the package(s)
  apk add --allow-untrusted msodbcsql18_18.3.1.1-1_$TARGETARCH.apk && \
  apk add --allow-untrusted mssql-tools18_18.3.1.1-1_$TARGETARCH.apk && \
  apk add --no-cache --update unixodbc-dev && \
#
  echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bash_profile && \
  echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc && \
#
  pear config-set php_ini `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` system && \
    pecl install sqlsrv && \
    pecl install pdo_sqlsrv && \
#
  docker-php-ext-enable sqlsrv.so && docker-php-ext-enable pdo_sqlsrv.so && \
  ln -fs /usr/share/zoneinfo/${TIME_ZONE} /etc/localtime && \
  apk del build-dependencies

# Python 3 for ML Recommender.
RUN apk add --no-cache --update python3 \
    py3-pip \
    py3-wheel \
    py3-virtualenv \
    python3-dev

COPY config/php.ini /usr/local/etc/php/
COPY config/fpm.conf /usr/local/etc/php-fpm.d/zz-totara.conf

# Source each .sh file found in the /shell/ folder
RUN echo 'for f in ~/custom_shell/*.sh; do [[ -e "$f" ]] && source "$f"; done;' >> ~/.bashrc

# Have the option of using the oh my zsh shell.
RUN apk add --no-cache --update zsh
RUN sh -c "$(curl https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" --unattended
RUN git clone https://github.com/romkatv/powerlevel10k ~/.oh-my-zsh/custom/themes/powerlevel10k
RUN git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
RUN git clone https://github.com/zsh-users/zsh-completions ~/.oh-my-zsh/custom/plugins/zsh-completions
RUN git clone https://github.com/zsh-users/zsh-syntax-highlighting ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
RUN echo 'setopt +o nomatch' > ~/.zshrc
RUN echo 'source ~/custom_shell/.zshrc' >> ~/.zshrc
RUN cat ~/.bashrc >> ~/.zshrc

Copy link
Member Author

@derschatta derschatta Sep 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the changes and why? @NingZhou-NZ

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I do was introduce the --virtual build-dependencies . Those dependencies only exist when we build this image and will be removed when build finish. This will reduce the size of image from 700 mb to 500 mb.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I do was introduce the --virtual build-dependencies . Those dependencies only exist when we build this image and will be removed when build finish. This will reduce the size of image from 700 mb to 500 mb.

ah nice. I'll add it to the patch

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you build the image base on my original comment, it will only be 500+ MB. Not sure why that delete build-dependencies doesn't work if you place it in the seperate RUN command. I am not a fan to chain everything together. However, it seems that was the only way to clean up the build-dependencies. I think that we can add # line to virsually seperate a one large RUN command to make it more readable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok if we have some repetition installing some of the packages multiple times, I prefer the readability and better maintainability (don't have to rebuild the whole image all the time). See my latest changes.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think each RUN is creating the "layer" in a image and each "layer" have some kind of isolation. So you would not be able to change one layer from other layer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have a look at the latest changes, built successfully locally for both, ARM64 and AMD64. Filesize looks good too.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work!


ARG TARGETARCH
ARG TIME_ZONE=Pacific/Auckland

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
apt-transport-https \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng-dev \
libxml2-dev \
libicu-dev \
libpq-dev \
gnupg2 \
RUN apk add --no-cache --update \
linux-headers \
aspell \
autoconf \
bash \
bc \
curl \
icu \
icu-data-full \
freetds \
freetype \
ghostscript \
git \
gnupg \
graphviz \
libldap \
libjpeg \
libmcrypt \
libmemcached \
libpng \
libpq \
musl \
musl-utils \
musl-locales \
musl-locales-lang \
nano \
vim \
wget \
openssl \
locales \
tzdata \
git \
vim \
wget \
zip

RUN apk add --no-cache --update --virtual build-dependencies \
curl-dev \
freetype-dev \
freetds-dev \
libjpeg-turbo-dev \
libmcrypt-dev \
libpng-dev \
libpq-dev \
libxml2-dev \
libzip-dev \
libmemcached-dev \
zip \
netcat \
bc \
ghostscript \
graphviz \
aspell \
libldap2-dev \
libltdl-dev \
&& docker-php-ext-install -j$(nproc) \
zip \
icu-dev \
openldap-dev \
gcc \
make \
g++ && \
docker-php-ext-install -j$(nproc) zip \
intl \
soap \
opcache \
Expand All @@ -40,69 +60,80 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
mysqli \
exif \
ldap \
&& docker-php-ext-configure gd \
pdo_dblib && \
docker-php-ext-configure gd \
--with-freetype \
--with-jpeg \
&& docker-php-ext-install -j$(nproc) gd

RUN git clone https://github.com/tideways/php-profiler-extension.git \
&& cd php-profiler-extension \
&& phpize \
&& ./configure \
&& make && make install
--with-jpeg && \
docker-php-ext-install -j$(nproc) gd && \
apk del build-dependencies

RUN apk add --no-cache --update --virtual build-dependencies \
gcc \
make \
g++ \
libmemcached-dev \
libzip-dev \
pkgconfig && \
git clone https://github.com/tideways/php-profiler-extension.git && \
cd php-profiler-extension && \
phpize && \
./configure && \
make && make install && \
pecl install -o -f redis && \
pecl install -o -f igbinary && \
pecl install -o -f memcached && \
rm -rf /tmp/pear && \
apk del build-dependencies

RUN echo "extension=tideways_xhprof.so" >> /usr/local/etc/php/conf.d/tideways_xhprof.ini

RUN pecl install -o -f redis \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable redis

RUN pecl install -o -f igbinary \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable igbinary

RUN pecl install -o -f memcached \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable memcached

# we need en_US locales for MSSQL connection to work
# we need en_AU locales for behat to work
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
sed -i -e 's/# en_AU.UTF-8 UTF-8/en_AU.UTF-8 UTF-8/' /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=en_US.UTF-8
RUN docker-php-ext-enable redis && \
docker-php-ext-enable igbinary && \
docker-php-ext-enable memcached

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
ENV LC_ALL en_US.UTF-8

# install mssql extension
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
&& curl https://packages.microsoft.com/config/debian/11/prod.list > /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update && ACCEPT_EULA=Y apt-get install -y \
msodbcsql18 \
mssql-tools18 \
unixodbc-dev
# Taken from https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server
RUN curl -O https://download.microsoft.com/download/3/5/5/355d7943-a338-41a7-858d-53b259ea33f5/msodbcsql18_18.3.1.1-1_$TARGETARCH.apk && \
curl -O https://download.microsoft.com/download/3/5/5/355d7943-a338-41a7-858d-53b259ea33f5/mssql-tools18_18.3.1.1-1_$TARGETARCH.apk

#(Optional) Verify signature, if 'gpg' is missing install it using 'apk add gnupg':
RUN curl -O https://download.microsoft.com/download/3/5/5/355d7943-a338-41a7-858d-53b259ea33f5/msodbcsql18_18.3.1.1-1_$TARGETARCH.sig && \
curl -O https://download.microsoft.com/download/3/5/5/355d7943-a338-41a7-858d-53b259ea33f5/mssql-tools18_18.3.1.1-1_$TARGETARCH.sig

RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --import - && \
gpg --verify msodbcsql18_18.3.1.1-1_$TARGETARCH.sig msodbcsql18_18.3.1.1-1_$TARGETARCH.apk && \
gpg --verify mssql-tools18_18.3.1.1-1_$TARGETARCH.sig mssql-tools18_18.3.1.1-1_$TARGETARCH.apk

# Install the package(s)
RUN apk add --allow-untrusted msodbcsql18_18.3.1.1-1_$TARGETARCH.apk && \
apk add --allow-untrusted mssql-tools18_18.3.1.1-1_$TARGETARCH.apk

RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile \
&& echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
RUN echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bash_profile && \
echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc

# Workaround applied: https://github.com/microsoft/msphpsql/issues/1438#issuecomment-1444773949
RUN pear config-set php_ini `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` system \
&& pecl install sqlsrv-5.10.1 pdo_sqlsrv-5.10.1 || \
apt-get install -y --allow-downgrades odbcinst=2.3.7 odbcinst1debian2=2.3.7 unixodbc=2.3.7 unixodbc-dev=2.3.7 && \
pecl install sqlsrv-5.10.1 pdo_sqlsrv-5.10.1
RUN apk add --no-cache --update --virtual build-dependencies \
gcc \
make \
g++ \
unixodbc-dev && \
pear config-set php_ini `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` system && \
pecl install sqlsrv && \
pecl install pdo_sqlsrv && \
rm -rf /tmp/pear && \
apk del build-dependencies

RUN docker-php-ext-enable sqlsrv.so && docker-php-ext-enable pdo_sqlsrv.so
Comment on lines +117 to 128

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these two RUN can be chained together.


RUN ln -fs /usr/share/zoneinfo/${TIME_ZONE} /etc/localtime \
&& dpkg-reconfigure --frontend noninteractive tzdata
RUN ln -fs /usr/share/zoneinfo/${TIME_ZONE} /etc/localtime

# Python 3.7 for ML Recommender.
RUN apt-get update && apt install -y python3 \
python3-pip \
python3-wheel \
python3-venv \
# Python 3 for ML Recommender.
RUN apk add --no-cache --update python3 \
py3-pip \
py3-wheel \
py3-virtualenv \
python3-dev

COPY config/php.ini /usr/local/etc/php/
Expand All @@ -112,7 +143,7 @@ COPY config/fpm.conf /usr/local/etc/php-fpm.d/zz-totara.conf
RUN echo 'for f in ~/custom_shell/*.sh; do [[ -e "$f" ]] && source "$f"; done;' >> ~/.bashrc

# Have the option of using the oh my zsh shell.
RUN apt-get update && apt-get install -y zsh
RUN apk add --no-cache --update zsh
RUN sh -c "$(curl https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" --unattended
RUN git clone https://github.com/romkatv/powerlevel10k ~/.oh-my-zsh/custom/themes/powerlevel10k
RUN git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
Expand Down
Loading