Skip to content

Commit

Permalink
add CI pipeline
Browse files Browse the repository at this point in the history
add github action

fix

add migration

try fix elk

fix ci

fix ci

fix ci

fix ci

fix ci

fix ci

fix ci

fix ci
  • Loading branch information
bailletced committed Dec 3, 2024
1 parent 4942ec1 commit 37710ef
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 12 deletions.
1 change: 0 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ PYTHONWARNINGS="ignore:Unverified HTTPS request"
###< synchro scripts ###

ELASTIC_PASSWORD=admin
ELASTICSEARCH_HOST=http://elasticsearch:9200
ELASTICSEARCH_IRI=https://elastic:admin@elasticsearch:9200
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,30 @@ jobs:
MYSQL_ROOT_PASSWORD: symfony
MYSQL_DATABASE: symfony
ports:
- 3306/tcp
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 --name=mysql
elasticsearch:
image: elasticsearch:8.16.0
ports:
- 9200/tcp
- 9200:9200
env:
ELASTIC_PASSWORD: admin
discovery.type: single-node
xpack.security.enabled: true
bootstrap.memory_lock: true
ES_JAVA_OPTS: -Xms512m -Xmx512m
options: --health-cmd="curl http://localhost:9200/_cluster/health" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.3"
tools: phpunit-bridge
extensions: mbstring, xml, ctype, intl, iconv, json, redis, mysql
extensions: mbstring, xml, ctype, intl, iconv, json, mysql
ini-values: date.timezone=Europe/Paris
- uses: actions/checkout@v4
- name: Create .env.test.local
# TODO remove LOCK_DSN on Symfony update
run: echo -e "DB_NAME_SUFFIX=\\ELASTICSEARCH_IRI=https://elastic:admin@elasticsearch:${{ job.services.elasticsearch.ports['9200'] }}" > .env.test.local
run: echo -e "DB_NAME_SUFFIX=\\nELASTICSEARCH_IRI=http://elastic:[email protected]:${{ job.services.elasticsearch.ports['9200'] }}" > .env.test.local
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
Expand All @@ -49,8 +53,6 @@ jobs:
restore-keys: ${{ runner.os }}-composer-
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Generate SSL Key for JWT
run: php bin/console lexik:jwt:generate-keypair
- name: Run migrations
run: |
php bin/console doctrine:migrations:migrate --no-interaction || echo "No migrations found or migration failed"
Expand All @@ -69,7 +71,6 @@ jobs:
- name: lint:container
if: always()
run: php bin/console lint:container
- name: lint:twig
- name: lint:yaml
if: always()
run: php bin/console lint:yaml config src
Expand Down
4 changes: 1 addition & 3 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ services:
- xpack.security.enrollment.enabled=true
- bootstrap.memory_lock=true
- ES_JAVA_OPTS=-Xms512m -Xmx512m # 512mo HEAP
- ELASTIC_PASSWORD=admin
networks:
- app-network
ports:
- 9200:9200
volumes:
- ./elastic/data:/usr/share/elasticsearch/elastic/data

backend:
extra_hosts: *default-extra_hosts
Expand All @@ -62,7 +61,6 @@ services:
environment:
SERVER_NAME: localhost api.openchurch.local admin.openchurch.local
DATABASE_URL: mysql://root:openchurch@db:3306/openchurch?serverVersion=11.5.2-MariaDB&charset=utf8mb4

volumes:
openchurch_db_data: {}

Expand Down
7 changes: 7 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,10 @@ services:
App\Core\Infrastructure\ElasticSearch\Helper\OfficialElasticSearchHelper:
arguments:
$elasticsearchHost: "%env(ELASTICSEARCH_IRI)%"

App\Core\Infrastructure\Doctrine\FixDoctrineMigrationTableSchema:
autoconfigure: false
arguments:
$dependencyFactory: "@doctrine.migrations.dependency_factory"
tags:
- { name: "doctrine.event_listener", event: "postGenerateSchema" }
29 changes: 29 additions & 0 deletions migrations/Version20241203150437.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20241203150437 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE field ADD CONSTRAINT FK_5BF54558FDA7B0BF FOREIGN KEY (community_id) REFERENCES community (id)');
$this->addSql('ALTER TABLE field ADD CONSTRAINT FK_5BF5455851D1B0E8 FOREIGN KEY (community_val_id) REFERENCES community (id)');
$this->addSql('ALTER TABLE field ADD CONSTRAINT FK_5BF5455882D54272 FOREIGN KEY (place_val_id) REFERENCES place (id)');
$this->addSql('ALTER TABLE field ADD CONSTRAINT FK_5BF545583414710B FOREIGN KEY (agent_id) REFERENCES agent (id)');
$this->addSql('ALTER TABLE field ADD CONSTRAINT FK_5BF54558DA6A219 FOREIGN KEY (place_id) REFERENCES place (id)');
}

public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE field DROP FOREIGN KEY FK_5BF54558FDA7B0BF');
$this->addSql('ALTER TABLE field DROP FOREIGN KEY FK_5BF5455851D1B0E8');
$this->addSql('ALTER TABLE field DROP FOREIGN KEY FK_5BF5455882D54272');
$this->addSql('ALTER TABLE field DROP FOREIGN KEY FK_5BF545583414710B');
$this->addSql('ALTER TABLE field DROP FOREIGN KEY FK_5BF54558DA6A219');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace App\Core\Infrastructure\Doctrine;

use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\Migrations\DependencyFactory;
use Doctrine\Migrations\Metadata\Storage\TableMetadataStorageConfiguration;
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
use Webmozart\Assert\Assert;

/** @see https://github.com/doctrine/migrations/issues/1406 */
final class FixDoctrineMigrationTableSchema
{
private TableMetadataStorageConfiguration $configuration;

public function __construct(
private readonly DependencyFactory $dependencyFactory,
) {
$configuration = $this->dependencyFactory->getConfiguration()->getMetadataStorageConfiguration();

Assert::notNull($configuration);
Assert::isInstanceOf($configuration, TableMetadataStorageConfiguration::class);

$this->configuration = $configuration;
}

/**
* @throws SchemaException
* @throws Exception
*/
public function postGenerateSchema(GenerateSchemaEventArgs $args): void
{
$schema = $args->getSchema();
$table = $schema->createTable($this->configuration->getTableName());
$table->addColumn(
$this->configuration->getVersionColumnName(),
'string',
['notnull' => true, 'length' => $this->configuration->getVersionColumnLength()],
);
$table->addColumn($this->configuration->getExecutedAtColumnName(), 'datetime', ['notnull' => false]);
$table->addColumn($this->configuration->getExecutionTimeColumnName(), 'integer', ['notnull' => false]);

$table->setPrimaryKey([$this->configuration->getVersionColumnName()]);
}
}

0 comments on commit 37710ef

Please sign in to comment.