-
Notifications
You must be signed in to change notification settings - Fork 33
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
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a few changes on php-8.0. The image build success on my local
@@ -1,36 +1,46 @@ | |||
FROM php:8.0-fpm-bullseye | |||
FROM php:8.0-fpm-alpine |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work!
fdd22c7
to
8c97f94
Compare
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 |
There was a problem hiding this comment.
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.
My 2 cents is that alpine images are more hassle than they're worth - even once you've got them building successfully. In my experience there are usually some random libraries can have weird issues that are difficult to diagnose, and you end up wasting more time than it's worth trying to fix them, all just to get some smaller images. |
No description provided.