-
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
Draft
derschatta
wants to merge
5
commits into
totara:develop
Choose a base branch
from
derschatta:php-alpine
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
24594e5
Move from debian to alpine for PHP image
derschatta 61cd0a0
Convert PHP 8.0 and 8.1 images alpine based images
22ad969
Change images to alpine where possible
8c97f94
Remove cached files during build
88de2bd
Make sure build dependencies are properly cleaned up
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
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 \ | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these two |
||
|
||
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/ | ||
|
@@ -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 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.
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 thebuild-dependencies
. I think that we can add#
line to virsually seperate a one largeRUN
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!