Skip to content

Commit 3e496bc

Browse files
committed
Base Dockerfile and scripts to generate PHP images with xdebug.
0 parents  commit 3e496bc

5 files changed

Lines changed: 153 additions & 0 deletions

File tree

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.DEFAULT_GOAL = help
2+
3+
.PHONY: help
4+
help:
5+
@echo "Usage: make [option]"
6+
@echo "Available options:"
7+
@echo "* generate - generates Dockerfiles for all defined versions of PHP in all variants"
8+
@echo "* build - builds all generated Dockerfiles available in ./build directory"
9+
@echo "* clean - cleans ./build directory"
10+
11+
12+
.PHONY: clean
13+
clean:
14+
@rm -rf ./build/*
15+
@echo "Removed all files from ./build directory."
16+
17+
generate:
18+
@./bin/generate.sh
19+
20+
build: generate
21+
@./bin/build-all.sh mobtitude/php-xdebug

bin/build-all.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
# Script builds all Dockerfiles defined in build directory
5+
# Prints summary after all images have been built (successfully or not)
6+
#
7+
8+
image_name="$1"
9+
10+
# Checks if image name was provided by user
11+
if [ -z "${image_name}" ]; then
12+
echo "Usage: $0 [docker_image_name]" >&2
13+
exit -1
14+
fi
15+
16+
# Change current path to project root
17+
script_path=$(dirname "$0")
18+
cd "${script_path}/../" || exit -1
19+
20+
# Text formatting
21+
text_bold=$(tput bold)
22+
text_red=$(tput setaf 1)
23+
text_normal=$(tput sgr0)
24+
25+
# Summary arrays
26+
build_failed=()
27+
build_done=()
28+
29+
# Loop through all available directories in ./build
30+
for i in ./build/*/; do
31+
version=$(basename "$i");
32+
image="${image_name}:${version}"
33+
34+
echo "${text_bold}* Building ${image} ${text_normal}"
35+
36+
# Builds image and check for return code
37+
if docker build --pull -t "${image}" "./build/${version}"; then
38+
build_done+=( "${image}" )
39+
else
40+
echo "${text_bold}${text_red}* ERROR when building ${image} ${text_normal}"
41+
build_failed+=( "${image}" )
42+
fi
43+
done
44+
45+
46+
# Prints summary for successful builds
47+
if [ "${#build_done[@]}" -gt 0 ]; then
48+
echo "${text_bold}"
49+
echo "Docker has successfully built the following images:${text_normal}"
50+
for img in "${build_done[@]}"; do
51+
echo "* ${img}"
52+
done
53+
echo -n "${text_normal}"
54+
fi
55+
56+
# Prints summary for failed builds
57+
if [ "${#build_failed[@]}" -gt 0 ]; then
58+
echo "${text_red}"
59+
echo "Docker failed when building the following images:"
60+
for img in "${build_failed[@]}"; do
61+
echo "${text_red}* ${img}${text_normal}"
62+
done
63+
fi

bin/generate.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
# Generates Dockerfiles for specified PHP versions
5+
#
6+
7+
# PHP Versions that will be generated
8+
php_versions=( "7.2" "7.1" "7.0" "5.6")
9+
10+
# PHP variants that will be generated for each PHP version
11+
# final source image will be generated as follow: php:7.2-cli, php:7-2-apache and php:7.2-fpm
12+
php_docker_suffix=( "cli" "apache" "fpm" )
13+
14+
# Map of xdebug versions for PHP images
15+
# PHP_VERSION => XDEBUG_VERSION
16+
declare -A xdebug_versions
17+
xdebug_versions=(
18+
["7.2"]="xdebug-2.6.0"
19+
["7.1"]="xdebug-2.6.0"
20+
["7.0"]="xdebug-2.6.0"
21+
["5.6"]="xdebug-2.5.5"
22+
)
23+
24+
25+
# Changes current path to project root
26+
script_path=$(dirname "$0")
27+
cd "${script_path}/../" || exit -1
28+
29+
# Generates Dockerfiles for each PHP version and variant
30+
for php_version in "${php_versions[@]}"; do
31+
for php_suffix in "${php_docker_suffix[@]}"; do
32+
target_dir="./build/${php_version}-${php_suffix}"
33+
target_dockerfile="${target_dir}/Dockerfile"
34+
35+
base_image="php:${php_version}-${php_suffix}"
36+
xdebug_version="${xdebug_versions[${php_version}]}"
37+
38+
mkdir -p "${target_dir}"
39+
cp ./src/xdebug.ini "${target_dir}/xdebug.ini"
40+
41+
# shellcheck disable=SC2002
42+
cat ./src/Dockerfile \
43+
| sed "s/#BASE_IMAGE#/${base_image}/g" \
44+
| sed "s/#XDEBUG_VERSION#/${xdebug_version}/g" \
45+
> "${target_dockerfile}"
46+
echo "Generated ${target_dockerfile}"
47+
done
48+
done

src/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM #BASE_IMAGE#
2+
MAINTAINER Przemek Szalko <[email protected]>
3+
4+
RUN pecl channel-update pecl.php.net \
5+
&& pecl install #XDEBUG_VERSION# \
6+
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
7+
8+
COPY xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini

src/xdebug.ini

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[xdebug]
2+
zend_extension=xdebug.so
3+
4+
xdebug.cli_color=1
5+
xdebug.profiler_enable=0
6+
xdebug.profiler_enable_trigger=1
7+
8+
xdebug.profiler_output_dir="/tmp"
9+
xdebug.profiler_output_name="cachegrind.out.%H.%t.%p"
10+
11+
xdebug.remote_enable=1
12+
xdebug.remote_connect_back=1
13+
xdebug.remote_port=9000

0 commit comments

Comments
 (0)