Skip to content

Commit 6226ca0

Browse files
authored
Merge pull request php-curl-class#535 from zachborboa/docker
Add additional containers for unit tests
2 parents 2ffeeaa + 6acf768 commit 6226ca0

File tree

19 files changed

+280
-7
lines changed

19 files changed

+280
-7
lines changed

tests/before_script.sh

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,29 @@ php -r "var_dump(curl_version());"
2727
composer self-update
2828
composer install --prefer-source --no-interaction
2929

30+
# Use docker-specific settings.
31+
if [ -f "/.dockerenv" ]; then
32+
# Skip using sudo.
33+
superuser=""
34+
# Use unix socket.
35+
fastcgi_pass="unix:/var/run/php5-fpm.sock"
36+
else
37+
# Use sudo.
38+
superuser="sudo"
39+
# Use ip socket.
40+
fastcgi_pass="127.0.0.1:9000"
41+
fi
42+
3043
if [[ "${TRAVIS_PHP_VERSION}" == "5.3" ]]; then
31-
sudo add-apt-repository -y ppa:nginx/development
32-
sudo apt-get update
33-
sudo apt-get install -y nginx
34-
sudo apt-get install -y php5-fpm
44+
if ! [ -x "$(command -v add-apt-repository)" ]; then
45+
$superuser apt-get install -y python-software-properties
46+
fi
47+
$superuser add-apt-repository -y ppa:nginx/development
48+
$superuser apt-get update
49+
$superuser apt-get install -y nginx
50+
$superuser apt-get install -y php5-fpm
3551
root="$(pwd)/tests/PHPCurlClass"
36-
sudo tee /etc/nginx/sites-enabled/default <<EOF
52+
$superuser tee /etc/nginx/sites-enabled/default <<EOF
3753
server {
3854
listen 8000 default_server;
3955
root ${root};
@@ -44,14 +60,15 @@ server {
4460
}
4561
location ~ \.php$ {
4662
fastcgi_split_path_info ^(.+\.php)(/.+)$;
47-
fastcgi_pass 127.0.0.1:9000;
63+
fastcgi_pass ${fastcgi_pass};
4864
fastcgi_index index.php;
4965
include fastcgi_params;
5066
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
5167
}
5268
}
5369
EOF
54-
sudo /etc/init.d/nginx restart
70+
$superuser /etc/init.d/php5-fpm start
71+
$superuser /etc/init.d/nginx restart
5572
phpunit_shim
5673
elif [[ "${TRAVIS_PHP_VERSION}" == "5.4" ]]; then
5774
php -S 127.0.0.1:8000 -t tests/PHPCurlClass/ &

tests/dockerfiles/php53/1_build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Build an image.
2+
docker build --tag="php-curl-class/php53" .

tests/dockerfiles/php53/2_start.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Run image to create container.
2+
3+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4+
set -x
5+
cd "${SCRIPT_DIR}/../../.."
6+
project_dir="${PWD}"
7+
8+
docker start "php53" ||
9+
docker run \
10+
--detach \
11+
--interactive \
12+
--mount "type=bind,src=${project_dir},dst=/data,readonly=true" \
13+
--name="php53" \
14+
--tty \
15+
"php-curl-class/php53"

tests/dockerfiles/php53/3_test.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Run tests inside container.
2+
command=$(cat <<-END
3+
mkdir --parents "/tmp/php-curl-class" &&
4+
rsync --exclude=".git" --exclude="vendor" --links --recursive "/data/" "/tmp/php-curl-class/" &&
5+
cd "/tmp/php-curl-class" &&
6+
export TRAVIS_PHP_VERSION="5.3" &&
7+
(
8+
[ ! -f "/tmp/.composer_updated" ] &&
9+
composer --no-interaction update &&
10+
touch "/tmp/.composer_updated" ||
11+
exit 0
12+
) &&
13+
bash "tests/before_script.sh" &&
14+
bash "tests/script.sh"
15+
END
16+
)
17+
docker exec --interactive --tty "php53" sh -c "${command}"

tests/dockerfiles/php53/4_stop.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Stop container.
2+
3+
docker stop "php53"

