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

2396-novy-docker #2409

Merged
merged 36 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
53613be
New docker for app - php, mysql, mysql-test, network, routing
Oct 19, 2023
1f6785a
add selenium
Oct 19, 2023
2f0a25d
add adminer for better db view
Oct 19, 2023
ff69a11
remove old docker configuration
Oct 19, 2023
b3943cd
Remove deprecated class, method
Oct 23, 2023
bdb9b68
Remove localhost domain
Oct 23, 2023
d9155ae
add php container for testing
Oct 23, 2023
bf63331
Add env supprot for yml files
Oct 23, 2023
17365de
Add tests requiremnst to composer
Oct 23, 2023
2f08542
Movo temp to one folder
Oct 23, 2023
d641737
Add consol command cache clear
Oct 23, 2023
aa24658
Add console command 'drop database' for testing purposes
Oct 23, 2023
56b00d2
Use env variables in all config files
Oct 23, 2023
898d036
remove cleanup sql. Add fixtures sql file
Oct 23, 2023
8bb6cec
Rewriting acceptance tests to standard Path classes
Oct 23, 2023
b8393d8
EVN variable support for Codeception
Oct 23, 2023
be65424
Fix build.xml for new test structure
Oct 23, 2023
ace2777
Add makefile with the most common commands
Oct 23, 2023
1d376e5
remove delete docker override
Oct 23, 2023
978c376
unification of container names
Oct 24, 2023
f5ff94c
update gitlab action config for new docker compose setup
Oct 24, 2023
12099ff
env for static analysis
Oct 24, 2023
67e44bf
fix CI acceptance test
Oct 24, 2023
69dfc5b
coding standard tests
Oct 24, 2023
2d5e5c0
fix init migration interactions
Oct 24, 2023
1d3cdbd
Update docs
Oct 24, 2023
a7fa91d
Add UPLOAD_MAX_FILESIZE to docker php image
Oct 25, 2023
cbb3f4f
Refactoring UPLOAD_MAX_FILESIZE
Oct 25, 2023
d3fa4ce
main.yml cleanup
Oct 28, 2023
9be1b30
main.yml cleanup - acceptance
Oct 28, 2023
9039032
remove assets port from php container
Oct 30, 2023
e14ba0f
change mysql collation
Oct 30, 2023
f8b7e97
remove ngrok.io
Oct 30, 2023
3ec3c2e
Setup headless for chrome - acceptance test
Nov 9, 2023
5c6defa
Acceptance test - enable UI on localhost
Nov 9, 2023
f9b0acc
revert acceptance test info back to -vv
Nov 9, 2023
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
21 changes: 8 additions & 13 deletions .docs/instalace.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ Aplikace vyžaduje:
- Composer
- Yarn

Všechny potřebné nástroje jsou instalovány v příslušných kontejnerech
Na hostujícím stroji musí být ve výchozím stavu volné porty 80 a 3306. Port 3306 je možné použít pro propojená s IDE

## Docker
Pro lokální vývoj je připraven Docker container a konfigurace pro **docker-compose**.
Pro lokální vývoj je připraven Docker container a konfigurace pro **docker compose**.
Všechny potřebné příkazy jsou definované v Make file

```bash
docker volume create --name hskauting_mysql
docker compose up -d # Spustí container v detached modu
make up # Spustí container v detached modu
```

V kontejneru je možné spustit bash pomocným skriptem:
```bash
docker/ssh
make enter
```

