Skip to content

Commit

Permalink
add db layer
Browse files Browse the repository at this point in the history
  • Loading branch information
esposimo committed Dec 24, 2024
1 parent 166882f commit 7eb3e59
Show file tree
Hide file tree
Showing 7 changed files with 605 additions and 283 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ obj/
/src/vendor/
/src/vendor/**/.git
/src/tests/.phpunit.result.cache
/vendor/
/vendor/**/.git
/tests/.phpunit.result.cache
old/
trash/
composer.lock
.*env

67 changes: 14 additions & 53 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,54 +1,15 @@
FROM php:8.2-fpm


RUN apt -y update -y && apt -y upgrade && apt -y install git libpq-dev libzip-dev zip libmemcached-dev && docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql && docker-php-ext-install pdo pdo_pgsql pgsql && docker-php-ext-install zip
RUN cd /tmp && curl -k https://getcomposer.org/installer -o composer-setup.php && php composer-setup.php && mv composer.phar /usr/local/bin/composer && rm -f composer-setup.php

RUN pecl install memcached && docker-php-ext-enable memcached && mv /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini

USER root:root
FROM composer:latest as composer
RUN mkdir -p /tmp/repo
COPY . /tmp/repo/
WORKDIR /tmp/repo
RUN composer install --no-dev

# git clone del progetto che deve andare a finire in /var/www/html/crawler
# run del comando composer install dalla directory /var/www/html/crawler

# from https://getcomposer.org/doc/faqs/should-i-commit-the-dependencies-in-my-vendor-directory.md
# remove all .git directory from installed dependencies
# find vendor/ -type d -name ".git" -exec rm -rf {} \;
#
# Add a .gitignore rule (/vendor/**/.git)


# valutare questo dockerfile
## Uso una build per effettuare il clone del repository. Il comando git non mi servirà più quindi è inutile installarlo nella build finale
## FROM alpine:latest as git_repo
## RUN apk upgrade && apk update && apk add git
## WORKDIR /tmp
## RUN git clone https://github.com/pagopa/pagopa-qi-log-crawler
##
##
##
##
## Uso la build di composer nella quale copio il repository precedentemente clonato, e lancio il composer install
## Anche in questo caso composer serve solo per effettuare il download delle dipendenze, quindi è inutile installarlo nella build finale
## FROM composer:latest as composer
## RUN mkdir -p /tmp/repo
## COPY --from=git_repo /tmp/pagopa-qi-log-crawler/src /tmp/repo/
## WORKDIR /tmp/repo
## RUN composer install
##
## Uso php-fpm ed installo alcuni modulo (forse libzip si può eliminare , serviva a composer)
## FROM php:8.2-fpm
## RUN apt -y update && \
## apt -y upgrade && \
## apt -y install libpq-dev libzip-dev zip libmemcached-dev cron && \
## docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql && \
## docker-php-ext-install pdo pdo_pgsql pgsql zip && \
## pecl install memcached && \
## docker-php-ext-enable memcached && \
## /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini && \
## mkdir -p /var/www/html/sherlock
## COPY --from=composer /tmp/repo/ /var/www/html/sherlock
##
##
## valutare https://packagist.org/packages/predis/predis per la connessione a Redis.
## se si usa redis eliminare dalla build le dipendenze di memcache
FROM php:8.2-fpm
COPY --from=composer /tmp/repo /var/www/html
RUN apt -y update && \
apt -y upgrade && \
apt -y install curl libpq-dev libzip-dev zip && \
docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql && \
docker-php-ext-install pdo pdo_pgsql pgsql && \
docker-php-ext-install zip && \
mv /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini
54 changes: 54 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

require './vendor/autoload.php';

/* load environment config */
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();

use Illuminate\Database\Capsule\Manager as Capsule;

$data = [
'config_instance' =>
[
'driver' => $_ENV['DB_CONFIG_INSTANCE_DRIVER'],
'host' => $_ENV['DB_CONFIG_INSTANCE_HOST'],
'port' => $_ENV['DB_CONFIG_INSTANCE_PORT'],
'database' => $_ENV['DB_CONFIG_INSTANCE_DATABASE'],
'username' => $_ENV['DB_CONFIG_INSTANCE_USERNAME'],
'password' => $_ENV['DB_CONFIG_INSTANCE_PASSWORD'],
'charset' => $_ENV['DB_CONFIG_INSTANCE_CHARSET'],
'collation' => $_ENV['DB_CONFIG_INSTANCE_COLLATION'],
],
'data_instance' =>
[
'driver' => $_ENV['DB_DATA_INSTANCE_DRIVER'],
'host' => $_ENV['DB_DATA_INSTANCE_HOST'],
'port' => $_ENV['DB_DATA_INSTANCE_PORT'],
'database' => $_ENV['DB_DATA_INSTANCE_DATABASE'],
'username' => $_ENV['DB_DATA_INSTANCE_USERNAME'],
'password' => $_ENV['DB_DATA_INSTANCE_PASSWORD'],
'charset' => $_ENV['DB_DATA_INSTANCE_CHARSET'],
'collation' => $_ENV['DB_DATA_INSTANCE_COLLATION'],
],
'history_instance' =>
[
'driver' => $_ENV['DB_HISTORY_INSTANCE_DRIVER'],
'host' => $_ENV['DB_HISTORY_INSTANCE_HOST'],
'port' => $_ENV['DB_HISTORY_INSTANCE_PORT'],
'database' => $_ENV['DB_HISTORY_INSTANCE_DATABASE'],
'username' => $_ENV['DB_HISTORY_INSTANCE_USERNAME'],
'password' => $_ENV['DB_HISTORY_INSTANCE_PASSWORD'],
'charset' => $_ENV['DB_HISTORY_INSTANCE_CHARSET'],
'collation' => $_ENV['DB_HISTORY_INSTANCE_COLLATION'],
]
];

$capsule = new Capsule;
foreach($data as $name => $config)
{
$capsule->addConnection($config, $name);
}

$capsule->setAsGlobal();
$capsule->bootEloquent();
26 changes: 16 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
{
"name": "$vendor_name$/$package_name$",
"description": "$description$",
"minimum-stability": "$stability$",
"license": "$license$",
"authors": [
{
"name": "$author$",
"email": "$email$"
"name" : "pagopa/crawler",
"author": "Simone Esposito",
"autoload": {
"psr-4": {
"pagopa\\sert\\": "src/"
}
],
},
"require": {
$END$
"illuminate/database": "10.39.0",
"predis/predis": "v2.2.2",
"vlucas/phpdotenv": "v5.6.1",
"ext-xmlreader": "*",
"ext-simplexml": "*",
"ext-libxml": "*",
"ext-pdo": "*"
},
"require-dev": {
"phpunit/phpunit": "11.0.1"
}
}
Loading

0 comments on commit 7eb3e59

Please sign in to comment.