Skip to content

Commit

Permalink
Add PHP CLI service and improve Docker setup
Browse files Browse the repository at this point in the history
Added a PHP CLI service definition in `docker-compose.yaml` and created the appropriate Dockerfile. Enhanced Composer dependencies and updated Makefile with new commands for initializing and managing the application containers. Updated `.gitignore` to exclude Docker database files.

Signed-off-by: mesilov <[email protected]>
  • Loading branch information
mesilov committed Oct 6, 2024
1 parent 4c2f9b9 commit ef8ab43
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/.idea*
/vendor
/.cache
/docker/db
composer.phar
composer.lock
.phpunit.result.cache
Expand Down
76 changes: 75 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#
# For the full copyright and license information, please view the MIT-LICENSE.txt
# file that was distributed with this source code.
#!/usr/bin/env make

export COMPOSE_HTTP_TIMEOUT=120
export DOCKER_CLIENT_TIMEOUT=120

default:
@echo "make needs target:"
Expand Down Expand Up @@ -31,4 +35,74 @@ docker-up:
docker compose up --build -d

docker-down:
docker compose down --remove-orphans
docker compose down --remove-orphans

#======================================
restart: down up

init:
@echo "remove all containers"
docker-compose down --remove-orphans
@echo "build containers"
docker-compose build
@echo "install dependencies"
docker-compose run --rm php-cli composer install
# @echo "run database migrations…"
# docker-compose run --rm php-cli php bin/doctrine doctrine:migrations:migrate --no-interaction
@echo "change owner of var folder for access from container"
docker-compose run --rm php-cli chown -R www-data:www-data /var/www/html/var/
@echo "run application…"
docker-compose up -d


up:
@echo "run application…"
docker-compose up -d

down:
@echo "stop application and remove containers"
docker-compose down --remove-orphans

down-clear:
@echo "stop application and remove containers with volumes"
docker-compose down -v --remove-orphans


composer-install:
@echo "install dependencies…"
docker-compose run --rm php-cli composer install

composer-update:
@echo "update dependencies…"
docker-compose run --rm php-cli composer update

# вызов composer с любыми параметрами
# Примеры:
# make composer install
# make composer "install --no-dev"
composer:
docker-compose run --rm php-cli composer $(filter-out $@,$(MAKECMDGOALS))

%:
@: # silence

dev-dump-cache:
composer dumpautoload

#======================================
cli-bash:
docker-compose run --rm php-cli sh $(filter-out $@,$(MAKECMDGOALS))

# static code analysis
test-run-phpstan:
docker-compose run --rm php-cli php vendor/bin/phpstan analyse --memory-limit 2G

# unit-tests
test-run-unit-tests:
docker-compose run --rm php-cli php vendor/bin/phpunit --testsuite=unit --testdox

# functional-tests, work with test database
test-run-functional-tests:
docker-compose run --rm php-cli php bin/doctrine orm:schema-tool:drop --force
docker-compose run --rm php-cli php bin/doctrine orm:schema-tool:create
docker-compose run --rm php-cli php vendor/bin/phpunit --testsuite=functional --testdox
25 changes: 19 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@
"SaaS"
],
"type": "library",
"homepage": "https://github.com/mesilov/bitrix24-app-core",
"homepage": "https://github.com/mesilov/bitrix24-php-lib",
"license": "MIT",
"authors": [
{
"name": "Maksim Mesilov",
"homepage": "https://github.com/mesilov/"
}
],
"support": {
"issues": "https://github.com/mesilov/bitrix24-php-lib/issues?state=open",
"source": "https://github.com/mesilov/bitrix24-php-lib"
},
"minimum-stability": "stable",
"config": {
"sort-packages": true,
"allow-plugins": {
Expand All @@ -28,6 +33,7 @@
"php": "8.3.*",
"ext-json": "*",
"ext-curl": "*",
"ext-bcmath": "*",
"ext-intl": "*",
"psr/log": "^3",
"fig/http-message-util": "^1",
Expand All @@ -36,14 +42,21 @@
"nesbot/carbon": "^3",
"moneyphp/money": "^4",
"mesilov/bitrix24-php-sdk": "^2",
"doctrine/orm": "^2",
"doctrine/doctrine-bundle": "^2",
"doctrine/doctrine-migrations-bundle": "^3",
"doctrine/orm": "^3",
"doctrine/doctrine-bundle": "*",
"doctrine/doctrine-migrations-bundle": "*",
"knplabs/knp-paginator-bundle": "^6",
"symfony/event-dispatcher": "^7",
"symfony/serializer": "^7",
"symfony/uid": "^7",
"knplabs/knp-paginator-bundle": "^6"
"symfony/yaml": "^7",
"symfony/cache": "^7",
"symfony/console": "^7",
"symfony/dotenv": "^7",
"symfony/framework-bundle": "^7"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.59",
"monolog/monolog": "^3",
"fakerphp/faker": "^1",
"phpstan/phpstan": "^1",
Expand All @@ -62,7 +75,7 @@
"autoload-dev": {
"psr-4": {
"Bitrix24\\SDK\\Lib\\Tests\\": "tests",
"Bitrix24\\SDK\\Tests\\":"vendor/mesilov/bitrix24-php-sdk/tests"
"Bitrix24\\SDK\\Tests\\": "vendor/mesilov/bitrix24-php-sdk/tests"
}
}
}
26 changes: 25 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,28 @@ services:
volumes:
- ./docker/postgres/data:/var/lib/postgresql/data
restart: always

php-cli:
build:
context: ./docker/php-cli
links:
- b24-account-test-database
volumes:
- .:/var/www/html
working_dir: /var/www/html
b24-account-test-database:
image: postgres:${POSTGRES_VERSION:-15}-alpine
restart: unless-stopped
environment:
POSTGRES_DB: ${POSTGRES_DB:-b24AccountTest}
# You should definitely change the password in production
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-b24AccountTest}
POSTGRES_USER: ${POSTGRES_USER:-b24AccountTest}
PGDATA: "/var/lib/postgresql/data/pgdata"
container_name: b24-account-test-database
ports:
- '5432:5432'
expose:
- 5432
volumes:
- ./Init Database:/docker-entrypoint-initdb.d
- ./docker/db:/var/lib/postgresql/data
9 changes: 9 additions & 0 deletions docker/php-cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM php:8.3-cli-alpine

RUN apk add unzip libpq-dev git icu-dev \
&& docker-php-ext-install bcmath pdo pdo_pgsql intl \
&& docker-php-ext-enable bcmath pdo pdo_pgsql intl

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/bin --filename=composer --quiet

ENV COMPOSER_ALLOW_SUPERUSER 1

0 comments on commit ef8ab43

Please sign in to comment.