## Nastavení hosts
Expand All @@ -30,12 +33,4 @@ Stačí přidat tento řádek do souboru `/etc/hosts`:
```

## Příprava projektu
V kontejneru stačí spustit příkaz `phing init`.

**Poznámka**: Při commitování se automaticky opravuje coding standard v PHP - to však vyžaduje lokálně nainstalované PHP.
Pokud nemáte mimo kontejner instalované PHP alespoň ve verzi jako používá Hospodaření,
je možné automatickou opravu coding standardu vypnout nastavením proměnné `HUSKY_SKIP_INSTALL` na `true` při instalaci
`yarn` závislostí. Tedy např.:

- `export HUSKY_SKIP_INSTALL=true; phing init`
- `HUSKY_SKIP_INSTALL=true yarn install`
Stačí spustit příkaz `make init`.
19 changes: 17 additions & 2 deletions .docs/nastroje.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,37 @@ Pro testování používáme [Codeception](http://codeception.com/).

Testy lze spustit příkazem v kontejneru:
```bash
phing tests # Jednotkové + Integrační testy + Akceptační testy
phing tests-unit # Pouze jednotkové testy
phing tests-integration # Pouze integrační testy
phing tests # Jednotkové + Integrační testy
phing tests-acceptance # Akceptační testy
```

nebo pomocí make přímo na hostujícím stroji:
```bash
make tests-all # Jednotkové + Integrační testy + Akceptační testy
make tests-unit # Pouze jednotkové testy
make tests-integration # Pouze integrační testy
make tests-acceptance # Akceptační testy
```


## Coding standard
Coding standard vychází z [Doctrine Coding Standardu](https://github.com/doctrine/coding-standard).
Zda je projekt v souladu s CS lze ověřit pomocí příkazu v kontejneru:

```bash
phing coding-standard
phing coding-standard-ci
```

Automaticky lze nechat opravit pomocí:

```bash
./vendor/bin/phpcbf app
```

Nebo opět přímo z hostujícího stroje pomocí make:

```bash
make coding-standard
```
11 changes: 10 additions & 1 deletion .docs/tipy-pro-testovani.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,20 @@ Jednotlivé testy:
vendor/bin/codecept run <cesta k souboru>
```

Všechny daného typu:
Všechny daného typu lze spustit v kontejneru:
```bash
phing tests
phing tests-acceptance
phing tests-integration
phing tests-unit
phing tests-with-coverage
```

Pomocí make na hostitelském stroji:
```bash
make tests-all
make tests-acceptance
make tests-integration
make tests-unit
make tests-with-coverage
```
5 changes: 5 additions & 0 deletions .env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DB_HOST=mysql
DB_USER=hskauting
DB_PASSWORD=hskauting
DB_NAME=hskauting
DEVELOPMENT_MACHINE=true
5 changes: 5 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DB_HOST=mysql-test
DB_USER=hskauting
DB_PASSWORD=hskauting
DB_NAME=hskauting
DB_TEST=true
52 changes: 17 additions & 35 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ jobs:
restore-keys: |
${{ runner.os }}-composer-
- run: composer install
- name: Remove development docker-compose override
run: rm docker-compose.override.yml
- name: Fix permissions
run: chown 1000:1000 . -R && chmod 777 . -R
- name: Create tarball
Expand Down Expand Up @@ -59,10 +57,6 @@ jobs:
runs-on: ubuntu-22.04
needs: workdir
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
- name: Download workdir
uses: actions/download-artifact@v1
with:
Expand All @@ -71,8 +65,7 @@ jobs:
- name: Extract workdir
run: tar -xzpf workdir.tar.gz
- name: Start application containers
run: docker-compose up -d mysql-test
- run: docker-compose run -T -u www-data app phing tests-integration
run: docker compose -f docker/docker-compose.yml run -T php-test phing tests-integration

