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 Docker #895

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d8cf59d
Initial commit
arogachev Oct 29, 2024
3c5ca51
WIP
arogachev Oct 30, 2024
b23740f
WIP
arogachev Nov 1, 2024
44c33de
WIP
arogachev Nov 1, 2024
ab5e779
WIP
arogachev Nov 18, 2024
aa8696d
WIP
arogachev Nov 19, 2024
d466d6f
WIP
arogachev Nov 21, 2024
86c0fb9
Merge branch 'master' into docker
arogachev Nov 21, 2024
28119a0
WIP
arogachev Nov 25, 2024
bcea166
Try approach with PHP and Oracle in one service
arogachev Dec 2, 2024
c7e8975
Cleanup
arogachev Dec 2, 2024
d03a8c2
WIP
arogachev Dec 2, 2024
b8f13ef
Merge branch 'master' into docker
arogachev Dec 2, 2024
4498919
WIP
arogachev Dec 3, 2024
82b078a
WIP
arogachev Dec 3, 2024
95bfdb7
WIP
arogachev Dec 3, 2024
9cb425c
make help [skip ci]
arogachev Dec 5, 2024
2b623c1
Move the rest of Docker related files to docker folder
arogachev Dec 6, 2024
4afa91d
WIP [skip ci]
arogachev Dec 6, 2024
397c3c3
Adjust .gitattributes [skip ci]
arogachev Dec 6, 2024
80870e8
WIP [skip ci]
arogachev Dec 6, 2024
167406a
Add name in docker compose [skip ci]
arogachev Dec 9, 2024
f573a62
Update docs/internals.md
arogachev Dec 9, 2024
890ee0b
WIP [skip ci]
arogachev Dec 9, 2024
7b32101
WIP [skip ci]
arogachev Dec 9, 2024
6da0e5b
Windows docs [skip ci]
arogachev Dec 9, 2024
fb83e8b
Update docs/internals.md
arogachev Dec 10, 2024
3edb0ba
Update docs/internals.md
arogachev Dec 10, 2024
b1abbc8
Merge branch 'master' into docker
vjik Dec 10, 2024
1d5491a
Fix [skip ci]
arogachev Dec 10, 2024
9389803
Merge remote-tracking branch 'origin/docker' into docker
arogachev Dec 10, 2024
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ phpunit.phar
#codeception
/tests/_output
c3.php

# Docker
docker-compose.override.yml
88 changes: 88 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
FROM composer/composer:latest-bin AS composer

FROM php:8.3-cli

# System packages

