Skip to content

Commit 87259e4

Browse files
committed
✨ add alpine images
1 parent cba7edb commit 87259e4

8 files changed

+66
-60
lines changed

.additional_bashrc.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
export LS_COLORS="${LS_COLORS}di=1;34:"
2-
export EXA_COLORS="da=1;34:gm=1;34"
3-
alias ls='exa'
4-
alias ll='ls -aalh --git --header --group'
2+
alias ll='ls -alh'
53
export PATH=$PATH:~/.config/composer/vendor/bin:./bin:./vendor/bin:./node_modules/.bin
64

75
# only enable docker aliases if docker-socket is mounted
86
CONTAINER_ID=$(basename $(findmnt /etc/hosts -o SOURCE | grep -o 'containers\/.\+\/'))
97
export HOST_DISPLAY_NAME=$HOSTNAME
108
if sudo docker ps -q &>/dev/null; then
11-
DOCKER_COMPOSE_PROJECT=$(sudo docker inspect ${CONTAINER_ID} | grep '"com.docker.compose.project":' | awk '{print $2}' | tr --delete '"' | tr --delete ',')
9+
DOCKER_COMPOSE_PROJECT=$(sudo docker inspect ${CONTAINER_ID} | jq -r '.[0].Config.Labels."com.docker.compose.project"')
1210
export NODE_CONTAINER=$(sudo docker ps -f "name=${DOCKER_COMPOSE_PROJECT}" --format {{.Names}} | grep node)
1311
export HOST_DISPLAY_NAME=$(sudo docker inspect ${CONTAINER_ID} --format='{{.Name}}')
1412
export HOST_DISPLAY_NAME=${HOST_DISPLAY_NAME:1}
@@ -26,6 +24,8 @@ if [[ $CONTAINER_ID != ${HOSTNAME}* ]] ; then
2624
export HOST_DISPLAY_NAME=$HOSTNAME
2725
fi
2826

27+
source ~/.bash_git
28+
2929
PS1='\033]2;'$(pwd)'\007\[\e[0;36m\][\[\e[1;31m\]\u\[\e[0;36m\]@\[\e[1;34m\]$HOST_DISPLAY_NAME\[\e[0;36m\]: \[\e[0m\]\w\[\e[0;36m\]]\[\e[0m\]\$\[\e[1;32m\]\s\[\e[0;33m\]$(__git_ps1)\[\e[0;36m\]> \[\e[0m\]\n$ ';
3030

3131
alias xdebug-toggle='test $(php -m | grep xdebug) && xdebug-disable && echo "xdebug disabled" || (xdebug-enable && echo "xdebug enabled")'

.github/workflows/main.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
matrix:
2020
php: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
2121
webserver: [ 'apache', 'nginx' ]
22+
distroAddon: [ '', '-alpine' ]
2223
steps:
2324
-
2425
name: Set up QEMU
@@ -36,13 +37,15 @@ jobs:
3637
username: ${{ secrets.DOCKERHUB_USERNAME }}
3738
password: ${{ secrets.DOCKERHUB_TOKEN }}
3839
-
39-
name: Build and push ${{ matrix.webserver }}-${{ matrix.php }}
40+
name: Build and push ${{ matrix.webserver }}-${{ matrix.php }}-${{ matrix.distro }}
4041
id: docker_build
4142
uses: docker/build-push-action@v2
4243
with:
4344
push: ${{ github.ref == 'refs/heads/main' }}
44-
tags: pluswerk/php-dev:${{ matrix.webserver }}-${{ matrix.php }},pluswerk/php-dev:${{ matrix.webserver }}-${{ matrix.php }}-${{ steps.date.outputs.date }}
45-
build-args: FROM=webdevops/php-${{ matrix.webserver }}-dev:${{ matrix.php }}
45+
tags: pluswerk/php-dev:${{ matrix.webserver }}-${{ matrix.php }}${{ matrix.distroAddon }},pluswerk/php-dev:${{ matrix.webserver }}-${{ matrix.php }}${{ matrix.distroAddon }}-${{ steps.date.outputs.date }}
46+
build-args: |
47+
FROM=webdevops/php-${{ matrix.webserver }}-dev:${{ matrix.php }}${{ matrix.distroAddon }}
48+
DIST_ADDON=${{ matrix.distroAddon }}
4649
-
4750
name: Image digest
4851
run: |

Dockerfile

