From 21eacb8a63f0da9fdd7d3308a2020d03960be3b3 Mon Sep 17 00:00:00 2001 From: hack3r-0m Date: Fri, 23 Oct 2020 17:36:52 +0000 Subject: [PATCH 1/5] Replace .mmdb reader with maxmind and native C extension --- Dockerfile | 33 +++++ app/controllers/api/locale.php | 14 +- app/init.php | 2 +- composer.json | 4 +- composer.lock | 233 +++++---------------------------- 5 files changed, 75 insertions(+), 211 deletions(-) diff --git a/Dockerfile b/Dockerfile index 75c03c3e0..184784856 100755 --- a/Dockerfile +++ b/Dockerfile @@ -34,6 +34,16 @@ RUN \ RUN docker-php-ext-install sockets +RUN wget https://github.com/maxmind/libmaxminddb/releases/download/1.4.3/libmaxminddb-1.4.3.tar.gz +RUN tar -xvf libmaxminddb-1.4.3.tar.gz && \ + cd ./libmaxminddb-1.4.3 && \ + ./configure && \ + make && \ + make check && \ + make install && \ + ldconfig ./libmaxminddb-1.4.3 + + RUN \ # Redis Extension wget -q https://github.com/phpredis/phpredis/archive/$PHP_REDIS_VERSION.tar.gz && \ @@ -128,6 +138,29 @@ COPY ./docs /usr/src/code/docs COPY ./public /usr/src/code/public COPY ./src /usr/src/code/src +RUN \ + apk add --no-cache --virtual .deps \ + make \ + automake \ + autoconf \ + gcc \ + g++ \ + tar \ + wget \ + git \ + zlib-dev \ + brotli-dev + +RUN apk add libmaxminddb-dev && \ + cd vendor/maxmind-db/reader/ext && ls -a && \ + phpize && \ + ./configure && \ + make && \ + make test && \ + make install + +RUN echo extension=maxminddb.so >> /usr/local/etc/php/php.ini + # Set Volumes RUN mkdir -p /storage/uploads && \ mkdir -p /storage/cache && \ diff --git a/app/controllers/api/locale.php b/app/controllers/api/locale.php index 8be46d8e4..04524abe5 100644 --- a/app/controllers/api/locale.php +++ b/app/controllers/api/locale.php @@ -30,16 +30,16 @@ App::get('/v1/locale') $currency = null; try { - $record = $geodb->country($ip); - $output['countryCode'] = $record->country->isoCode; - $output['country'] = (isset($countries[$record->country->isoCode])) ? $countries[$record->country->isoCode] : $locale->getText('locale.country.unknown'); + $record = $geodb->get($ip); + $output['countryCode'] = $record['country']['iso_code']; + $output['country'] = (isset($countries[$record['country']['iso_code']])) ? $countries[$record['country']['iso_code']] : $locale->getText('locale.country.unknown'); //$output['countryTimeZone'] = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, $record->country->isoCode); - $output['continent'] = (isset($continents[$record->continent->code])) ? $continents[$record->continent->code] : $locale->getText('locale.country.unknown'); - $output['continentCode'] = $record->continent->code; - $output['eu'] = (\in_array($record->country->isoCode, $eu)) ? true : false; + $output['continent'] = (isset($continents[$record['continent']['code']])) ? $continents[$record['continent']['code']] : $locale->getText('locale.country.unknown'); + $output['continentCode'] = $record['continent']['code']; + $output['eu'] = (\in_array($record['country']['iso_code'], $eu)) ? true : false; foreach ($currencies as $code => $element) { - if (isset($element['locations']) && isset($element['code']) && \in_array($record->country->isoCode, $element['locations'])) { + if (isset($element['locations']) && isset($element['code']) && \in_array($record['country']['iso_code'], $element['locations'])) { $currency = $element['code']; } } diff --git a/app/init.php b/app/init.php index 9637c4381..1afa2a837 100644 --- a/app/init.php +++ b/app/init.php @@ -25,7 +25,7 @@ use Utopia\View; use Utopia\Config\Config; use Utopia\Locale\Locale; use Utopia\Registry\Registry; -use GeoIp2\Database\Reader; +use MaxMind\Db\Reader; use PHPMailer\PHPMailer\PHPMailer; use PDO as PDONative; diff --git a/composer.json b/composer.json index 7f3faed7e..8b49062d4 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,7 @@ "utopia-php/domains": "1.1.*", "resque/php-resque": "1.3.6", - "geoip2/geoip2": "2.10.0", + "maxmind-db/reader": "1.8.*", "piwik/device-detector": "3.13.0", "dragonmantank/cron-expression": "3.0.1", "domnikl/statsd": "3.0.*", @@ -73,4 +73,4 @@ "php": "7.4" } } -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock index 2d881b4b1..a7c4e3981 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "19f7cef86ddc98623cd3ffffa2be2cae", + "content-hash": "555bdf22c5a6417b7336ce7e616eba50", "packages": [ { "name": "appwrite/php-clamav", @@ -140,76 +140,6 @@ "homepage": "https://github.com/colinmollenhour/credis", "time": "2020-10-13T23:55:13+00:00" }, - { - "name": "composer/ca-bundle", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/composer/ca-bundle.git", - "reference": "8a7ecad675253e4654ea05505233285377405215" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/composer/ca-bundle/zipball/8a7ecad675253e4654ea05505233285377405215", - "reference": "8a7ecad675253e4654ea05505233285377405215", - "shasum": "" - }, - "require": { - "ext-openssl": "*", - "ext-pcre": "*", - "php": "^5.3.2 || ^7.0 || ^8.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7 || 6.5 - 8", - "psr/log": "^1.0", - "symfony/process": "^2.5 || ^3.0 || ^4.0 || ^5.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Composer\\CaBundle\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jordi Boggiano", - "email": "j.boggiano@seld.be", - "homepage": "http://seld.be" - } - ], - "description": "Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.", - "keywords": [ - "cabundle", - "cacert", - "certificate", - "ssl", - "tls" - ], - "funding": [ - { - "url": "https://packagist.com", - "type": "custom" - }, - { - "url": "https://github.com/composer", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/composer/composer", - "type": "tidelift" - } - ], - "time": "2020-08-23T12:54:47+00:00" - }, { "name": "dasprid/enum", "version": "1.0.3", @@ -357,59 +287,6 @@ ], "time": "2020-08-21T02:30:13+00:00" }, - { - "name": "geoip2/geoip2", - "version": "v2.10.0", - "source": { - "type": "git", - "url": "https://github.com/maxmind/GeoIP2-php.git", - "reference": "419557cd21d9fe039721a83490701a58c8ce784a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/maxmind/GeoIP2-php/zipball/419557cd21d9fe039721a83490701a58c8ce784a", - "reference": "419557cd21d9fe039721a83490701a58c8ce784a", - "shasum": "" - }, - "require": { - "ext-json": "*", - "maxmind-db/reader": "~1.5", - "maxmind/web-service-common": "~0.6", - "php": ">=5.6" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "2.*", - "phpunit/phpunit": "5.*", - "squizlabs/php_codesniffer": "3.*" - }, - "type": "library", - "autoload": { - "psr-4": { - "GeoIp2\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache-2.0" - ], - "authors": [ - { - "name": "Gregory J. Oschwald", - "email": "goschwald@maxmind.com", - "homepage": "https://www.maxmind.com/" - } - ], - "description": "MaxMind GeoIP2 PHP API", - "homepage": "https://github.com/maxmind/GeoIP2-php", - "keywords": [ - "IP", - "geoip", - "geoip2", - "geolocation", - "maxmind" - ], - "time": "2019-12-12T18:48:39+00:00" - }, { "name": "guzzlehttp/guzzle", "version": "7.2.0", @@ -514,12 +391,12 @@ "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "60d379c243457e073cff02bc323a2a86cb355631" + "reference": "ddfeedfff2a52661429437da0702979f708e6ac6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/60d379c243457e073cff02bc323a2a86cb355631", - "reference": "60d379c243457e073cff02bc323a2a86cb355631", + "url": "https://api.github.com/repos/guzzle/promises/zipball/ddfeedfff2a52661429437da0702979f708e6ac6", + "reference": "ddfeedfff2a52661429437da0702979f708e6ac6", "shasum": "" }, "require": { @@ -557,7 +434,7 @@ "keywords": [ "promise" ], - "time": "2020-09-30T07:37:28+00:00" + "time": "2020-10-19T16:50:15+00:00" }, { "name": "guzzlehttp/psr7", @@ -565,12 +442,12 @@ "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "53330f47520498c0ae1f61f7e2c90f55690c06a3" + "reference": "25f7f893f0b52b7b14e244a16679d72b1f0088de" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/53330f47520498c0ae1f61f7e2c90f55690c06a3", - "reference": "53330f47520498c0ae1f61f7e2c90f55690c06a3", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/25f7f893f0b52b7b14e244a16679d72b1f0088de", + "reference": "25f7f893f0b52b7b14e244a16679d72b1f0088de", "shasum": "" }, "require": { @@ -628,7 +505,7 @@ "uri", "url" ], - "time": "2020-09-30T07:37:11+00:00" + "time": "2020-10-22T07:42:05+00:00" }, { "name": "influxdb/influxdb-php", @@ -751,52 +628,6 @@ ], "time": "2020-10-01T17:30:21+00:00" }, - { - "name": "maxmind/web-service-common", - "version": "v0.8.0", - "source": { - "type": "git", - "url": "https://github.com/maxmind/web-service-common-php.git", - "reference": "ba67d9532cfaf499bd71774b8170d05df4f75fb7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/maxmind/web-service-common-php/zipball/ba67d9532cfaf499bd71774b8170d05df4f75fb7", - "reference": "ba67d9532cfaf499bd71774b8170d05df4f75fb7", - "shasum": "" - }, - "require": { - "composer/ca-bundle": "^1.0.3", - "ext-curl": "*", - "ext-json": "*", - "php": ">=7.2" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "2.*", - "phpunit/phpunit": "^8.0 || ^9.0", - "squizlabs/php_codesniffer": "3.*" - }, - "type": "library", - "autoload": { - "psr-4": { - "MaxMind\\Exception\\": "src/Exception", - "MaxMind\\WebService\\": "src/WebService" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache-2.0" - ], - "authors": [ - { - "name": "Gregory Oschwald", - "email": "goschwald@maxmind.com" - } - ], - "description": "Internal MaxMind Web Service API", - "homepage": "https://github.com/maxmind/web-service-common-php", - "time": "2020-10-01T15:28:36+00:00" - }, { "name": "mustangostang/spyc", "version": "dev-master", @@ -1713,7 +1544,7 @@ "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator", - "reference": "a57b3cd56c4bfe1538276cfc77456cf95d8835cb" + "reference": "ad1ee55f61967546c0889d377b628e244182311e" }, "require": { "ext-curl": "*", @@ -1743,7 +1574,7 @@ } ], "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", - "time": "2020-10-14T12:07:25+00:00" + "time": "2020-10-20T10:23:43+00:00" }, { "name": "doctrine/instantiator", @@ -2646,12 +2477,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "338bf27b4510498c4b0ab70c7cbc292a591dc0df" + "reference": "b2a9914fd2057a72ec65bc9b3cd963c831a1b14b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/338bf27b4510498c4b0ab70c7cbc292a591dc0df", - "reference": "338bf27b4510498c4b0ab70c7cbc292a591dc0df", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b2a9914fd2057a72ec65bc9b3cd963c831a1b14b", + "reference": "b2a9914fd2057a72ec65bc9b3cd963c831a1b14b", "shasum": "" }, "require": { @@ -2737,7 +2568,7 @@ "type": "github" } ], - "time": "2020-10-19T09:25:00+00:00" + "time": "2020-10-22T06:06:02+00:00" }, { "name": "sebastian/cli-parser", @@ -3675,16 +3506,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "dev-master", + "version": "dev-main", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "1c302646f6efc070cd46856e600e5e0684d6b454" + "reference": "325e20642232b66e3f140a76f795b58b50a08787" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/1c302646f6efc070cd46856e600e5e0684d6b454", - "reference": "1c302646f6efc070cd46856e600e5e0684d6b454", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/325e20642232b66e3f140a76f795b58b50a08787", + "reference": "325e20642232b66e3f140a76f795b58b50a08787", "shasum": "" }, "require": { @@ -3696,7 +3527,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.18-dev" + "dev-main": "1.19-dev" }, "thanks": { "name": "symfony/polyfill", @@ -3747,20 +3578,20 @@ "type": "tidelift" } ], - "time": "2020-07-14T12:35:20+00:00" + "time": "2020-10-21T09:57:48+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "dev-master", + "version": "dev-main", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "48928d471ede0548b399f54b0286fe0d0ed79267" + "reference": "15e533d0893e58cc6c7a1971046a3dfc219435f2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/48928d471ede0548b399f54b0286fe0d0ed79267", - "reference": "48928d471ede0548b399f54b0286fe0d0ed79267", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/15e533d0893e58cc6c7a1971046a3dfc219435f2", + "reference": "15e533d0893e58cc6c7a1971046a3dfc219435f2", "shasum": "" }, "require": { @@ -3772,7 +3603,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.18-dev" + "dev-main": "1.19-dev" }, "thanks": { "name": "symfony/polyfill", @@ -3824,7 +3655,7 @@ "type": "tidelift" } ], - "time": "2020-09-14T11:01:58+00:00" + "time": "2020-10-21T09:57:48+00:00" }, { "name": "theseer/tokenizer", @@ -3878,16 +3709,16 @@ "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "fa2f1ccdb44a973571235c4a78487c040f26f116" + "reference": "78173b3c850e344cb8515fc2a05138d39a6c39e0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/fa2f1ccdb44a973571235c4a78487c040f26f116", - "reference": "fa2f1ccdb44a973571235c4a78487c040f26f116", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/78173b3c850e344cb8515fc2a05138d39a6c39e0", + "reference": "78173b3c850e344cb8515fc2a05138d39a6c39e0", "shasum": "" }, "require": { - "php": ">=7.1.3", + "php": ">=7.2.5", "symfony/polyfill-ctype": "^1.8", "symfony/polyfill-mbstring": "^1.3" }, @@ -3945,7 +3776,7 @@ "type": "tidelift" } ], - "time": "2020-10-14T06:37:57+00:00" + "time": "2020-10-21T12:45:52+00:00" }, { "name": "webmozart/assert", From 198b6e02b27e73868952f2a95cd0841a5c435884 Mon Sep 17 00:00:00 2001 From: hack3r-0m Date: Fri, 23 Oct 2020 17:46:51 +0000 Subject: [PATCH 2/5] refactored Dockerfile --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 184784856..c0f66d1c5 100755 --- a/Dockerfile +++ b/Dockerfile @@ -34,6 +34,8 @@ RUN \ RUN docker-php-ext-install sockets +# install C extension for .mmdb reader +# https://github.com/maxmind/libmaxminddb RUN wget https://github.com/maxmind/libmaxminddb/releases/download/1.4.3/libmaxminddb-1.4.3.tar.gz RUN tar -xvf libmaxminddb-1.4.3.tar.gz && \ cd ./libmaxminddb-1.4.3 && \ @@ -43,7 +45,6 @@ RUN tar -xvf libmaxminddb-1.4.3.tar.gz && \ make install && \ ldconfig ./libmaxminddb-1.4.3 - RUN \ # Redis Extension wget -q https://github.com/phpredis/phpredis/archive/$PHP_REDIS_VERSION.tar.gz && \ @@ -151,6 +152,7 @@ RUN \ zlib-dev \ brotli-dev +# Enabling C extension for .mmdb reader and adding loading it RUN apk add libmaxminddb-dev && \ cd vendor/maxmind-db/reader/ext && ls -a && \ phpize && \ From e102c9d9901594f9e763bc79af19025a84a9393d Mon Sep 17 00:00:00 2001 From: hack3r-0m Date: Sat, 24 Oct 2020 11:39:57 +0000 Subject: [PATCH 3/5] replaced old Reader method to new --- app/controllers/api/account.php | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index f80c09c6b..286463cd8 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -639,9 +639,17 @@ App::get('/v1/account/sessions') ]; try { - $record = $geodb->country($token->getAttribute('ip', '')); - $sessions[$index]['geo']['isoCode'] = \strtolower($record->country->isoCode); - $sessions[$index]['geo']['country'] = (isset($countries[$record->country->isoCode])) ? $countries[$record->country->isoCode] : $locale->getText('locale.country.unknown'); + $record = $geodb->get($token->getAttribute('ip', '')); + + if(isset($record)){ + $sessions[$index]['geo']['isoCode'] = \strtolower($record['country']['iso_code']); + $sessions[$index]['geo']['country'] = (isset($countries[$record['country']['iso_code']])) ? $countries[$record['country']['iso_code']] : $locale->getText('locale.country.unknown'); + } + else{ + $sessions[$index]['geo']['isoCode'] = '--'; + $sessions[$index]['geo']['country'] = $locale->getText('locale.country.unknown'); + } + } catch (\Exception $e) { $sessions[$index]['geo']['isoCode'] = '--'; $sessions[$index]['geo']['country'] = $locale->getText('locale.country.unknown'); @@ -716,10 +724,17 @@ App::get('/v1/account/logs') ]; try { - $record = $geodb->country($log['ip']); - $output[$i]['geo']['isoCode'] = \strtolower($record->country->isoCode); - $output[$i]['geo']['country'] = $record->country->name; - $output[$i]['geo']['country'] = (isset($countries[$record->country->isoCode])) ? $countries[$record->country->isoCode] : $locale->getText('locale.country.unknown'); + $record = $geodb->get($log['ip']); + + if(isset($record)){ + $output[$i]['geo']['isoCode'] = \strtolower($record['country']['iso_code']); + $output[$i]['geo']['country'] = (isset($countries[$record['country']['iso_code']])) ? $countries[$record['country']['iso_code']] : $locale->getText('locale.country.unknown'); + } + else{ + $output[$i]['geo']['isoCode'] = '--'; + $output[$i]['geo']['country'] = $locale->getText('locale.country.unknown'); + } + } catch (\Exception $e) { $output[$i]['geo']['isoCode'] = '--'; $output[$i]['geo']['country'] = $locale->getText('locale.country.unknown'); From 76202f19a60b44e288e51a36bdef298945953e9a Mon Sep 17 00:00:00 2001 From: hack3r-0m Date: Sat, 24 Oct 2020 11:48:07 +0000 Subject: [PATCH 4/5] replaced old Reader method to new --- app/controllers/api/users.php | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 21894e313..9de6f3356 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -270,9 +270,17 @@ App::get('/v1/users/:userId/sessions') ]; try { - $record = $geodb->country($token->getAttribute('ip', '')); - $sessions[$index]['geo']['isoCode'] = \strtolower($record->country->isoCode); - $sessions[$index]['geo']['country'] = (isset($countries[$record->country->isoCode])) ? $countries[$record->country->isoCode] : $locale->getText('locale.country.unknown'); + $record = $geodb->get($token->getAttribute('ip', '')); + + if(isset($record)){ + $sessions[$index]['geo']['isoCode'] = \strtolower($record['country']['iso_code']); + $sessions[$index]['geo']['country'] = (isset($countries[$record['country']['iso_code']])) ? $countries[$record['country']['iso_code']] : $locale->getText('locale.country.unknown'); + } + else{ + $sessions[$index]['geo']['isoCode'] = '--'; + $sessions[$index]['geo']['country'] = $locale->getText('locale.country.unknown'); + } + } catch (\Exception $e) { $sessions[$index]['geo']['isoCode'] = '--'; $sessions[$index]['geo']['country'] = $locale->getText('locale.country.unknown'); @@ -356,10 +364,17 @@ App::get('/v1/users/:userId/logs') ]; try { - $record = $geodb->country($log['ip']); - $output[$i]['geo']['isoCode'] = \strtolower($record->country->isoCode); - $output[$i]['geo']['country'] = $record->country->name; - $output[$i]['geo']['country'] = (isset($countries[$record->country->isoCode])) ? $countries[$record->country->isoCode] : $locale->getText('locale.country.unknown'); + $record = $geodb->get($log['ip']); + + if(isset($record)){ + $output[$i]['geo']['isoCode'] = \strtolower($record['country']['iso_code']); + $output[$i]['geo']['country'] = (isset($countries[$record['country']['iso_code']])) ? $countries[$record['country']['iso_code']] : $locale->getText('locale.country.unknown'); + } + else{ + $output[$i]['geo']['isoCode'] = '--'; + $output[$i]['geo']['country'] = $locale->getText('locale.country.unknown'); + } + } catch (\Exception $e) { $output[$i]['geo']['isoCode'] = '--'; $output[$i]['geo']['country'] = $locale->getText('locale.country.unknown'); From 0fe865064029c43ded3ff6c607bfceeb109894ea Mon Sep 17 00:00:00 2001 From: hack3r-0m Date: Sat, 24 Oct 2020 20:45:15 +0000 Subject: [PATCH 5/5] Fixed issues with Installing and Enabling C extension --- Dockerfile | 56 ++++++++++++++++++--------------------------------- composer.json | 1 - 2 files changed, 20 insertions(+), 37 deletions(-) diff --git a/Dockerfile b/Dockerfile index c0f66d1c5..d605f696b 100755 --- a/Dockerfile +++ b/Dockerfile @@ -30,23 +30,14 @@ RUN \ wget \ git \ zlib-dev \ - brotli-dev + brotli-dev \ + libmaxminddb-dev RUN docker-php-ext-install sockets -# install C extension for .mmdb reader -# https://github.com/maxmind/libmaxminddb -RUN wget https://github.com/maxmind/libmaxminddb/releases/download/1.4.3/libmaxminddb-1.4.3.tar.gz -RUN tar -xvf libmaxminddb-1.4.3.tar.gz && \ - cd ./libmaxminddb-1.4.3 && \ - ./configure && \ - make && \ - make check && \ - make install && \ - ldconfig ./libmaxminddb-1.4.3 - RUN \ # Redis Extension + wget -q https://github.com/phpredis/phpredis/archive/$PHP_REDIS_VERSION.tar.gz && \ tar -xf $PHP_REDIS_VERSION.tar.gz && \ cd phpredis-$PHP_REDIS_VERSION && \ @@ -54,15 +45,27 @@ RUN \ ./configure && \ make && make install && \ cd .. && \ + ## Swoole Extension + git clone https://github.com/swoole/swoole-src.git && \ cd swoole-src && \ git checkout v$PHP_SWOOLE_VERSION && \ phpize && \ ./configure --enable-sockets --enable-http2 && \ make && make install && \ + cd .. && \ + + ## php reader extension + + git clone https://github.com/maxmind/MaxMind-DB-Reader-php.git && \ + cd MaxMind-DB-Reader-php/ext && \ + phpize && \ + ./configure && \ + make && make install && \ cd .. + FROM php:7.4-cli-alpine as final LABEL maintainer="team@appwrite.io" @@ -120,6 +123,9 @@ RUN \ imagemagick-dev \ certbot \ docker-cli \ + libmaxminddb \ + libmaxminddb-dev \ + && pecl install imagick yaml \ && docker-php-ext-enable imagick yaml \ && docker-php-ext-install sockets opcache pdo_mysql \ @@ -131,6 +137,7 @@ WORKDIR /usr/src/code COPY --from=step0 /usr/local/src/vendor /usr/src/code/vendor COPY --from=step1 /usr/local/lib/php/extensions/no-debug-non-zts-20190902/swoole.so /usr/local/lib/php/extensions/no-debug-non-zts-20190902/ COPY --from=step1 /usr/local/lib/php/extensions/no-debug-non-zts-20190902/redis.so /usr/local/lib/php/extensions/no-debug-non-zts-20190902/ +COPY --from=step1 /usr/local/lib/php/extensions/no-debug-non-zts-20190902/maxminddb.so /usr/local/lib/php/extensions/no-debug-non-zts-20190902/ # Add Source Code COPY ./app /usr/src/code/app @@ -139,30 +146,6 @@ COPY ./docs /usr/src/code/docs COPY ./public /usr/src/code/public COPY ./src /usr/src/code/src -RUN \ - apk add --no-cache --virtual .deps \ - make \ - automake \ - autoconf \ - gcc \ - g++ \ - tar \ - wget \ - git \ - zlib-dev \ - brotli-dev - -# Enabling C extension for .mmdb reader and adding loading it -RUN apk add libmaxminddb-dev && \ - cd vendor/maxmind-db/reader/ext && ls -a && \ - phpize && \ - ./configure && \ - make && \ - make test && \ - make install - -RUN echo extension=maxminddb.so >> /usr/local/etc/php/php.ini - # Set Volumes RUN mkdir -p /storage/uploads && \ mkdir -p /storage/cache && \ @@ -200,6 +183,7 @@ RUN mkdir -p /etc/letsencrypt/live/ && chmod -Rf 755 /etc/letsencrypt/live/ # Enable Extensions RUN echo extension=swoole.so >> /usr/local/etc/php/conf.d/swoole.ini RUN echo extension=redis.so >> /usr/local/etc/php/conf.d/redis.ini +RUN echo extension=maxminddb.so >> /usr/local/etc/php/conf.d/maxminddb.ini RUN echo "opcache.preload_user=www-data" >> /usr/local/etc/php/conf.d/appwrite.ini RUN echo "opcache.preload=/usr/src/code/app/preload.php" >> /usr/local/etc/php/conf.d/appwrite.ini diff --git a/composer.json b/composer.json index 8b49062d4..7e716d45e 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,6 @@ "utopia-php/domains": "1.1.*", "resque/php-resque": "1.3.6", - "maxmind-db/reader": "1.8.*", "piwik/device-detector": "3.13.0", "dragonmantank/cron-expression": "3.0.1", "domnikl/statsd": "3.0.*",