RUN apt-get update && apt-get install -y \
unzip \
# PostgreSQL
libpq-dev \
# MSSQL
apt-transport-https \
gnupg2 \
libpng-dev \
# Oracle
libaio1 && \
rm -rf /var/lib/apt/lists/*

# MSSQL dependencies

ENV ACCEPT_EULA=Y

# Install prerequisites for the sqlsrv and pdo_sqlsrv PHP extensions.
# Some packages are pinned with lower priority to prevent build issues due to package conflicts.
# Link: https://github.com/microsoft/linux-package-repositories/issues/39
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 \
&& echo "Package: unixodbc\nPin: origin \"packages.microsoft.com\"\nPin-Priority: 100\n" >> /etc/apt/preferences.d/microsoft \
&& echo "Package: unixodbc-dev\nPin: origin \"packages.microsoft.com\"\nPin-Priority: 100\n" >> /etc/apt/preferences.d/microsoft \
&& echo "Package: libodbc1:amd64\nPin: origin \"packages.microsoft.com\"\nPin-Priority: 100\n" >> /etc/apt/preferences.d/microsoft \
&& echo "Package: odbcinst\nPin: origin \"packages.microsoft.com\"\nPin-Priority: 100\n" >> /etc/apt/preferences.d/microsoft \
&& echo "Package: odbcinst1debian2:amd64\nPin: origin \"packages.microsoft.com\"\nPin-Priority: 100\n" >> /etc/apt/preferences.d/microsoft \
&& apt-get update \
&& apt-get install -y msodbcsql18 mssql-tools18 unixodbc-dev \
&& rm -rf /var/lib/apt/lists/*

# Oracle dependencies

RUN cd /tmp && curl -L https://download.oracle.com/otn_software/linux/instantclient/2350000/instantclient-basic-linux.x64-23.5.0.24.07.zip -O
RUN cd /tmp && curl -L https://download.oracle.com/otn_software/linux/instantclient/2350000/instantclient-sdk-linux.x64-23.5.0.24.07.zip -O
RUN cd /tmp && curl -L https://download.oracle.com/otn_software/linux/instantclient/2350000/instantclient-sqlplus-linux.x64-23.5.0.24.07.zip -O

RUN unzip /tmp/instantclient-basic-linux.x64-23.5.0.24.07.zip -d /usr/local/
RUN unzip -o /tmp/instantclient-sdk-linux.x64-23.5.0.24.07.zip -d /usr/local/
RUN unzip -o /tmp/instantclient-sqlplus-linux.x64-23.5.0.24.07.zip -d /usr/local/

RUN ln -s /usr/local/instantclient_23_5 /usr/local/instantclient
RUN ln -s /usr/local/instantclient/lib* /usr/lib
RUN ln -s /usr/local/instantclient/sqlplus /usr/bin/sqlplus

RUN echo 'export LD_LIBRARY_PATH="/usr/local/instantclient"' >> /root/.bashrc
RUN echo 'umask 002' >> /root/.bashrc

# PHP extensions

RUN docker-php-ext-install \
pdo_mysql \
pdo_pgsql \
# For Psalm, to make use of JIT for a 20%+ performance boost.
opcache

RUN pecl install sqlsrv
RUN printf "; priority=20\nextension=sqlsrv.so\n" > /usr/local/etc/php/conf.d/php-sqlsrv.ini

RUN pecl install pdo_sqlsrv
RUN printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /usr/local/etc/php/conf.d/php-pdo-sqlsrv.ini

RUN echo 'instantclient,/usr/local/instantclient' | pecl install oci8
RUN echo "extension=oci8.so" > /usr/local/etc/php/conf.d/php-oci8.ini

RUN echo 'instantclient,/usr/local/instantclient' | pecl install pdo_oci
RUN echo "extension=pdo_oci.so" > /usr/local/etc/php/conf.d/php-pdo-oci.ini

# For code coverage (mutation testing)
RUN pecl install pcov && docker-php-ext-enable pcov

# Composer

COPY --from=composer /composer /usr/bin/composer

# Code

COPY . /code
WORKDIR /code

# PHP packages

RUN composer install
57 changes: 57 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
run:
docker compose run \
--rm \
--entrypoint $(CMD) \
php

test-all: test-base \
test-driver-all
test-driver-all: test-driver-sqlite \
test-driver-mysql \
test-driver-mariadb \
test-driver-pgsql \
test-driver-mssql \
test-driver-oracle
test-base: testsuite-Db
test-driver-sqlite: testsuite-Sqlite
test-driver-mysql: testsuite-Mysql
test-driver-mariadb:
docker compose run \
--rm \
--entrypoint "vendor/bin/phpunit --testsuite Mysql $(RUN_ARGS)" \
-e YII_MYSQL_TYPE=mariadb \
php
test-driver-pgsql: testsuite-Pgsql
test-driver-mssql: testsuite-Mssql
test-driver-oracle:
docker compose run \
--rm \
--entrypoint "bash -c -l 'vendor/bin/phpunit --testsuite Oracle $(RUN_ARGS)'" \
php

testsuite-%:
docker compose run \
--rm \
--entrypoint "vendor/bin/phpunit --testsuite $(subst testsuite-,,$@) $(RUN_ARGS)" \
php

mutation: CMD="\
vendor/bin/roave-infection-static-analysis-plugin \
--threads=2 \
--min-msi=0 \
--min-covered-msi=100 \
--ignore-msi-with-no-mutations \
--only-covered"
mutation: run

static-analysis: CMD="vendor/bin/psalm --no-cache"
static-analysis: run

rector: CMD="vendor/bin/rector"
rector: run

composer-require-checker: CMD="vendor/bin/composer-require-checker"
composer-require-checker: run

shell: CMD="bash"
shell: run
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@
},
"autoload-dev": {
"psr-4": {
"Yiisoft\\ActiveRecord\\": "vendor/yiisoft/active-record/src",
"Yiisoft\\Db\\Migration\\": "vendor/yiisoft/db-migration/src",
"Yiisoft\\Db\\Mssql\\": "vendor/yiisoft/db-mssql/src",
"Yiisoft\\Db\\Mysql\\": "vendor/yiisoft/db-mysql/src",
"Yiisoft\\Db\\Oracle\\": "vendor/yiisoft/db-oracle/src",
"Yiisoft\\Db\\Pgsql\\": "vendor/yiisoft/db-pgsql/src",
"Yiisoft\\Db\\Sqlite\\": "vendor/yiisoft/db-sqlite/src",
"Yiisoft\\Db\\Tests\\": "tests",
"Yiisoft\\ActiveRecord\\Tests\\": "vendor/yiisoft/active-record/tests",
"Yiisoft\\Db\\Mssql\\Tests\\": "vendor/yiisoft/db-mssql/tests",
Expand Down
147 changes: 147 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
services:
arogachev marked this conversation as resolved.
Show resolved Hide resolved
php:
build: .
volumes:
- ./src:/code/src
- ./tests:/code/tests
- ./composer.json:/code/composer.json
- ./phpunit.xml.dist:/code/phpunit.xml.dist
environment:
YII_MYSQL_DATABASE: yii
YII_MYSQL_HOST: mysql
YII_MYSQL_PORT: 3306
YII_MYSQL_USER: root
YII_MYSQL_PASSWORD: root
YII_MYSQL_TYPE: mysql

YII_MARIADB_DATABASE: yii
YII_MARIADB_HOST: mariadb
YII_MARIADB_PORT: 13306
YII_MARIADB_USER: root
YII_MARIADB_PASSWORD: root

YII_PGSQL_DATABASE: yii
YII_PGSQL_HOST: postgres
YII_PGSQL_PORT: 5432
YII_PGSQL_USER: postgres
YII_PGSQL_PASSWORD: postgres

YII_MSSQL_DATABASE: tempdb
YII_MSSQL_HOST: mssql
YII_MSSQL_PORT: 1433
YII_MSSQL_USER: SA
YII_MSSQL_PASSWORD: YourStrong!Passw0rd

YII_ORACLE_SID: FREE
YII_ORACLE_DATABASE: FREEPDB1
YII_ORACLE_HOST: oracle
YII_ORACLE_PORT: 1521
YII_ORACLE_USER: system
YII_ORACLE_PASSWORD: sys_user_password

ORACLE_PASSWORD: sys_user_password
APP_USER: my_user
APP_USER_PASSWORD: password_i_should_change
command: tail -F anything
depends_on:
mysql:
condition: service_healthy
mariadb:
condition: service_healthy
postgres:
condition: service_healthy
mssql:
condition: service_healthy
oracle:
condition: service_healthy
mysql:
image: mysql:9
ports:
- "3306:3306"
volumes:
- type: tmpfs
target: /var/lib/mysql
environment:
MYSQL_DATABASE: yii
MYSQL_ROOT_PASSWORD: root
MYSQL_ROOT_HOST: "%"
healthcheck:
test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost", "-uroot" ]
interval: 5s
timeout: 5s
retries: 20
mariadb:
image: mariadb:11
ports:
- "13306:3306"
volumes:
- type: tmpfs
target: /var/lib/mysql
environment:
MYSQL_DATABASE: yii
MYSQL_ROOT_PASSWORD: root
MYSQL_ROOT_HOST: "%"
MYSQL_TCP_PORT: 13306
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
start_period: 10s
interval: 10s
timeout: 5s
retries: 30
postgres:
image: postgres:17
ports:
- "5432:5432"
volumes:
- type: tmpfs
target: /var/lib/postgresql/data
environment:
POSTGRES_DB: yii
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
interval: 5s
timeout: 5s
retries: 5
mssql:
image: mcr.microsoft.com/mssql/server:2022-latest
ports:
- "1433:1433"
user: root
volumes:
- mssql-data:/var/opt/mssql/data
- mssql-log:/var/opt/mssql/log
- mssql-secrets:/var/opt/mssql/secrets
environment:
SA_PASSWORD: YourStrong!Passw0rd
ACCEPT_EULA: Y
healthcheck:
test: /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "$${SA_PASSWORD}" -Q "SELECT 1" -b -C -o /dev/null
interval: 10s
timeout: 3s
retries: 100
start_period: 10s
oracle:
build:
context: docker/oracle
ports:
- "1521:1521"
volumes:
- oracle-data:/opt/oracle/oradata
environment:
ORACLE_PASSWORD: sys_user_password
APP_USER: my_user
APP_USER_PASSWORD: password_i_should_change
healthcheck:
test: ["CMD", "healthcheck.sh"]
interval: 10s
timeout: 5s
retries: 100
start_period: 5s
start_interval: 5s
volumes:
mssql-data:
mssql-log:
mssql-secrets:
oracle-data:
3 changes: 3 additions & 0 deletions docker/oracle/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM gvenzl/oracle-free:23

RUN chown -R 54321:54321 /opt/oracle/oradata && chmod 0777 /opt/oracle/oradata
Loading
Loading