+31-44
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,60 @@
1-
ARG FROM=webdevops/php-nginx-dev:8.0
2-
FROM $FROM
3-
4-
ENV XHPROF_VERSION=5.0.4
5-
6-
# Install additional software
1+
ARG FROM=webdevops/php-nginx-dev:8.2
2+
ARG DIST_ADDON=
3+
FROM $FROM as base-alpine
4+
# Install additional software Alpine:
5+
RUN apk add --no-cache sudo vim nano less tree bash-completion mariadb-client iputils sshpass gdb tzdata findmnt jq docker-cli && \
6+
echo "application ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
7+
8+
FROM $FROM as base
9+
# Install additional software Debian:
710
RUN apt-get update && \
8-
apt-get install -y sudo vim nano less tree bash-completion mariadb-client iputils-ping sshpass gdb exa && \
11+
apt-get install -y sudo vim nano less tree bash-completion mariadb-client iputils-ping sshpass gdb jq && \
912
usermod -aG sudo application && \
1013
echo "application ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \
1114
curl -fsSL https://get.docker.com/ | sh && \
1215
rm -rf /var/lib/apt/lists/*
1316

14-
# Install XHProf
15-
COPY profiler.php /opt/docker/profiler.php
16-
17-
RUN cd /tmp && \
18-
wget https://github.com/tideways/php-xhprof-extension/archive/v${XHPROF_VERSION}.zip && \
19-
unzip v${XHPROF_VERSION}.zip && \
20-
cd php-xhprof-extension-${XHPROF_VERSION} && \
21-
phpize && \
22-
./configure && \
23-
make && \
24-
make install && \
25-
cd / && \
26-
rm -rf /tmp/php-xhprof-extension-${XHPROF_VERSION} && \
27-
echo "extension=tideways_xhprof.so" >> /opt/docker/etc/php/php.ini && \
28-
echo "auto_prepend_file=/opt/docker/profiler.php" >> /opt/docker/etc/php/php.ini
17+
FROM base${DIST_ADDON}
2918

30-
RUN pecl install pcov && \
31-
docker-php-ext-enable pcov mongodb && \
32-
echo "pcov.enabled=0" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini && \
33-
echo "pcov.exclude='~vendor~'" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini
19+
COPY entrypoint.d/* /opt/docker/provision/entrypoint.d/
20+
COPY profiler.php /opt/docker/profiler.php
21+
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/
22+
RUN install-php-extensions @fix_letsencrypt xhprof mongodb pcov && \
23+
echo "auto_prepend_file=/opt/docker/profiler.php" >> /opt/docker/etc/php/php.ini && \
24+
echo "pcov.enabled=0" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini && \
25+
echo "pcov.exclude='~vendor~'" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini && \
26+
composer self-update --clean-backups && \
27+
php -r "version_compare(PHP_VERSION, '7.2', '>=') && print_r(exec('composer completion bash > /etc/bash_completion.d/composer'));" && \
28+
if [ -f /etc/apache2/envvars ]; then \
29+
sed -i 's/export APACHE_RUN_USER=www-data/export APACHE_RUN_USER=application/g' /etc/apache2/envvars && \
30+
sed -i 's/export APACHE_RUN_GROUP=www-data/export APACHE_RUN_GROUP=application/g' /etc/apache2/envvars ; \
31+
fi && \
32+
if [ -f /etc/nginx/nginx.conf ]; then sed -i 's/user www-data;/user application application;/g' /etc/nginx/nginx.conf ; fi
3433

35-
RUN composer self-update --clean-backups
36-
RUN php -r "version_compare(PHP_VERSION, '7.2', '>=') && print_r(exec('composer completion bash > /etc/bash_completion.d/composer'));"
3734

3835
USER application
39-
RUN composer global require davidrjonas/composer-lock-diff perftools/xhgui-collector alcaeus/mongo-php-adapter perftools/php-profiler && \
40-
composer clear
4136

42-
# add .additional_bashrc.sh
4337
COPY bin/* /usr/local/bin/
4438
COPY .additional_bashrc.sh /home/application/.additional_bashrc.sh
4539
COPY .vimrc /home/application/.vimrc
4640
COPY .vimrc /root/.vimrc
4741
COPY apache.conf /opt/docker/etc/httpd/vhost.common.d/apache.conf
48-
RUN echo "source ~/.additional_bashrc.sh" >> ~/.bashrc
42+
43+
RUN composer global require davidrjonas/composer-lock-diff perftools/xhgui-collector alcaeus/mongo-php-adapter perftools/php-profiler && \
44+
composer clear && \
45+
echo "source ~/.additional_bashrc.sh" >> ~/.bashrc && \
46+
curl -L https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh > ~/.bash_git
4947

5048
USER root
5149

5250
ENV \
5351
COMPOSER_CACHE_DIR=/home/application/.composer/cache \
5452
POSTFIX_RELAYHOST="[global-mail]:1025" \
55-
PHP_DISMOD="ioncube" \
53+
PHP_DISMOD="ioncube,tideways" \
5654
PHP_DISPLAY_ERRORS="1" \
5755
PHP_MEMORY_LIMIT="-1" \
5856
XHGUI_MONGO_URI="global-xhgui:27017" \
5957
XHGUI_PROFILING="enabled" \
6058
TZ=Europe/Berlin
6159

62-
COPY entrypoint.d/* /opt/docker/provision/entrypoint.d/
63-
64-
# set apache user group to application:
65-
RUN if [ -f /etc/apache2/envvars ]; then sed -i 's/export APACHE_RUN_USER=www-data/export APACHE_RUN_USER=application/g' /etc/apache2/envvars ; fi
66-
RUN if [ -f /etc/apache2/envvars ]; then sed -i 's/export APACHE_RUN_GROUP=www-data/export APACHE_RUN_GROUP=application/g' /etc/apache2/envvars ; fi
67-
# set nginx user group to application:
68-
RUN if [ -f /etc/nginx/nginx.conf ]; then sed -i 's/user www-data;/user application application;/g' /etc/nginx/nginx.conf ; fi
69-
70-
# https://stackoverflow.com/questions/52998331/imagemagick-security-policy-pdf-blocking-conversion#comment110879511_59193253
71-
RUN sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml
72-
7360
WORKDIR /app

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ PHP-DEV is a small package that includes a web server, PHP and some tools needed
44
You can easily decide which version of PHP you want to use and whether you want to start an Apache or a Nginx webserver by setting the values in a docker-compose.yml.
55
We recommend using [pluswerk/docker-global](https://github.com/pluswerk/docker-global) as a wrapper for your projects, since this Dockerfile has been built keeping that in mind.
66

7+
# Tags
8+
9+
- php versions supported: `7.1`-`8.2`
10+
- webserver supported: `nginx` and `apache`
11+
- alpine images: `-alpine`
12+
- examples
13+
- `pluswerk/php-dev:nginx-8.2-alpine`
14+
- `pluswerk/php-dev:apache-7.1-alpine`
15+
- `pluswerk/php-dev:nginx-8.0`
16+
717
## Setup
818

919
Create a `compose/Development/docker-compose.yml` like shown below.
@@ -46,7 +56,7 @@ version: '3.5'
4656

4757
services:
4858
web:
49-
image: pluswerk/php-dev:nginx-8.1
59+
image: pluswerk/php-dev:nginx-8.2-alpine
5060

5161
volumes:
5262
- .:/app

entrypoint.d/10-set-timezone.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ echo ${TZ} >/etc/timezone
1010

1111
ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime
1212

13-
dpkg-reconfigure -f noninteractive tzdata &> /dev/null
13+
#dpkg-reconfigure -f noninteractive tzdata &> /dev/null
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env bash
22

33
if [ -n "${PHP_DEBUGGER:-}" ] && [[ "${PHP_DEBUGGER}" = 'xdebug' ]]; then
4-
xdebug-enable;
4+
echo 'xdebug-enable:'
5+
xdebug-enable || true;
56
else
6-
xdebug-disable;
7+
echo 'xdebug-disable:'
8+
xdebug-disable || true;
79
fi;

profiler.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
// we want minimal file inclusion.
55

66
if ((isset($_COOKIE['XDEBUG_PROFILE']) || getenv('PROFILING_ENABLED'))) {
7-
require_once '/home/application/.config/composer/vendor/perftools/php-profiler/autoload.php';
7+
$composerVendorDir = '/home/application/.composer/vendor';
8+
if (!is_dir($composerVendorDir)) {
9+
$composerVendorDir = '/home/application/.config/composer/vendor';
10+
}
11+
require_once $composerVendorDir . '/perftools/php-profiler/autoload.php';
812

9-
$tmpFile = '/tmp/'. uniqid('xhgui', true) . '.data.jsonl';
13+
$tmpFile = '/tmp/' . uniqid('xhgui', true) . '.data.jsonl';
1014

1115
$profiler = new \Xhgui\Profiler\Profiler(
1216
[
13-
'profiler' => \Xhgui\Profiler\Profiler::PROFILER_TIDEWAYS_XHPROF,
17+
'profiler' => \Xhgui\Profiler\Profiler::PROFILER_XHPROF,
1418
# 'save.handler' => \Xhgui\Profiler\Profiler::SAVER_MONGODB,
1519

1620
'save.handler' => \Xhgui\Profiler\Profiler::SAVER_FILE,
@@ -23,9 +27,9 @@
2327
$profiler->enable();
2428

2529

26-
register_shutdown_function(static function () use ($tmpFile, $profiler) {
30+
register_shutdown_function(static function () use ($composerVendorDir, $tmpFile, $profiler) {
2731
//we want this autoloading only after the main php script executed everything.
28-
require_once '/home/application/.config/composer/vendor/autoload.php';
32+
require_once $composerVendorDir . '/autoload.php';
2933
$profiler->stop();
3034

3135
//huge performance Optimisation possible:

0 commit comments

Comments
 (0)