Commit 9e116674 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Switching image to alpine

parent 87d857f9
FROM nginx FROM alpine:3.9.5
RUN apt -y update && apt -y install php-fpm \ RUN apk add --update \
nginx \
tzdata \
ca-certificates \ ca-certificates \
cron \ dcron \
zip \ zip \
php7.3-common \ redis \
php7.3-curl \ php7 \
php7.3-mbstring \ php7-fpm \
php7.3-sqlite3 \ php7-common \
php7.3-mysql \ php7-curl \
php7.3-xml \ php7-mbstring \
php7.3-zip \ php7-sqlite3 \
php7.3-redis \ php7-pdo_mysql \
php7.3-gd \ php7-pdo_sqlite \
redis-server php7-dom \
php7-simplexml \
RUN sed -i 's/listen.owner = www-data/listen.owner = nginx/g' /etc/php/7.3/fpm/pool.d/www.conf && \ php7-tokenizer \
sed -i 's/listen.group = www-data/listen.group = nginx/g' /etc/php/7.3/fpm/pool.d/www.conf && \ php7-zip \
sed -i 's/pm.max_children = 5/pm.max_children = 100/g' /etc/php/7.3/fpm/pool.d/www.conf && \ php7-redis \
sed -i 's/pm.start_servers = 2/pm.start_servers = 25/g' /etc/php/7.3/fpm/pool.d/www.conf && \ php7-gd \
sed -i 's/pm.min_spare_servers = 1/pm.min_spare_servers = 5/g' /etc/php/7.3/fpm/pool.d/www.conf && \ php7-json \
sed -i 's/pm.max_spare_servers = 3/pm.max_spare_servers = 25/g' /etc/php/7.3/fpm/pool.d/www.conf && \ php7-pcntl \
sed -i 's/user = www-data/user = nginx/g' /etc/php/7.3/fpm/pool.d/www.conf && \ && rm -rf /var/cache/apk/*
sed -i 's/group = www-data/group = nginx/g' /etc/php/7.3/fpm/pool.d/www.conf && \
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php/7.3/fpm/php.ini && \
rm /var/log/nginx/access.log && ln -s /dev/null /var/log/nginx/access.log && \
rm /var/log/nginx/error.log && ln -s /dev/stdout /var/log/nginx/error.log && \
mkdir /html
# Set correct timezone
RUN ln -fs /usr/share/zoneinfo/Europe/Berlin /etc/localtime && dpkg-reconfigure -f noninteractive tzdata
# Add Cronjob for Laravel
RUN (crontab -l ; echo "* * * * * php /html/artisan schedule:run >> /dev/null 2>&1") | crontab
WORKDIR /html WORKDIR /html
EXPOSE 80
RUN sed -i 's/user = nobody/user = nginx/g' /etc/php7/php-fpm.d/www.conf && \
sed -i 's/group = nobody/group = nginx/g' /etc/php7/php-fpm.d/www.conf && \
sed -i 's/pm.max_children = 5/pm.max_children = 100/g' /etc/php7/php-fpm.d/www.conf && \
sed -i 's/pm.start_servers = 2/pm.start_servers = 5/g' /etc/php7/php-fpm.d/www.conf && \
sed -i 's/pm.min_spare_servers = 1/pm.min_spare_servers = 5/g' /etc/php7/php-fpm.d/www.conf && \
sed -i 's/pm.max_spare_servers = 3/pm.max_spare_servers = 25/g' /etc/php7/php-fpm.d/www.conf && \
sed -i 's/user = www-data/user = nginx/g' /etc/php7/php-fpm.d/www.conf && \
sed -i 's/group = www-data/group = nginx/g' /etc/php7/php-fpm.d/www.conf && \
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php7/php.ini && \
echo "daemonize yes" >> /etc/redis.conf && \
ln -s /dev/null /var/log/nginx/access.log && \
ln -s /dev/stdout /var/log/nginx/error.log && \
cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime && \
echo "Europe/Berlin" > /etc/timezone && \
(crontab -l ; echo "* * * * * php /html/artisan schedule:run >> /dev/null 2>&1") | crontab -
COPY config/nginx.conf /etc/nginx/nginx.conf COPY config/nginx.conf /etc/nginx/nginx.conf
COPY config/nginx-default.conf /etc/nginx/conf.d/default.conf COPY config/nginx-default.conf /etc/nginx/conf.d/default.conf
COPY --chown=root:nginx . /html COPY --chown=root:nginx . /html
WORKDIR /html
EXPOSE 80
CMD chown -R root:nginx storage/logs/metager bootstrap/cache && \ CMD chown -R root:nginx storage/logs/metager bootstrap/cache && \
chmod -R g+w storage/logs/metager bootstrap/cache && \ chmod -R g+w storage/logs/metager bootstrap/cache && \
/etc/init.d/cron start && \ crond -L /dev/stdout && \
/etc/init.d/php7.3-fpm start && \ nginx && \
/etc/init.d/nginx start && \ php-fpm7 -D && \
/etc/init.d/redis-server start && \ redis-server /etc/redis.conf && \
su -s /bin/bash -c 'php artisan requests:fetcher' nginx su -s /bin/sh -c 'php artisan requests:fetcher' nginx
FROM alpine:3.9.5
RUN apk add --update \
nginx \
tzdata \
ca-certificates \
dcron \
zip \
redis \
php7 \
php7-fpm \
php7-common \
php7-curl \
php7-mbstring \
php7-sqlite3 \
php7-pdo_mysql \
php7-pdo_sqlite \
php7-dom \
php7-simplexml \
php7-tokenizer \
php7-zip \
php7-redis \
php7-gd \
php7-json \
php7-pcntl \
&& rm -rf /var/cache/apk/*
WORKDIR /html
RUN sed -i 's/user = nobody/user = nginx/g' /etc/php7/php-fpm.d/www.conf && \
sed -i 's/group = nobody/group = nginx/g' /etc/php7/php-fpm.d/www.conf && \
sed -i 's/pm.max_children = 5/pm.max_children = 100/g' /etc/php7/php-fpm.d/www.conf && \
sed -i 's/pm.start_servers = 2/pm.start_servers = 5/g' /etc/php7/php-fpm.d/www.conf && \
sed -i 's/pm.min_spare_servers = 1/pm.min_spare_servers = 5/g' /etc/php7/php-fpm.d/www.conf && \
sed -i 's/pm.max_spare_servers = 3/pm.max_spare_servers = 25/g' /etc/php7/php-fpm.d/www.conf && \
sed -i 's/user = www-data/user = nginx/g' /etc/php7/php-fpm.d/www.conf && \
sed -i 's/group = www-data/group = nginx/g' /etc/php7/php-fpm.d/www.conf && \
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php7/php.ini && \
echo "daemonize yes" >> /etc/redis.conf && \
ln -s /dev/null /var/log/nginx/access.log && \
ln -s /dev/stdout /var/log/nginx/error.log && \
cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime && \
echo "Europe/Berlin" > /etc/timezone && \
(crontab -l ; echo "* * * * * php /html/artisan schedule:run >> /dev/null 2>&1") | crontab -
WORKDIR /html
EXPOSE 80
CMD chown -R root:nginx storage/logs/metager bootstrap/cache && \
chmod -R g+w storage/logs/metager bootstrap/cache && \
crond -L /dev/stdout && \
nginx && \
php-fpm7 -D && \
redis-server /etc/redis.conf && \
su -s /bin/sh -c 'php artisan requests:fetcher' nginx
...@@ -50,9 +50,6 @@ class RequestFetcher extends Command ...@@ -50,9 +50,6 @@ class RequestFetcher extends Command
*/ */
public function handle() public function handle()
{ {
$pids = [];
pcntl_async_signals(true);
pcntl_signal(SIGINT, [$this, "sig_handler"]); pcntl_signal(SIGINT, [$this, "sig_handler"]);
pcntl_signal(SIGTERM, [$this, "sig_handler"]); pcntl_signal(SIGTERM, [$this, "sig_handler"]);
pcntl_signal(SIGHUP, [$this, "sig_handler"]); pcntl_signal(SIGHUP, [$this, "sig_handler"]);
...@@ -114,9 +111,6 @@ class RequestFetcher extends Command ...@@ -114,9 +111,6 @@ class RequestFetcher extends Command
} finally { } finally {
curl_multi_close($this->multicurl); curl_multi_close($this->multicurl);
} }
foreach ($pids as $tmppid) {
\pcntl_waitpid($tmppid, $status, WNOHANG);
}
} }
private function getCurlHandle($job) private function getCurlHandle($job)
......
...@@ -77,7 +77,7 @@ class AdminInterface extends Controller ...@@ -77,7 +77,7 @@ class AdminInterface extends Controller
private function getSearchEngineNames() private function getSearchEngineNames()
{ {
$url = config_path() . "/sumas.xml"; $url = config_path() . "/sumas.xml";
$xml = simplexml_load_file($url); $xml = \simplexml_load_file($url);
$sumas = $xml->xpath("suma"); $sumas = $xml->xpath("suma");
$names = array(); $names = array();
......
...@@ -42,7 +42,7 @@ class Assoziator extends Controller ...@@ -42,7 +42,7 @@ class Assoziator extends Controller
} }
$response = preg_replace("/^<\?.*\?>/s", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", $response); $response = preg_replace("/^<\?.*\?>/s", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", $response);
$content = simplexml_load_string($response); $content = \simplexml_load_string($response);
$words = []; $words = [];
......
...@@ -15,7 +15,7 @@ class FokiLoader ...@@ -15,7 +15,7 @@ class FokiLoader
$sumaFile = config_path() . "/sumas.xml"; $sumaFile = config_path() . "/sumas.xml";
} }
$xml = simplexml_load_file($sumaFile); $xml = \simplexml_load_file($sumaFile);
$sumas = $xml->xpath("suma"); $sumas = $xml->xpath("suma");
$foki = []; $foki = [];
......
...@@ -253,7 +253,7 @@ class MetaGerSearch extends Controller ...@@ -253,7 +253,7 @@ class MetaGerSearch extends Controller
$tips_text = file_get_contents($tipserver); $tips_text = file_get_contents($tipserver);
$tips = []; $tips = [];
try { try {
$tips_xml = simplexml_load_string($tips_text); $tips_xml = \simplexml_load_string($tips_text);
$tips_xml->registerXPathNamespace('mg', 'http://metager.de/tips/'); $tips_xml->registerXPathNamespace('mg', 'http://metager.de/tips/');
$tips_xml = $tips_xml->xpath('mg:tip'); $tips_xml = $tips_xml->xpath('mg:tip');
......
...@@ -86,7 +86,7 @@ class Quicktips ...@@ -86,7 +86,7 @@ class Quicktips
{ {
$quicktips_raw = preg_replace("/\r\n/si", "", $quicktips_raw); $quicktips_raw = preg_replace("/\r\n/si", "", $quicktips_raw);
try { try {
$content = simplexml_load_string($quicktips_raw); $content = \simplexml_load_string($quicktips_raw);
if (!$content) { if (!$content) {
return; return;
} }
......
...@@ -9,7 +9,7 @@ abstract class XmlSearchengine extends Searchengine ...@@ -9,7 +9,7 @@ abstract class XmlSearchengine extends Searchengine
public function loadresults($results) public function loadresults($results)
{ {
try { try {
$resultsXml = simplexml_load_string($results); $resultsXml = \simplexml_load_string($results);
$this->loadXmlResults($resultsXml); $this->loadXmlResults($resultsXml);
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error($e->getMessage()); Log::error($e->getMessage());
......
...@@ -18,7 +18,7 @@ class BASE extends Searchengine ...@@ -18,7 +18,7 @@ class BASE extends Searchengine
{ {
$result = preg_replace("/\r\n/si", "", $result); $result = preg_replace("/\r\n/si", "", $result);
try { try {
$content = simplexml_load_string($result); $content = \simplexml_load_string($result);
if (!$content) { if (!$content) {
return; return;
} }
...@@ -33,7 +33,7 @@ class BASE extends Searchengine ...@@ -33,7 +33,7 @@ class BASE extends Searchengine
$title = $attribute; $title = $attribute;
break; break;
case 'dclink': case 'dclink':
$link = $attribute; $link = $attribute;
$anzeigeLink = $link; $anzeigeLink = $link;
break; break;
case 'dcdescription': case 'dcdescription':
...@@ -49,7 +49,7 @@ class BASE extends Searchengine ...@@ -49,7 +49,7 @@ class BASE extends Searchengine
$link, $link,
$anzeigeLink, $anzeigeLink,
$descr, $descr,
$this->engine->{"display-name"},$this->engine->homepage, $this->engine->{"display-name"}, $this->engine->homepage,
$this->counter $this->counter
); );
} }
......
...@@ -18,17 +18,17 @@ class Blogsearch extends Searchengine ...@@ -18,17 +18,17 @@ class Blogsearch extends Searchengine
{ {
$result = preg_replace("/\r\n/si", "", $result); $result = preg_replace("/\r\n/si", "", $result);
try { try {
$content = simplexml_load_string($result); $content = \simplexml_load_string($result);
if (!$content) { if (!$content) {
return; return;
} }
$results = $content->xpath('//xml/docs/doc'); $results = $content->xpath('//xml/docs/doc');
foreach ($results as $result) { foreach ($results as $result) {
$title = $result->{"title"}->__toString(); $title = $result->{"title"}->__toString();
$link = $result->{"url"}->__toString(); $link = $result->{"url"}->__toString();
$anzeigeLink = $link; $anzeigeLink = $link;
$descr = $result->{"content"}->__toString(); $descr = $result->{"content"}->__toString();
$this->counter++; $this->counter++;
$this->results[] = new \App\Models\Result( $this->results[] = new \App\Models\Result(
$this->engine, $this->engine,
...@@ -36,7 +36,7 @@ class Blogsearch extends Searchengine ...@@ -36,7 +36,7 @@ class Blogsearch extends Searchengine
$link, $link,
$anzeigeLink, $anzeigeLink,
$descr, $descr,
$this->engine->{"display-name"},$this->engine->homepage, $this->engine->{"display-name"}, $this->engine->homepage,
$this->counter $this->counter
); );
} }
......
...@@ -18,7 +18,7 @@ class Ebay extends Searchengine ...@@ -18,7 +18,7 @@ class Ebay extends Searchengine
{ {
$result = preg_replace("/\r\n/si", "", $result); $result = preg_replace("/\r\n/si", "", $result);
try { try {
$content = simplexml_load_string($result); $content = \simplexml_load_string($result);
if (!$content) { if (!$content) {
return; return;
} }
......
...@@ -18,16 +18,16 @@ class Ecoshopper extends Searchengine ...@@ -18,16 +18,16 @@ class Ecoshopper extends Searchengine
{ {
$result = preg_replace("/\r\n/si", "", $result); $result = preg_replace("/\r\n/si", "", $result);
try { try {
$content = simplexml_load_string($result); $content = \simplexml_load_string($result);
if (!$content) { if (!$content) {
return; return;
} }
$results = $content->xpath('//response/result[@name="response"]/doc'); $results = $content->xpath('//response/result[@name="response"]/doc');
foreach ($results as $result) { foreach ($results as $result) {
$result = simplexml_load_string($result->saveXML()); $result = \simplexml_load_string($result->saveXML());
$title = $result->xpath('//doc/str[@name="artikelName"]')[0]->__toString(); $title = $result->xpath('//doc/str[@name="artikelName"]')[0]->__toString();
$link = $result->xpath('//doc/str[@name="artikelDeeplink"]')[0]->__toString(); $link = $result->xpath('//doc/str[@name="artikelDeeplink"]')[0]->__toString();
$anzeigeLink = parse_url($link); $anzeigeLink = parse_url($link);
if (isset($anzeigeLink['query'])) { if (isset($anzeigeLink['query'])) {
parse_str($anzeigeLink['query'], $query); parse_str($anzeigeLink['query'], $query);
...@@ -49,10 +49,10 @@ class Ecoshopper extends Searchengine ...@@ -49,10 +49,10 @@ class Ecoshopper extends Searchengine
$link, $link,
$anzeigeLink, $anzeigeLink,
$descr, $descr,
$this->engine->{"display-name"},$this->engine->homepage, $this->engine->{"display-name"}, $this->engine->homepage,
$this->counter, $this->counter,
['partnershop' => false, ['partnershop' => false,
'image' => $image] 'image' => $image]
); );
} }
} catch (\Exception $e) { } catch (\Exception $e) {
......
...@@ -18,7 +18,7 @@ class Exalead extends Searchengine ...@@ -18,7 +18,7 @@ class Exalead extends Searchengine
{ {
$result = preg_replace("/\r\n/si", "", $result); $result = preg_replace("/\r\n/si", "", $result);
try { try {
$content = simplexml_load_string($result); $content = \simplexml_load_string($result);
if (!$content) { if (!$content) {
return; return;
} }
......
...@@ -18,7 +18,7 @@ class Flickr extends Searchengine ...@@ -18,7 +18,7 @@ class Flickr extends Searchengine
{ {
$result = preg_replace("/\r\n/si", "", $result); $result = preg_replace("/\r\n/si", "", $result);
try { try {
$content = simplexml_load_string($result); $content = \simplexml_load_string($result);
if (!$content) { if (!$content) {
return; return;
} }
...@@ -53,7 +53,7 @@ class Flickr extends Searchengine ...@@ -53,7 +53,7 @@ class Flickr extends Searchengine
{ {
$result = preg_replace("/\r\n/si", "", $result); $result = preg_replace("/\r\n/si", "", $result);
try { try {
$content = simplexml_load_string($result); $content = \simplexml_load_string($result);
if (!$content) { if (!$content) {
return; return;
} }
......
...@@ -18,14 +18,13 @@ class Kelkoo extends Searchengine ...@@ -18,14 +18,13 @@ class Kelkoo extends Searchengine
$this->hash = md5($this->engine->host . $this->getString . $this->engine->port . $this->name); $this->hash = md5($this->engine->host . $this->getString . $this->engine->port . $this->name);
} }
public function loadResults($result) public function loadResults($result)
{ {
$result = preg_replace("/\r\n/si", "", $result); $result = preg_replace("/\r\n/si", "", $result);
# delete namespace, allowing easier xpath access # delete namespace, allowing easier xpath access
$result = str_replace('xmlns="urn:yahoo:prods"', '', $result); $result = str_replace('xmlns="urn:yahoo:prods"', '', $result);
try { try {
$content = simplexml_load_string($result); $content = \simplexml_load_string($result);
if (!$content) { if (!$content) {
return; return;
} }
...@@ -40,23 +39,22 @@ class Kelkoo extends Searchengine ...@@ -40,23 +39,22 @@ class Kelkoo extends Searchengine
$results = $content->xpath('/ProductSearch/Products/Product/Offer'); $results = $content->xpath('/ProductSearch/Products/Product/Offer');
foreach ($results as $result) { foreach ($results as $result) {
$result = simplexml_load_string($result->saveXML()); $result = \simplexml_load_string($result->saveXML());
$title = $result->Title[0]->__toString();
$title = $result->Title[0]->__toString();
$price = floatval($result->Price[0]->Price[0]); $price = floatval($result->Price[0]->Price[0]);
$deliveryPrice = floatval($result->Price[0]->DeliveryCost[0]); $deliveryPrice = floatval($result->Price[0]->DeliveryCost[0]);
$totalPrice = $price + $deliveryPrice; $totalPrice = $price + $deliveryPrice;
$descr = ""; $descr = "";
if(isset($result->Description[0])) if (isset($result->Description[0])) {
{
$descr = $result->Description[0]->__toString(); $descr = $result->Description[0]->__toString();
} }
$descr .= "<p>Preis: " . $price . " €</p>"; $descr .= "<p>Preis: " . $price . " €</p>";
$image = $result->Images[0]->Image[0]->Url[0]->__toString(); $image = $result->Images[0]->Image[0]->Url[0]->__toString();
$link = $result->Url[0]->__toString(); $link = $result->Url[0]->__toString();
$anzeigeLink = $result->Merchant[0]->Name[0]->__toString(); $anzeigeLink = $result->Merchant[0]->Name[0]->__toString();
$this->counter++; $this->counter++;
$this->results[] = new \App\Models\Result( $this->results[] = new \App\Models\Result(
...@@ -65,10 +63,10 @@ class Kelkoo extends Searchengine ...@@ -65,10 +63,10 @@ class Kelkoo extends Searchengine
$link, $link,
$anzeigeLink, $anzeigeLink,
$descr, $descr,
$this->engine->{"display-name"},$this->engine->homepage, $this->engine->{"display-name"}, $this->engine->homepage,
$this->counter, $this->counter,
['image' => $image, ['image' => $image,
'price' => $totalPrice * 100] 'price' => $totalPrice * 100]
); );
} }
} catch (\Exception $e) { } catch (\Exception $e) {
...@@ -84,7 +82,7 @@ class Kelkoo extends Searchengine ...@@ -84,7 +82,7 @@ class Kelkoo extends Searchengine
# delete namespace, allowing easier xpath access # delete namespace, allowing easier xpath access
$result = str_replace('xmlns="urn:yahoo:prods"', '', $result); $result = str_replace('xmlns="urn:yahoo:prods"', '', $result);
try { try {
$content = simplexml_load_string($result); $content = \simplexml_load_string($result);
if (!$content) { if (!$content) {
return; return;
} }
...@@ -120,22 +118,22 @@ class Kelkoo extends Searchengine ...@@ -120,22 +118,22 @@ class Kelkoo extends Searchengine
$next = new Kelkoo($this->name, $this->engine, $metager); $next = new Kelkoo($this->name, $this->engine, $metager);
$next->unsignedGetString .= "&start=" . ($current + 20); $next->unsignedGetString .= "&start=" . ($current + 20);
$next->getString = $next->UrlSigner($next->unsignedGetString); $next->getString = $next->UrlSigner($next->unsignedGetString);
$next->hash = md5($next->engine->host . $next->getString . $next->engine->port . $next->name); $next->hash = md5($next->engine->host . $next->getString . $next->engine->port . $next->name);
$this->next = $next; $this->next = $next;
} }
# kelkoogroup.com/kelkoo-customer-service/kelkoo-developer-network/shopping-services/samples/signing-url-php/ # kelkoogroup.com/kelkoo-customer-service/kelkoo-developer-network/shopping-services/samples/signing-url-php/
public function UrlSigner($path){ public function UrlSigner($path)
{
$urlPath = $path; $urlPath = $path;
$partner = $this->engine->{"http-auth-credentials"}->ID; $partner = $this->engine->{"http-auth-credentials"}->ID;
$key = $this->engine->{"http-auth-credentials"}->Key; $key = $this->engine->{"http-auth-credentials"}->Key;
$URL_sig = "hash"; $URL_sig = "hash";
$URL_ts = "timestamp"; $URL_ts = "timestamp";
$URL_partner = "aid"; $URL_partner = "aid";
$URLreturn = ""; $URLreturn = "";
$URLtmp = "";