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

Feature/performance #6

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RR_VERSION=2024.1.1
PHP_IMAGE_VERSION=8.3-cli-alpine

46 changes: 0 additions & 46 deletions .github/workflows/ci.yml

This file was deleted.

45 changes: 0 additions & 45 deletions .github/workflows/cicd-dev.yml

This file was deleted.

62 changes: 62 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Deploy

on:
pull_request:
types:
- labeled

jobs:
deploy:
if: github.event.label.name == 'REDELIVRE'
runs-on: ubuntu-latest

steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
# list of Docker images to use as base name for tags
images: |
docker.io/hacklab/mapasculturais
# ghcr.io/username/app
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
type=sha,format=long
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to Docker Hub
# if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v4
with:
file: ./docker/Dockerfile
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
with:
prefix: RL_
-
name: deploy to cluster
uses: steebchen/[email protected]
with: # defaults to latest kubectl binary version
config: ${{ secrets.KUBE_CONFIG_DATA }}
command: set image --record deployment/mapasculturais -nredelivre-mapas-dev mapas=docker.io/hacklab/mapasculturais:sha-${{ github.sha }}
35 changes: 35 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Test

on:
pull_request:
branches:
- main

jobs:
build-test:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Install composer and dependencies
uses: php-actions/composer@v6
with:
php_extensions: xdebug zip sockets pdo_pgsql intl opcache xml curl iconv xmlwriter simplexml
- name: PHPUnit Tests
uses: php-actions/phpunit@v3
env:
XDEBUG_MODE: coverage
with:
bootstrap: vendor/autoload.php
configuration: phpunit.xml
php_extensions: xdebug zip sockets pdo_pgsql intl opcache xml curl iconv xmlwriter simplexml
args: tests --coverage-clover ./coverage.xml

- name: Upload to Codecov
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODE_COV_TOKEN }}
files: ./coverage.xml
verbose: true
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ src/themes/BaseV1/assets/css/main.css.map
.idea
.phpunit.result.cache
.php-cs-fixer.cache
docker-data
public/assets/
docker-data/
src/.phpdoc
.phpunit*
.phpdocs*
.env
2 changes: 1 addition & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart

tasks:
- init: docker compose -f dev/docker-compose.yml up -d
- init: docker compose -f dev/docker-compose.yml up -d && cd src && pnpm i && pnpm run build
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,47 @@ Temos muito a agradecer tudo que foi construído até a versão XXX, e a partir

---

## Instalação rápida com docker compose

`docker compose up -d`

### Ferramentas

#### PHP Composer

`docker run --rm -it -v $PWD:/app composer:latest install`

#### Migração do Banco de Dados

`docker compose exec backend php src/tools/apply-updates.php`
`docker compose exec backend php src/tools/apply-multicore-db-update.php`

#### Frontend

`nvm use 18 && cd src && pnpm install --recursive && pnpm build`

npx oxlint@latest

#### Phpdoc

`docker run --rm -v ${PWD}/src:/data phpdoc/phpdoc:3`

#### Phpunit

`docker compose exec backend ./vendor/bin/phpunit`

#### Phpcs

`docker compose exec backend ./vendor/bin/phpcs -d memory_limit=1024M src/**/*.php`

#### Phplint

`docker run --rm -it -v $PWD:/app overtrue/phplint:latest /app/src/`

#### HTTP Endpoints

`egrep -r "function API_|function GET_|function POST_|function PATCH_|function PUT_|function DELETE_|function ALL_" src`

## Instalação
A maneira mais simples e segura para instalar o MapaCultural é seguindo [Este tutorial]()

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

declare(strict_types=1);

$psr17Factory = new Nyholm\Psr7\Factory\Psr17Factory();
$containerBuilder = new DI\ContainerBuilder();
$containerBuilder->addDefinitions([
Psr\Http\Message\ResponseFactoryInterface::class => $psr17Factory,
Psr\Http\Message\ServerRequestFactoryInterface::class => $psr17Factory,
Psr\Http\Message\StreamFactoryInterface::class => $psr17Factory,
Psr\Http\Message\UploadedFileFactoryInterface::class => $psr17Factory,
Spiral\RoadRunner\WorkerInterface::class => Spiral\RoadRunner\Worker::create(),
Spiral\RoadRunner\Http\PSR7WorkerInterface::class => DI\autowire(Spiral\RoadRunner\Http\PSR7Worker::class),
]);
$container = $containerBuilder->build();

$app = DI\Bridge\Slim\Bridge::create($container);
// define routes
$app->get('/', function (Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response) {
$config = require_once(__DIR__ . '/src/conf/config.php');
$container2 = MapasCulturais\App::i('web');
$container2->init($config);

return $container2->run();
// $response->getBody()->write('Hello world from RoadRunner and Slim!');
// return $response;
});

// set routing error handling
$app->add(App\ErrorHandlingMiddleware::class);

return $app;
38 changes: 38 additions & 0 deletions app/src/ErrorHandlingMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace App;

use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Slim\Exception\HttpMethodNotAllowedException;
use Slim\Exception\HttpNotFoundException;

class ErrorHandlingMiddleware implements MiddlewareInterface
{
private $responseFactory;

public function __construct(ResponseFactoryInterface $responseFactory)
{
$this->responseFactory = $responseFactory;
}

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
try {
return $handler->handle($request);
} catch (HttpNotFoundException $e) {
$response = $this->responseFactory->createResponse(404);
$response->getBody()->write('route not found');
return $response;
} catch (HttpMethodNotAllowedException $e) {
$response = $this->responseFactory->createResponse(405);
$response->getBody()->write('method not allowed');
return $response;
}
}
}
12 changes: 9 additions & 3 deletions app/src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

declare(strict_types=1);


namespace App;

// use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;

// use MicroKernelTrait;

use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
Expand All @@ -12,15 +18,15 @@
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;

class Kernel
class Kernel extends BaseKernel
{
private string $url;
private RouteCollection $routes;

public function __construct()
{
$this->url = $this->getPathRequest();
$this->routes = require_once dirname(__DIR__).'/routes/routes.php';
$this->routes = require_once dirname(__DIR__) . '/routes/routes.php';
}

public function execute(): void
Expand All @@ -35,7 +41,7 @@ public function execute(): void
$this->dispatchAction($matcher);
} catch (MethodNotAllowedException $exception) {
(new JsonResponse([
'error' => 'Method not allowed: '.$_SERVER['REQUEST_METHOD'],
'error' => 'Method not allowed: ' . $_SERVER['REQUEST_METHOD'],
], status: Response::HTTP_METHOD_NOT_ALLOWED))->send();

exit;
Expand Down
Loading
Loading