tests/dockerfiles/php53/Dockerfile

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
FROM debian:jessie
2+
ENV DEBIAN_FRONTEND noninteractive
3+
4+
RUN apt-get --assume-yes --quiet update
5+
6+
RUN apt-get --assume-yes --quiet install \
7+
curl \
8+
rsync \
9+
# "/bin/sh: 1: make: not found"
10+
make \
11+
# "make[1]: *** No rule to make target '../include/openssl/bio.h', needed by 'cryptlib.o'. Stop."
12+
# "configure: error: xml2-config not found. Please check your libxml2 installation."
13+
libxml2-dev \
14+
# "make[1]: gcc: Command not found"
15+
gcc \
16+
# tar (child): xz: Cannot exec: No such file or directory
17+
# tar (child): Error is not recoverable: exiting now
18+
# tar: Child returned status 2
19+
# tar: Error is not recoverable: exiting now
20+
xz-utils \
21+
# "configure: error: Cannot find libz"
22+
libssl-dev \
23+
# "configure: error: Please reinstall the libcurl distribution -
24+
# easy.h should be in <curl-dir>/include/curl/"
25+
libcurl4-openssl-dev \
26+
# "configure: error: png.h not found."
27+
libpng-dev \
28+
# "sh: 1: git: not found" (composer).
29+
git \
30+
# "Failed to download phpunit/phpunit from dist: The zip extension and unzip command are both missing,
31+
# skipping."
32+
zip
33+
34+
# Compile openssl so that php configure --with-openssl works.
35+
RUN mkdir --parents "/tmp/openssl/" && \
36+
curl --silent --show-error --output "openssl.tar.gz" \
37+
"https://www.openssl.org/source/openssl-1.0.2k.tar.gz" && \
38+
tar --extract --file "openssl.tar.gz" --directory "/tmp/openssl/" --strip-components="1" && \
39+
cd "/tmp/openssl/" && \
40+
./config && \
41+
make && \
42+
make install && \
43+
rm -rf "/tmp/openssl/"
44+
45+
RUN mkdir --parents "/usr/src/php/" && \
46+
curl --silent --show-error --output "php.tar.xz" \
47+
"https://secure.php.net/distributions/php-5.3.29.tar.xz" && \
48+
tar --extract --file "php.tar.xz" --directory "/usr/src/php/" --strip-components="1" && \
49+
rm "php.tar.xz"* && \
50+
cd "/usr/src/php/" && \
51+
./configure \
52+
--enable-mbstring \
53+
--with-curl \
54+
--with-gd \
55+
--with-openssl="/usr/local/ssl" \
56+
--with-zlib && \
57+
make --jobs="$(nproc)" && \
58+
make install && \
59+
make clean
60+
61+
RUN curl --silent --show-error "https://getcomposer.org/installer" | php && \
62+
mv "composer.phar" "/usr/local/bin/composer" && \
63+
composer global require --no-interaction "phpunit/phpunit"
64+
65+
ENV PATH /root/.composer/vendor/bin:$PATH
66+
CMD ["bash"]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Run image to create container and attach to it.
2+
3+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4+
set -x
5+
cd "${SCRIPT_DIR}/../../.."
6+
project_dir="${PWD}"
7+
8+
docker run \
9+
--interactive \
10+
--mount "type=bind,src=${project_dir},dst=/data,readonly=true" \
11+
--name="php53" \
12+
--rm \
13+
--tty \
14+
"php-curl-class/php53" /bin/bash

tests/dockerfiles/php54/1_build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Build an image.
2+
docker build --tag="php-curl-class/php54" .

tests/dockerfiles/php54/2_start.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Run image to create container.
2+
3+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4+
set -x
5+
cd "${SCRIPT_DIR}/../../.."
6+
project_dir="${PWD}"
7+
8+
docker start "php54" ||
9+
docker run \
10+
--detach \
11+
--interactive \
12+
--mount "type=bind,src=${project_dir},dst=/data,readonly=true" \
13+
--name="php54" \
14+
--tty \
15+
"php-curl-class/php54"

tests/dockerfiles/php54/3_test.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Run tests inside container.
2+
command=$(cat <<-END
3+
mkdir --parents "/tmp/php-curl-class" &&
4+
rsync --exclude=".git" --exclude="vendor" --links --recursive "/data/" "/tmp/php-curl-class/" &&
5+
cd "/tmp/php-curl-class" &&
6+
export TRAVIS_PHP_VERSION="5.4" &&
7+
(
8+
[ ! -f "/tmp/.composer_updated" ] &&
9+
composer --no-interaction update &&
10+
touch "/tmp/.composer_updated" ||
11+
exit 0
12+
) &&
13+
bash "tests/before_script.sh" &&
14+
bash "tests/script.sh"
15+
END
16+
)
17+
docker exec --interactive --tty "php54" sh -c "${command}"

0 commit comments

Comments
 (0)