collect-code-coverage:
name: "Collect code coverage"
Expand All @@ -87,10 +80,8 @@ jobs:
path: .
- name: Extract workdir
run: tar -xzpf workdir.tar.gz
- name: Start application containers
run: docker-compose up -d app mysql-test
- name: Run tests with coverage
run: docker-compose exec -T -u www-data app phing tests-with-coverage
run: docker compose -f docker/docker-compose.yml run -T php-test phing tests-with-coverage
- name: Upload code coverage
uses: codecov/codecov-action@v3
with:
Expand All @@ -110,30 +101,15 @@ jobs:
path: .
- name: Extract workdir
run: tar -xzpf workdir.tar.gz
- name: Start application containers
run: docker-compose up -d
- name: Append to .env file
run: echo -e "\nHEADLESS='--headless'" >> .env.test
- name: Init app
run: docker compose -f docker/docker-compose.yml run -T php-test phing app-init
- name: Start selenium container
run: docker compose -f docker/docker-compose.yml up -d selenium nginx
- run: mv app/config/config.ci.local.neon app/config/config.local.neon
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
# Copy & paste from https://github.com/actions/cache/blob/master/examples.md#node---yarn
- name: Get yarn cache
id: yarn-cache
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- run: npm install -g yarn
- name: Build frontend assets
run: yarn install && yarn build
- name: Prepare database
run: docker-compose exec -T -u www-data app bin/console migrations:migrate --no-interaction
- run: docker-compose exec -T -u www-data app phing tests-acceptance
- name: Run acceptance tests
run: docker compose -f docker/docker-compose.yml run -T php-test phing tests-acceptance
- uses: actions/upload-artifact@v3
if: failure()
with:
Expand All @@ -143,6 +119,12 @@ jobs:
static-analysis:
name: "Run PHPStan analysis"
runs-on: ubuntu-22.04
env:
DB_HOST: mysql-test
DB_USER: hskauting
DB_PASSWORD: hskauting
DB_NAME: hskauting
DB_TEST: true
container:
image: skaut/lebeda:8.1
needs: workdir
Expand Down Expand Up @@ -172,7 +154,7 @@ jobs:
path: .
- name: Extract workdir
run: tar -xzpf workdir.tar.gz
- run: phing coding-standard
- run: phing coding-standard-ci

latte-lint:
name: "Lint Latte templates"
Expand Down
39 changes: 39 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
CONTAINER_PHP=hskauting.app
CONTAINER_PHP_TEST=hskauting.app-test
CONTAINER_DB=hskauting.mysql
CONTAINER_DB_TEST=hskauting.mysql-test

COMPOSE_FILE=-f docker/docker-compose.yml

CONSOLE?=

up: down
docker compose ${COMPOSE_FILE} up -d --force-recreate

down:
docker compose ${COMPOSE_FILE} down --remove-orphans

enter:
@docker exec -it ${CONTAINER_PHP} bash

init:
docker exec -it $(CONTAINER_PHP) composer install
docker exec -it $(CONTAINER_PHP) /app/vendor/bin/phing app-init

tests-all:
docker exec -it ${CONTAINER_PHP_TEST} /app/vendor/bin/phing tests

tests-unit:
docker exec -it ${CONTAINER_PHP_TEST} /app/vendor/bin/phing tests-unit

tests-integration:
docker exec -it ${CONTAINER_PHP_TEST} /app/vendor/bin/phing tests-integration

tests-acceptance:
docker exec -it ${CONTAINER_PHP_TEST} /app/vendor/bin/phing tests-acceptance

static-analysis:
docker exec -it ${CONTAINER_PHP} /app/vendor/bin/phing static-analysis

coding-standard:
docker exec -it ${CONTAINER_PHP} /app/vendor/bin/phing coding-standard
2 changes: 2 additions & 0 deletions app/AccountancyModule/Components/BaseControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
abstract class BaseControl extends Control
{
public const MAX_FILE_SIZE_VALUE = 15 * 1024 * 1024;

abstract public function render(): void;

public function getPresenter(): BasePresenter|null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected function createComponentUploadForm(): BaseForm
BaseForm::MIME_TYPE,
'Neplatný formát skenu, povolené formáty jsou ' . implode(', ', array_keys(IScanStorage::ALLOWED_MIME_TYPES)) . '.',
IScanStorage::ALLOWED_MIME_TYPES,
)->addRule(BaseForm::MAX_FILE_SIZE, 'Maximální povolená velikost souboru je 15 MB', 15 * 1024 * 1024);
)->addRule(BaseForm::MAX_FILE_SIZE, 'Maximální povolená velikost souboru je 15 MB', BaseControl::MAX_FILE_SIZE_VALUE);

