|
| 1 | +FROM debian:jessie |
| 2 | + |
| 3 | +ENV \ |
| 4 | + NGINX_VERSION=1.11.6 \ |
| 5 | + PHP_VERSION=7.0.13 |
| 6 | + |
| 7 | +COPY \ |
| 8 | + docker-entrypoint \ |
| 9 | + nginx.conf \ |
| 10 | + Procfile \ |
| 11 | + /tmp/build/scripts/ |
| 12 | + |
| 13 | +RUN \ |
| 14 | + # Install tools, required for building |
| 15 | + apt-get update && \ |
| 16 | + apt-get install -y --no-install-recommends \ |
| 17 | + # In general... |
| 18 | + build-essential \ |
| 19 | + curl \ |
| 20 | + |
| 21 | + # For Nginx |
| 22 | + libpcre3-dev \ |
| 23 | + libssl-dev \ |
| 24 | + |
| 25 | + # For PHP |
| 26 | + bison \ |
| 27 | + libbz2-dev \ |
| 28 | + libcurl4-openssl-dev \ |
| 29 | + libpng12-dev \ |
| 30 | + libpq-dev \ |
| 31 | + libreadline-dev \ |
| 32 | + libxml2-dev \ |
| 33 | + libxslt1-dev \ |
| 34 | + pkg-config \ |
| 35 | + re2c \ |
| 36 | + |
| 37 | + # For PHP composer |
| 38 | + git \ |
| 39 | + |
| 40 | + # For Honcho |
| 41 | + python \ |
| 42 | + python-pip \ |
| 43 | + python-pkg-resources && \ |
| 44 | + |
| 45 | + pip install honcho && \ |
| 46 | + |
| 47 | + # Prepare for building |
| 48 | + mkdir -p /tmp/build && \ |
| 49 | + |
| 50 | + mkdir -p /tmp/build/nginx/ && \ |
| 51 | + cd /tmp/build/nginx && \ |
| 52 | + |
| 53 | + # Download Nginx |
| 54 | + curl -SLO https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \ |
| 55 | + |
| 56 | + cd /tmp/build/nginx && \ |
| 57 | + |
| 58 | + # GPG keys from the main maintainers of Nginx |
| 59 | + # Source https://nginx.org/en/pgp_keys.html |
| 60 | + curl -SLO https://nginx.org/keys/nginx_signing.key && \ |
| 61 | + gpg --import nginx_signing.key && \ |
| 62 | + curl -SLO https://nginx.org/keys/aalexeev.key && \ |
| 63 | + gpg --import aalexeev.key && \ |
| 64 | + curl -SLO https://nginx.org/keys/is.key && \ |
| 65 | + gpg --import is.key && \ |
| 66 | + curl -SLO https://nginx.org/keys/mdounin.key && \ |
| 67 | + gpg --import mdounin.key && \ |
| 68 | + curl -SLO https://nginx.org/keys/maxim.key && \ |
| 69 | + gpg --import maxim.key && \ |
| 70 | + curl -SLO https://nginx.org/keys/sb.key && \ |
| 71 | + gpg --import sb.key && \ |
| 72 | + |
| 73 | + # Verify signature |
| 74 | + curl -SLO https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz.asc && \ |
| 75 | + gpg nginx-${NGINX_VERSION}.tar.gz.asc && \ |
| 76 | + |
| 77 | + cd /tmp/build/nginx && \ |
| 78 | + # Unpack tarball |
| 79 | + tar -xvzf nginx-${NGINX_VERSION}.tar.gz && \ |
| 80 | + |
| 81 | + cd /tmp/build/nginx/nginx-${NGINX_VERSION} && \ |
| 82 | + # Run configuration |
| 83 | + ./configure \ |
| 84 | + --group=www-data \ |
| 85 | + --user=www-data \ |
| 86 | + --with-file-aio \ |
| 87 | + --with-http_gunzip_module \ |
| 88 | + --with-http_gzip_static_module \ |
| 89 | + --with-http_realip_module \ |
| 90 | + --with-http_ssl_module \ |
| 91 | + --with-http_v2_module \ |
| 92 | + --with-pcre \ |
| 93 | + --with-threads && \ |
| 94 | + |
| 95 | + cd /tmp/build/nginx/nginx-${NGINX_VERSION} && \ |
| 96 | + # Start compiling and installing |
| 97 | + make -j$(nproc) build && \ |
| 98 | + make modules && \ |
| 99 | + make install && \ |
| 100 | + |
| 101 | + # Nginx configuration |
| 102 | + mv /tmp/build/scripts/nginx.conf /usr/local/nginx/conf/ && \ |
| 103 | + |
| 104 | + mkdir -p /tmp/build/php/ && \ |
| 105 | + cd /tmp/build/php && \ |
| 106 | + |
| 107 | + # Download PHP |
| 108 | + curl -SLo php-${PHP_VERSION}.tar.gz http://ch1.php.net/get/php-${PHP_VERSION}.tar.gz/from/this/mirror && \ |
| 109 | + |
| 110 | + cd /tmp/build/php/ && \ |
| 111 | + |
| 112 | + # GPG keys from the release managers of PHP 7.0 |
| 113 | + # Source https://secure.php.net/gpg-keys.php#gpg-7.0 |
| 114 | + gpg --keyserver pgp.mit.edu/ --recv "1A4E 8B72 77C4 2E53 DBA9 C7B9 BCAA 30EA 9C0D 5763" && \ |
| 115 | + gpg --keyserver pgp.mit.edu/ --recv "6E4F 6AB3 21FD C07F 2C33 2E3A C2BF 0BC4 33CF C8B3" && \ |
| 116 | + |
| 117 | + # Verify signature |
| 118 | + curl -SLo php-${PHP_VERSION}.tar.gz.asc http://ch1.php.net/get/php-${PHP_VERSION}.tar.gz.asc/from/this/mirror && \ |
| 119 | + gpg php-${PHP_VERSION}.tar.gz.asc && \ |
| 120 | + |
| 121 | + cd /tmp/build/php && \ |
| 122 | + # Unpack tarball |
| 123 | + tar -xvzf php-${PHP_VERSION}.tar.gz && \ |
| 124 | + |
| 125 | + cd /tmp/build/php/php-${PHP_VERSION} && \ |
| 126 | + # Run configuration |
| 127 | + ./configure \ |
| 128 | + --enable-fpm \ |
| 129 | + --enable-mbregex \ |
| 130 | + --enable-mbstring \ |
| 131 | + --enable-mbstring=all \ |
| 132 | + --enable-opcache \ |
| 133 | + --enable-sockets \ |
| 134 | + --enable-zip \ |
| 135 | + --enable-zip \ |
| 136 | + --with-bz2 \ |
| 137 | + --with-curl \ |
| 138 | + --with-fpm-group=www-data \ |
| 139 | + --with-fpm-user=www-data \ |
| 140 | + --with-gd \ |
| 141 | + --with-gettext \ |
| 142 | + --with-openssl \ |
| 143 | + --with-pcre-regex \ |
| 144 | + --with-pdo-mysql \ |
| 145 | + --with-pdo-pgsql \ |
| 146 | + --with-readline \ |
| 147 | + --with-xsl \ |
| 148 | + --with-zlib && \ |
| 149 | + |
| 150 | + cd /tmp/build/php/php-${PHP_VERSION} && \ |
| 151 | + # Compile, test and install |
| 152 | + make -j$(nproc) build && \ |
| 153 | + make install && \ |
| 154 | + |
| 155 | + # Fix permissions |
| 156 | + chown -R www-data:www-data /usr/local/nginx/html && \ |
| 157 | + |
| 158 | + # Symlink Nginx binary |
| 159 | + ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ && \ |
| 160 | + |
| 161 | + # Copy PHP-FPM configuration files |
| 162 | + cp /tmp/build/php/php-${PHP_VERSION}/sapi/fpm/php-fpm.conf /usr/local/etc/php-fpm.conf && \ |
| 163 | + cp /tmp/build/php/php-${PHP_VERSION}/sapi/fpm/www.conf /usr/local/etc/www.conf && \ |
| 164 | + cp /tmp/build/php/php-${PHP_VERSION}/php.ini-development /usr/local/php/php.ini && \ |
| 165 | + |
| 166 | + # Patch PHP-FPM for proper loading www.conf |
| 167 | + sed -Ei \ |
| 168 | + -e 's/^;?\s*daemonize\s*=\s*yes/daemonize = no/' \ |
| 169 | + -e 's/^;?\s*include=NONE\/etc\/php-fpm.d\/\*.conf/include=\/usr\/local\/etc\/www.conf/' \ |
| 170 | + /usr/local/etc/php-fpm.conf && \ |
| 171 | + |
| 172 | + # Patch www.conf config connection establishment |
| 173 | + sed -Ei \ |
| 174 | + -e 's/^;?\s*listen\s*=.*/listen = \/var\/run\/php-fpm.sock/' \ |
| 175 | + -e 's/^;?\s*?\s*listen.owner\s*=.*/listen.owner = www-data/' \ |
| 176 | + -e 's/^;?\s*?\s*listen.group\s*=.*/listen.group = www-data/' \ |
| 177 | + -e 's/^;?\s*?\s*listen.mode\s*=.*/listen.mode = 0660/' \ |
| 178 | + /usr/local/etc/www.conf && \ |
| 179 | + |
| 180 | + # Patch PHP config files on the fly |
| 181 | + sed -Ei \ |
| 182 | + -e 's/^;?\s*expose_php\s*=.*/expose_php = Off/' \ |
| 183 | + -e 's/^;?\s*cgi.fix_pathinfo\s*=.*/cgi.fix_pathinfo=0/' \ |
| 184 | + -e 's/^;?\s*error_log\s*=.*/error_log = \/usr\/local\/nginx\/logs\/error-php.log/' \ |
| 185 | + -e 's/^;?\s*date.timezone\s*=.*/date.timezone = \"UTC\"/' \ |
| 186 | + -e 's/^;?\s*opcache.enable\s*=.*/opcache.enable = 1/' \ |
| 187 | + -e 's/^;?\s*opcache.enable_cli\s*=.*/opcache.enable_cli=1/' \ |
| 188 | + -e 's/^;?\s*opcache.memory_consumption\s*=.*/opcache.memory_consumption = 256/' \ |
| 189 | + -e 's/^;?\s*opcache.max_accelerated_files\s=.*/opcache.max_accelerated_files = 10000/' \ |
| 190 | + /usr/local/php/php.ini && \ |
| 191 | + |
| 192 | + # Install PHP composer |
| 193 | + php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \ |
| 194 | + php -r "if (hash_file('SHA384', 'composer-setup.php') === 'aa96f26c2b67226a324c27919f1eb05f21c248b987e6195cad9690d5c1ff713d53020a02ac8c217dbf90a7eacc9d141d') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \ |
| 195 | + php composer-setup.php --install-dir=/usr/local/bin --filename=composer && \ |
| 196 | + php -r "unlink('composer-setup.php');" && \ |
| 197 | + |
| 198 | + # Configure Honcho |
| 199 | + mv /tmp/build/scripts/Procfile / && \ |
| 200 | + |
| 201 | + # Add entrypoint for docker |
| 202 | + mv /tmp/build/scripts/docker-entrypoint / && \ |
| 203 | + chmod +x /docker-entrypoint && \ |
| 204 | + |
| 205 | + # Final cleanup |
| 206 | + apt-get remove -y \ |
| 207 | + bison \ |
| 208 | + build-essential \ |
| 209 | + curl \ |
| 210 | + pkg-config \ |
| 211 | + python-pip \ |
| 212 | + re2c && \ |
| 213 | + |
| 214 | + apt-get autoremove -y && \ |
| 215 | + |
| 216 | + rm -rf /var/lib/apt/lists/* && \ |
| 217 | + rm -rf /tmp/build |
| 218 | + |
| 219 | +# Declare entrypoint |
| 220 | +ENTRYPOINT ["/docker-entrypoint"] |
| 221 | + |
| 222 | +# Define default command |
| 223 | +CMD ["server"] |
| 224 | + |
| 225 | +# Define Workdir |
| 226 | +WORKDIR "/usr/local/nginx/html" |
| 227 | + |
| 228 | +# Exposing ports |
| 229 | +EXPOSE 80/tcp 443/tcp |
0 commit comments