Skip to content
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

Add consistent local environment for testing with docker and docker-compose #86

Merged
merged 2 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .docker/php53/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
FROM buildpack-deps:jessie

ENV PHP_VERSION 5.3.29

# php 5.3 needs older autoconf
RUN set -eux; \
\
apt-get update; \
apt-get install -y \
curl \
autoconf2.13 \
; \
rm -r /var/lib/apt/lists/*; \
\
curl -sSLfO http://launchpadlibrarian.net/140087283/libbison-dev_2.7.1.dfsg-1_amd64.deb; \
curl -sSLfO http://launchpadlibrarian.net/140087282/bison_2.7.1.dfsg-1_amd64.deb; \
dpkg -i libbison-dev_2.7.1.dfsg-1_amd64.deb; \
dpkg -i bison_2.7.1.dfsg-1_amd64.deb; \
rm *.deb; \
\
curl -sSLf "https://php.net/get/php-$PHP_VERSION.tar.bz2/from/this/mirror" -o php.tar.bz2; \
echo 'c4e1cf6972b2a9c7f2777a18497d83bf713cdbecabb65d3ff62ba441aebb0091 php.tar.bz2' | sha256sum -cw --status; \
\
mkdir -p /usr/src/php; \
tar -xf php.tar.bz2 -C /usr/src/php --strip-components=1; \
rm php.tar.bz2*; \
\
cd /usr/src/php; \
./buildconf --force; \
./configure --disable-cgi \
$(command -v apxs2 > /dev/null 2>&1 && echo '--with-apxs2' || true) \
--with-pdo-mysql \
--with-zlib \
--enable-mbstring \
; \
make -j"$(nproc)"; \
make install; \
\
dpkg -r \
bison \
libbison-dev \
; \
apt-get purge -y --auto-remove \
autoconf2.13 \
; \
rm -r /usr/src/php

CMD ["php", "-a"]
5 changes: 5 additions & 0 deletions .docker/php54/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM php:5.4-cli

RUN docker-php-ext-install pdo
RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-install mbstring
6 changes: 6 additions & 0 deletions .docker/php55_71/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ARG PHP_TAG
FROM php:${PHP_TAG}

RUN docker-php-ext-install pdo
RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-install mbstring
22 changes: 22 additions & 0 deletions .docker/php72_73/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ARG PHP_VERSION
FROM php:${PHP_VERSION}-cli

RUN docker-php-ext-install pdo
RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-install mbstring

# For consistent mime type file guesser
RUN set -eux; \
distFilePath=`which file`; \
\
mv ${distFilePath} ${distFilePath}.dist; \
{ \
echo '#! /bin/sh -eu'; \
echo ''; \
echo "${distFilePath}"'.dist "$@" | sed -e s,application/x-pie-executable,application/x-executable,g'; \
} | tee ${distFilePath}; \
\
chmod +x ${distFilePath}; \
\
file /bin/ls --mime | grep application/x-executable; \
:;
34 changes: 34 additions & 0 deletions .docker/php74_81/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
ARG PHP_VERSION
FROM php:${PHP_VERSION}-cli

RUN docker-php-ext-install pdo
RUN docker-php-ext-install pdo_mysql

# Install mbstring PHP extension
#
RUN set -eux; \
apt-get update; \
apt-get install -y --no-upgrade --no-install-recommends \
libonig-dev \
; \
\
apt-get clean; \
rm -rf /var/lib/apt/lists/*; \
\
docker-php-ext-install mbstring

# For consistent mime type file guesser
RUN set -eux; \
distFilePath=`which file`; \
\
mv ${distFilePath} ${distFilePath}.dist; \
{ \
echo '#! /bin/sh -eu'; \
echo ''; \
echo "${distFilePath}"'.dist "$@" | sed -e s,application/x-pie-executable,application/x-executable,g'; \
} | tee ${distFilePath}; \
\
chmod +x ${distFilePath}; \
\
file /bin/ls --mime | grep application/x-executable; \
:;
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
tests/DoctrineTest/doctrine_tests/*
*TestCase.php
/composer.lock
/tests/tmp
/tests/foo.sq3
/vendor/
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Doctrine1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The heading is not consistent within the file (using ### Header 3 and underlines, like on this like)

We should keep the formatting consistent, I suggest to use:

  • # Header 1
  • ## Hader 2

wdyt?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not have any point of view about Markdown formatting.

I am curious about that, do you have some resources to share ?

=========

About this version
------------------

This is a community driven fork of doctrine 1, as official support has been interrupted long time ago.

**Do not use it for new projects: this version is great to improve existing symfony1 applications using doctrine1, but [Doctrine2](https://www.doctrine-project.org/projects/orm.html) is the way to go today.**


Requirements
------------

PHP 5.3 and up.


Installation
------------

Using [Composer](http://getcomposer.org/doc/00-intro.md) as dependency management:

composer require friendsofsymfony1/doctrine1 "1.5.*"
composer install



Tests
-----

### Prerequisites

* docker-engine version 17.12.0+
* docker-compose version 1.20.0+

### How to execute all tests on all supported PHP versions and dependencies?

tests/bin/test

### When you finish your work day, do not forget to clean up your desk

docker-compose down


Documentation
-------------

Read the official [doctrine1 documentation](https://web.archive.org/web/20171008235327/http://docs.doctrine-project.org:80/projects/doctrine1/en/latest/en/manual/index.html)


Contributing
------------

You can send pull requests or create an issue.
138 changes: 138 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
version: '3.5'

volumes:
db_socket:

services:
composer:
image: composer
working_dir: /app
volumes:
- .:/app
entrypoint:
- sh
- -c
- |
exec tail -f /dev/null

php53:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of multiple service, we could merge together multiple docker-compose files
and with a Makefile choose which PHP container to start:
something like docker-compose --file=docker-compose.yml --file=docker/docker-compose.php5.yml

WDYT?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refacto.

I do not have time to implements right now.

build: .docker/php53
working_dir: /app/tests
volumes:
- .:/app
- db_socket:/var/run/mysqld
entrypoint:
- sh
- -c
- |
{
echo 'pdo_mysql.default_socket = /var/run/mysqld/mysql.sock'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this into a file, and copy it into the build image?
The file looks like the same for php 5.3 and next versions, the difference is its location path

WDYT?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly

echo 'memory_limit = -1'
echo 'short_open_tag = off'
echo 'magic_quotes_gpc = off'
echo 'date.timezone = "UTC"'
} | tee -a /usr/local/lib/php.ini

exec tail -f /dev/null

php54: &services_php54
build:
context: .docker/php54
working_dir: /app/tests
volumes:
- .:/app
- db_socket:/var/run/mysqld
entrypoint:
- sh
- -c
- |
{
echo 'pdo_mysql.default_socket = /var/run/mysqld/mysql.sock'
echo 'memory_limit = -1'
echo 'short_open_tag = off'
echo 'magic_quotes_gpc = off'
echo 'date.timezone = "UTC"'
} | tee -a /usr/local/etc/php/php.ini

exec tail -f /dev/null
depends_on:
- db

php55:
<<: *services_php54
build:
context: .docker/php55_71
args:
PHP_TAG: '5.5-cli'

php56:
<<: *services_php54
build:
context: .docker/php55_71
args:
PHP_TAG: '5.6-cli-jessie'

php70:
<<: *services_php54
build:
context: .docker/php55_71
args:
PHP_TAG: '7.0-cli-jessie'

php71:
<<: *services_php54
build:
context: .docker/php55_71
args:
PHP_TAG: '7.1-cli-jessie'

php72:
<<: *services_php54
build:
context: .docker/php72_73
args:
PHP_VERSION: '7.2'

php73:
<<: *services_php54
build:
context: .docker/php72_73
args:
PHP_VERSION: '7.3'

php74:
<<: *services_php54
build:
context: .docker/php74_81
args:
PHP_VERSION: '7.4'

php80:
<<: *services_php54
build:
context: .docker/php74_81
args:
PHP_VERSION: '8.0'

php81:
<<: *services_php54
build:
context: .docker/php74_81
args:
PHP_VERSION: '8.1'

db:
image: mysql:5.5.62
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
volumes:
- db_socket:/tmp
entrypoint:
- bash
- -c
- |
{
echo "CREATE DATABASE IF NOT EXISTS test;"
} | tee /docker-entrypoint-initdb.d/init.sql

exec /usr/local/bin/docker-entrypoint.sh mysqld
76 changes: 76 additions & 0 deletions tests/bin/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#! /bin/sh -eu
#
# [<php-version>] [<dependency-preference>] [<php-test-runtime>]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to split this into 2 scripts?

  • first scripts takes the php version, dependency-level [highest|lowest]
  • second script to run tests for all php versions

WDYT?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What issue should this fix ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, what I think.

The current script if a first step that can be improved.

Regarding developer experience

We need simplicity over complexity or confusion.

2 test scripts available are already too much.

2 test scripts will bring too much complexity and confusion.

The goal is to have only one command to execute the test suite and that done things well.

tests/bin/test

If this command done successfully you should feel safe to merge the code or submit the pull request.

Quote from the book "Clean Code" wrote by Robert C. Martin

You should be able to run all the unit tests with just one command. In the best case you can run all the tests by clicking on one button in your IDE. In the worst case you should be able to issue a single simple command in a shell. Being able to run all the tests is so fundamental and so important that it should be quick, easy, and obvious to do.

#
# <php-version> example: php70
# <dependency-preference> One of highest (default), lowest
#
# Both arguments can be a space separated value.
# Example: "lowest highest"
#

# Configuration
#
dependencyPreferences='highest'
skipPHPVersions='php8'

# Commands
#
dcexec="docker-compose exec -u `id -u`:`id -g`"
composerUpdate='composer update --prefer-dist --no-suggest --optimize-autoloader'
doctrineTestSuite='run.php'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we need to change this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To speed up feedback loop during TDD sessions, when the modified does not touch outside.

The full test suite is slow, moreover, with all PHP version to execute. That's a problem.

So, need to run only one test case.
The test tool does not allow it, as I saw, so new feature.


# Parse arguments
#
phpVersions="${1-}"
dependencyPreferences="${2-${dependencyPreferences}}"
phpTestRuntime="${3-${doctrineTestSuite}}"

script ()
{
echo
echo
echo $0 ${1} ${2}
echo
${dcexec} ${1} php ${phpTestRuntime}
}

scriptAll ()
{
for dependencyPreference in ${dependencyPreferences}
do
install_${dependencyPreference}

for phpVersion in ${phpVersions}
do
script ${phpVersion} ${dependencyPreference}
done
done
}

fetchAllPHPVersions ()
{
docker-compose 2>/dev/null ps --services --filter status=running \
| grep php \
| sort \
| grep -v ${skipPHPVersions}
}

install_highest ()
{
${dcexec} composer ${composerUpdate}
}

install_lowest ()
{
${dcexec} composer ${composerUpdate} --prefer-lowest
}

echo '+ docker-compose build'
docker-compose up -d --build --remove-orphans > /dev/null

test x"" != x"${phpVersions}" || {
phpVersions=`fetchAllPHPVersions`
}

scriptAll