$form->addSubmit('submit', 'Nahrát');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected function createComponentUploadForm(): BaseForm
BaseForm::MIME_TYPE,
'Neplatný formát skenu, povolené formáty jsou ' . implode(', ', array_keys(IScanStorage::ALLOWED_MIME_TYPES)) . '.',
IScanStorage::ALLOWED_MIME_TYPES,
)->addRule(BaseForm::MAX_FILE_SIZE, 'Maximální povolená velikost souboru je 15 MB', 15 * 1024 * 1024);
)->addRule(BaseForm::MAX_FILE_SIZE, 'Maximální povolená velikost souboru je 15 MB', BaseControl::MAX_FILE_SIZE_VALUE);

$form->addSubmit('submit', 'Ok');

Expand Down
64 changes: 64 additions & 0 deletions app/Console/MigrationsDropCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

namespace Console;

use Doctrine\DBAL\Exception;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use function getenv;
use function sprintf;

class MigrationsDropCommand extends Command
juradee marked this conversation as resolved.
Show resolved Hide resolved
{
// phpcs:disable SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
/** @var string|null $defaultName The default command name */
protected static $defaultName = 'migrations:drop-all-tables-views';

public function __construct(private EntityManagerInterface $em)
{
parent::__construct();
}

protected function configure(): void
{
$this->setName(self::$defaultName)
->setDescription('Drops all tables from the database');
}

/** @throws Exception */
protected function execute(InputInterface $input, OutputInterface $output): int
{
if (getenv('DB_TEST') !== 'true') {
$output->writeln('Cannot run on non testing environment');

return Command::FAILURE;
}

$conn = $this->em->getConnection();
$schemaManager = $conn->getSchemaManager();

// Drop tables
$tables = $schemaManager->listTables();
$conn->executeStatement('SET foreign_key_checks = 0');
foreach ($tables as $table) {
$tableName = $table->getName();
$conn->executeStatement(sprintf('DROP TABLE %s', $tableName));
$output->writeln(sprintf('Dropped table %s', $tableName));
}

// Drop views
$views = $schemaManager->listViews();
foreach ($views as $view) {
$viewName = $view->getName();
$conn->executeStatement(sprintf('DROP VIEW %s', $viewName));
$output->writeln(sprintf('Dropped view %s', $viewName));
}

return Command::SUCCESS;
}
}
9 changes: 7 additions & 2 deletions app/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

declare(strict_types=1);

use Nette\Bootstrap\Configurator;

require __DIR__ . '/../vendor/autoload.php';

setlocale(LC_COLLATE, 'cs_CZ.utf8');
Expand All @@ -11,16 +13,19 @@

putenv('TMPDIR=' . $tempDir);

$configurator = new Nette\Configurator();
$env = getenv();

$configurator = new Configurator();
$configurator->setDebugMode(getenv('DEVELOPMENT_MACHINE') === 'true' ?: '89.177.225.213');
$configurator->enableDebugger($logDir);
$configurator->enableTracy($logDir);
$configurator->setTempDirectory($tempDir);

$configurator->createRobotLoader()
->addDirectory(__DIR__)
->register(true);

$configurator->addConfig(__DIR__ . '/config/config.neon');
$configurator->addDynamicParameters(['env' => $env]);
$configurator->addConfig(__DIR__ . '/config/config.local.neon');

$configurator->addParameters(['logDir' => $logDir]);
Expand Down
3 changes: 3 additions & 0 deletions app/config/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ extensions:
skautis: Skautis\Nette\SkautisExtension
messenger: Fmasa\Messenger\DI\MessengerExtension
console: Contributte\Console\DI\ConsoleExtension(%consoleMode%)
console.cache: Contributte\Console\Extra\DI\CacheConsoleExtension(%consoleMode%)

search:
command handlers:
Expand Down Expand Up @@ -110,6 +111,8 @@ services:
- Model\Common\Services\MessengerCommandBus(@messenger.commandBus.bus)
- Model\Common\Services\MessengerQueryBus(@messenger.queryBus.bus)
- Model\Common\Services\MessengerEventBus(@messenger.eventBus.bus)
- Console\MigrationsDropCommand


skautisCache:
factory: Nette\Caching\Cache(namespace: 'skautis')
Expand Down
Loading
Loading