From 375172f5d9bb7c924557a24e5aec76ca6e3629ad Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Fri, 26 Jun 2020 12:54:37 +0300 Subject: [PATCH] Work in progress --- Dockerfile | 168 +++++++++++++++++--------------------------- Dockerfile.nginx | 179 +++++++++++++++++++++++++++++++++++++++++++++++ app/server.php | 50 +++++++++++++ composer.json | 1 + composer.lock | 36 +++++++++- 5 files changed, 329 insertions(+), 105 deletions(-) mode change 100644 => 100755 Dockerfile create mode 100644 Dockerfile.nginx create mode 100644 app/server.php diff --git a/Dockerfile b/Dockerfile old mode 100644 new mode 100755 index 8a86a910f..e59cb2991 --- a/Dockerfile +++ b/Dockerfile @@ -1,56 +1,56 @@ -FROM ubuntu:18.04 AS builder - -LABEL maintainer="team@appwrite.io" +FROM composer:2.0 as step0 ARG TESTING=false - -ENV TZ=Asia/Tel_Aviv \ - DEBIAN_FRONTEND=noninteractive \ - PHP_VERSION=7.4 \ - PHP_REDIS_VERSION=5.2.1 - -RUN \ - apt-get update && \ - apt-get install -y --no-install-recommends --no-install-suggests ca-certificates software-properties-common wget git openssl && \ - LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php && \ - apt-get update && \ - apt-get install -y --no-install-recommends --no-install-suggests make php$PHP_VERSION php$PHP_VERSION-dev zip unzip php$PHP_VERSION-zip && \ - # 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 && \ - phpize$PHP_VERSION && \ - ./configure && \ - make && \ - # Composer - wget https://getcomposer.org/composer.phar && \ - chmod +x ./composer.phar && \ - mv ./composer.phar /usr/bin/composer && \ - #Brotli - cd / && \ - git clone https://github.com/eustas/ngx_brotli.git && \ - cd ngx_brotli && git submodule update --init && cd .. +ENV TESTING=$TESTING WORKDIR /usr/local/src/ -# Updating PHP Dependencies and Auto-loading... - -ENV TESTING=$TESTING - -COPY composer.* /usr/local/src/ +COPY composer.lock /usr/local/src/ +COPY composer.json /usr/local/src/ RUN composer update --ignore-platform-reqs --optimize-autoloader \ --no-plugins --no-scripts --prefer-dist \ `if [ "$TESTING" != "true" ]; then echo "--no-dev"; fi` -FROM ubuntu:18.04 +FROM php:7.4-cli as step1 + +ENV TZ=Asia/Tel_Aviv \ + DEBIAN_FRONTEND=noninteractive \ + PHP_REDIS_VERSION=5.2.1 \ + PHP_SWOOLE_VERSION=4.5.2 + +RUN \ + apt-get update && \ + apt-get install -y --no-install-recommends --no-install-suggests ca-certificates software-properties-common wget git openssl make zip unzip + +RUN docker-php-ext-install sockets + +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 && \ + phpize && \ + ./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 + ## Brotli Extension + +FROM php:7.4-cli as final + LABEL maintainer="team@appwrite.io" ARG VERSION=dev ENV TZ=Asia/Tel_Aviv \ DEBIAN_FRONTEND=noninteractive \ - PHP_VERSION=7.4 \ _APP_ENV=production \ _APP_DOMAIN=localhost \ _APP_DOMAIN_TARGET=localhost \ @@ -80,77 +80,32 @@ ENV TZ=Asia/Tel_Aviv \ #ENV _APP_SMTP_USERNAME '' #ENV _APP_SMTP_PASSWORD '' -COPY --from=builder /phpredis-5.2.1/modules/redis.so /usr/lib/php/20190902/ -COPY --from=builder /phpredis-5.2.1/modules/redis.so /usr/lib/php/20190902/ -COPY --from=builder /ngx_brotli /ngx_brotli - RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone RUN \ apt-get update && \ - apt-get install -y --no-install-recommends --no-install-suggests wget ca-certificates software-properties-common build-essential libpcre3-dev zlib1g-dev libssl-dev openssl gnupg htop supervisor && \ - LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php && \ - add-apt-repository universe && \ - add-apt-repository ppa:certbot/certbot && \ - apt-get update && \ - apt-get install -y --no-install-recommends --no-install-suggests php$PHP_VERSION php$PHP_VERSION-fpm \ - php$PHP_VERSION-mysqlnd php$PHP_VERSION-curl php$PHP_VERSION-imagick php$PHP_VERSION-mbstring php$PHP_VERSION-dom webp certbot && \ - # Nginx - wget http://nginx.org/download/nginx-1.19.0.tar.gz && \ - tar -xzvf nginx-1.19.0.tar.gz && rm nginx-1.19.0.tar.gz && \ - cd nginx-1.19.0 && \ - ./configure --prefix=/usr/share/nginx \ - --sbin-path=/usr/sbin/nginx \ - --modules-path=/usr/lib/nginx/modules \ - --conf-path=/etc/nginx/nginx.conf \ - --error-log-path=/var/log/nginx/error.log \ - --http-log-path=/var/log/nginx/access.log \ - --pid-path=/run/nginx.pid \ - --lock-path=/var/lock/nginx.lock \ - --user=www-data \ - --group=www-data \ - --build=Ubuntu \ - --with-http_gzip_static_module \ - --with-http_ssl_module \ - --with-http_v2_module \ - --add-module=/ngx_brotli && \ - make && \ - make install && \ - rm -rf ../nginx-1.19.0 && \ - # Redis Extension - echo extension=redis.so >> /etc/php/$PHP_VERSION/fpm/conf.d/redis.ini && \ - echo extension=redis.so >> /etc/php/$PHP_VERSION/cli/conf.d/redis.ini && \ - # Cleanup - cd ../ && \ - apt-get purge -y --auto-remove wget software-properties-common build-essential libpcre3-dev zlib1g-dev libssl-dev gnupg && \ - apt-get clean && \ - rm -rf /ngx_brotli && \ - rm -rf /var/lib/apt/lists/* + apt-get install -y --no-install-recommends --no-install-suggests webp certbot \ + libonig-dev libcurl4-gnutls-dev libmagickwand-dev libyaml-dev && \ + pecl install imagick yaml && \ + docker-php-ext-enable imagick yaml -# Set Upload Limit (default to 100MB) -RUN echo "upload_max_filesize = ${_APP_STORAGE_LIMIT}" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini -RUN echo "post_max_size = ${_APP_STORAGE_LIMIT}" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini +RUN docker-php-ext-install sockets curl pdo opcache -# Add logs file -RUN echo "" >> /var/log/appwrite.log +WORKDIR /usr/src/code -# Nginx Configuration (with self-signed ssl certificates) -COPY ./docker/nginx.conf.template /etc/nginx/nginx.conf.template -COPY ./docker/ssl/cert.pem /etc/nginx/ssl/cert.pem -COPY ./docker/ssl/key.pem /etc/nginx/ssl/key.pem +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/redis.so /usr/local/lib/php/extensions/no-debug-non-zts-20190902/ -# PHP Configuration -RUN mkdir -p /var/run/php -COPY ./docker/www.conf /etc/php/$PHP_VERSION/fpm/pool.d/www.conf - -# Add PHP Source Code -COPY ./app /usr/share/nginx/html/app +# Add Source Code +COPY ./app /usr/src/code/app COPY ./bin /usr/local/bin -COPY ./docs /usr/share/nginx/html/docs -COPY ./public /usr/share/nginx/html/public -COPY ./src /usr/share/nginx/html/src -COPY --from=builder /usr/local/src/vendor /usr/share/nginx/html/vendor +COPY ./docs /usr/src/code/docs +COPY ./public /usr/src/code/public +COPY ./src /usr/src/code/src +# Set Volumes RUN mkdir -p /storage/uploads && \ mkdir -p /storage/cache && \ mkdir -p /storage/config && \ @@ -160,9 +115,6 @@ RUN mkdir -p /storage/uploads && \ chown -Rf www-data.www-data /storage/config && chmod -Rf 0755 /storage/config && \ chown -Rf www-data.www-data /storage/certificates && chmod -Rf 0755 /storage/certificates -# Supervisord Conf -COPY ./docker/supervisord.conf /etc/supervisord.conf - # Executables RUN chmod +x /usr/local/bin/start RUN chmod +x /usr/local/bin/doctor @@ -172,8 +124,16 @@ RUN chmod +x /usr/local/bin/test # Letsencrypt Permissions RUN mkdir -p /etc/letsencrypt/live/ && chmod -Rf 755 /etc/letsencrypt/live/ -EXPOSE 80 +# 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 -WORKDIR /usr/share/nginx/html +EXPOSE 9501 -CMD ["/bin/bash", "/usr/local/bin/start"] +# CMD [ "php" , "app/server.php" ] +CMD [ "php" , "-i" ] + +# static files: https://gist.github.com/ezimuel/a2e0ff7308952f2aa946f828a1302a63 + +# docker build -t saw . +# docker run -it --rm --name saw-run saw \ No newline at end of file diff --git a/Dockerfile.nginx b/Dockerfile.nginx new file mode 100644 index 000000000..8a86a910f --- /dev/null +++ b/Dockerfile.nginx @@ -0,0 +1,179 @@ +FROM ubuntu:18.04 AS builder + +LABEL maintainer="team@appwrite.io" + +ARG TESTING=false + +ENV TZ=Asia/Tel_Aviv \ + DEBIAN_FRONTEND=noninteractive \ + PHP_VERSION=7.4 \ + PHP_REDIS_VERSION=5.2.1 + +RUN \ + apt-get update && \ + apt-get install -y --no-install-recommends --no-install-suggests ca-certificates software-properties-common wget git openssl && \ + LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php && \ + apt-get update && \ + apt-get install -y --no-install-recommends --no-install-suggests make php$PHP_VERSION php$PHP_VERSION-dev zip unzip php$PHP_VERSION-zip && \ + # 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 && \ + phpize$PHP_VERSION && \ + ./configure && \ + make && \ + # Composer + wget https://getcomposer.org/composer.phar && \ + chmod +x ./composer.phar && \ + mv ./composer.phar /usr/bin/composer && \ + #Brotli + cd / && \ + git clone https://github.com/eustas/ngx_brotli.git && \ + cd ngx_brotli && git submodule update --init && cd .. + +WORKDIR /usr/local/src/ + +# Updating PHP Dependencies and Auto-loading... + +ENV TESTING=$TESTING + +COPY composer.* /usr/local/src/ + +RUN composer update --ignore-platform-reqs --optimize-autoloader \ + --no-plugins --no-scripts --prefer-dist \ + `if [ "$TESTING" != "true" ]; then echo "--no-dev"; fi` + +FROM ubuntu:18.04 +LABEL maintainer="team@appwrite.io" + +ARG VERSION=dev + +ENV TZ=Asia/Tel_Aviv \ + DEBIAN_FRONTEND=noninteractive \ + PHP_VERSION=7.4 \ + _APP_ENV=production \ + _APP_DOMAIN=localhost \ + _APP_DOMAIN_TARGET=localhost \ + _APP_HOME=https://appwrite.io \ + _APP_EDITION=community \ + _APP_OPTIONS_ABUSE=enabled \ + _APP_OPTIONS_FORCE_HTTPS=disabled \ + _APP_OPENSSL_KEY_V1=your-secret-key \ + _APP_STORAGE_LIMIT=104857600 \ + _APP_STORAGE_ANTIVIRUS=enabled \ + _APP_REDIS_HOST=redis \ + _APP_REDIS_PORT=6379 \ + _APP_DB_HOST=mariadb \ + _APP_DB_PORT=3306 \ + _APP_DB_USER=root \ + _APP_DB_PASS=password \ + _APP_DB_SCHEMA=appwrite \ + _APP_INFLUXDB_HOST=influxdb \ + _APP_INFLUXDB_PORT=8086 \ + _APP_STATSD_HOST=telegraf \ + _APP_STATSD_PORT=8125 \ + _APP_SMTP_HOST=smtp \ + _APP_SMTP_PORT=25 \ + _APP_SETUP=self-hosted \ + _APP_VERSION=$VERSION +#ENV _APP_SMTP_SECURE '' +#ENV _APP_SMTP_USERNAME '' +#ENV _APP_SMTP_PASSWORD '' + +COPY --from=builder /phpredis-5.2.1/modules/redis.so /usr/lib/php/20190902/ +COPY --from=builder /phpredis-5.2.1/modules/redis.so /usr/lib/php/20190902/ +COPY --from=builder /ngx_brotli /ngx_brotli + +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +RUN \ + apt-get update && \ + apt-get install -y --no-install-recommends --no-install-suggests wget ca-certificates software-properties-common build-essential libpcre3-dev zlib1g-dev libssl-dev openssl gnupg htop supervisor && \ + LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php && \ + add-apt-repository universe && \ + add-apt-repository ppa:certbot/certbot && \ + apt-get update && \ + apt-get install -y --no-install-recommends --no-install-suggests php$PHP_VERSION php$PHP_VERSION-fpm \ + php$PHP_VERSION-mysqlnd php$PHP_VERSION-curl php$PHP_VERSION-imagick php$PHP_VERSION-mbstring php$PHP_VERSION-dom webp certbot && \ + # Nginx + wget http://nginx.org/download/nginx-1.19.0.tar.gz && \ + tar -xzvf nginx-1.19.0.tar.gz && rm nginx-1.19.0.tar.gz && \ + cd nginx-1.19.0 && \ + ./configure --prefix=/usr/share/nginx \ + --sbin-path=/usr/sbin/nginx \ + --modules-path=/usr/lib/nginx/modules \ + --conf-path=/etc/nginx/nginx.conf \ + --error-log-path=/var/log/nginx/error.log \ + --http-log-path=/var/log/nginx/access.log \ + --pid-path=/run/nginx.pid \ + --lock-path=/var/lock/nginx.lock \ + --user=www-data \ + --group=www-data \ + --build=Ubuntu \ + --with-http_gzip_static_module \ + --with-http_ssl_module \ + --with-http_v2_module \ + --add-module=/ngx_brotli && \ + make && \ + make install && \ + rm -rf ../nginx-1.19.0 && \ + # Redis Extension + echo extension=redis.so >> /etc/php/$PHP_VERSION/fpm/conf.d/redis.ini && \ + echo extension=redis.so >> /etc/php/$PHP_VERSION/cli/conf.d/redis.ini && \ + # Cleanup + cd ../ && \ + apt-get purge -y --auto-remove wget software-properties-common build-essential libpcre3-dev zlib1g-dev libssl-dev gnupg && \ + apt-get clean && \ + rm -rf /ngx_brotli && \ + rm -rf /var/lib/apt/lists/* + +# Set Upload Limit (default to 100MB) +RUN echo "upload_max_filesize = ${_APP_STORAGE_LIMIT}" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini +RUN echo "post_max_size = ${_APP_STORAGE_LIMIT}" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini + +# Add logs file +RUN echo "" >> /var/log/appwrite.log + +# Nginx Configuration (with self-signed ssl certificates) +COPY ./docker/nginx.conf.template /etc/nginx/nginx.conf.template +COPY ./docker/ssl/cert.pem /etc/nginx/ssl/cert.pem +COPY ./docker/ssl/key.pem /etc/nginx/ssl/key.pem + +# PHP Configuration +RUN mkdir -p /var/run/php +COPY ./docker/www.conf /etc/php/$PHP_VERSION/fpm/pool.d/www.conf + +# Add PHP Source Code +COPY ./app /usr/share/nginx/html/app +COPY ./bin /usr/local/bin +COPY ./docs /usr/share/nginx/html/docs +COPY ./public /usr/share/nginx/html/public +COPY ./src /usr/share/nginx/html/src +COPY --from=builder /usr/local/src/vendor /usr/share/nginx/html/vendor + +RUN mkdir -p /storage/uploads && \ + mkdir -p /storage/cache && \ + mkdir -p /storage/config && \ + mkdir -p /storage/certificates && \ + chown -Rf www-data.www-data /storage/uploads && chmod -Rf 0755 /storage/uploads && \ + chown -Rf www-data.www-data /storage/cache && chmod -Rf 0755 /storage/cache && \ + chown -Rf www-data.www-data /storage/config && chmod -Rf 0755 /storage/config && \ + chown -Rf www-data.www-data /storage/certificates && chmod -Rf 0755 /storage/certificates + +# Supervisord Conf +COPY ./docker/supervisord.conf /etc/supervisord.conf + +# Executables +RUN chmod +x /usr/local/bin/start +RUN chmod +x /usr/local/bin/doctor +RUN chmod +x /usr/local/bin/migrate +RUN chmod +x /usr/local/bin/test + +# Letsencrypt Permissions +RUN mkdir -p /etc/letsencrypt/live/ && chmod -Rf 755 /etc/letsencrypt/live/ + +EXPOSE 80 + +WORKDIR /usr/share/nginx/html + +CMD ["/bin/bash", "/usr/local/bin/start"] diff --git a/app/server.php b/app/server.php new file mode 100644 index 000000000..c43b25470 --- /dev/null +++ b/app/server.php @@ -0,0 +1,50 @@ +set([ + 'open_http2_protocol' => true, + 'document_root' => __DIR__ . '/../public', + 'enable_static_handler' => true, + 'timeout' => 4, + ]) +; + +$server->on('WorkerStart', function($serv, $workerId) { + Console::success('Server started succefully'); +}); + +$server->on('BeforeReload', function($serv, $workerId) { + Console::success('Starting reload...'); +}); + +$server->on('AfterReload', function($serv, $workerId) { + Console::success('Reload completed...'); +}); + +// http && http2 +$server->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swooleResponse) { + +}); + +// websocket +$server->on('message', function (Server $server, Frame $frame) { + $server->push($frame->fd, 'Hello ' . $frame->data); +}); + +$server->start(); \ No newline at end of file diff --git a/composer.json b/composer.json index 78b0fd76c..c2a0606be 100644 --- a/composer.json +++ b/composer.json @@ -52,6 +52,7 @@ "phpmailer/phpmailer": "6.1.6" }, "require-dev": { + "swoole/ide-helper": "4.5.2", "appwrite/sdk-generator": "master", "phpunit/phpunit": "^7.0" }, diff --git a/composer.lock b/composer.lock index 595045b9b..9cb06696f 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": "7f6cbe77fe2e0f8bdff33c37a4d9ca11", + "content-hash": "950a131ba83024caad4b96de7c184b58", "packages": [ { "name": "appwrite/php-clamav", @@ -3199,6 +3199,40 @@ "homepage": "https://github.com/sebastianbergmann/version", "time": "2016-10-03T07:35:21+00:00" }, + { + "name": "swoole/ide-helper", + "version": "4.5.2", + "source": { + "type": "git", + "url": "https://github.com/swoole/ide-helper.git", + "reference": "e45892fb913204fc776bdec019ca8b723e7249b1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/swoole/ide-helper/zipball/e45892fb913204fc776bdec019ca8b723e7249b1", + "reference": "e45892fb913204fc776bdec019ca8b723e7249b1", + "shasum": "" + }, + "require-dev": { + "guzzlehttp/guzzle": "~6.5.0", + "laminas/laminas-code": "~3.4.0", + "squizlabs/php_codesniffer": "~3.5.0", + "symfony/filesystem": "~4.0" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Team Swoole", + "email": "team@swoole.com" + } + ], + "description": "IDE help files for Swoole.", + "time": "2020-05-28T19:17:49+00:00" + }, { "name": "symfony/polyfill-ctype", "version": "dev-master",