浏览代码

docker fixes

develop
Robin Thoni 8 年前
父节点
当前提交
12632752f2
共有 7 个文件被更改,包括 286 次插入129 次删除
  1. 0
    15
      app/Route/routes.json
  2. 0
    0
      app/routes.php
  3. 104
    114
      docker/Dockerfile
  4. 19
    0
      docker/docker-php-ext-configure
  5. 83
    0
      docker/docker-php-ext-enable
  6. 79
    0
      docker/docker-php-ext-install
  7. 1
    0
      docker/php-apache.ini

+ 0
- 15
app/Route/routes.json 查看文件

@@ -1,15 +0,0 @@
1
-{
2
-  "middlewares": [
3
-    {
4
-      "middleware": "Luticate\\Auth\\Business\\LuticateMiddleware",
5
-      "parameters": {}
6
-    }
7
-  ],
8
-  "routes": [
9
-    {
10
-      "method": "GET", "url": "/test",
11
-      "controller": "Test", "action": "test",
12
-      "middlewares": [], "permissions": []
13
-    }
14
-  ]
15
-}

app/Route/routes.php → app/routes.php 查看文件


+ 104
- 114
docker/Dockerfile 查看文件

@@ -1,80 +1,49 @@
1
-#ADD https://www.dotdeb.org/dotdeb.gpg /tmp/dotdeb.gpg
2
-#RUN apt-key add /tmp/dotdeb.gpg
3
-#COPY php7.list /etc/apt/sources.list.d
4
-#
5
-#RUN apt-get update &&\
6
-#        apt-get -y install\
7
-#        apache2=2.4.*\
8
-#        php-pear\
9
-#        libapache2-mod-php7.0\
10
-#        php7.0\
11
-#        php7.0-gd\
12
-#        php7.0-curl\
13
-#        php7.0-pgsql\
14
-#        php7.0-mcrypt\
15
-#        php7.0-json &&\
16
-#        apt-get clean
17
-#
18
-#COPY apache2.conf /etc/apache2/apache2.conf
19
-#COPY run.sh /run.sh
20
-#
21
-#RUN /usr/sbin/a2enmod rewrite &&\
22
-#        ln -sf /dev/stdout /var/log/apache2/access.log &&\
23
-#        ln -sf /dev/stderr /var/log/apache2/error.log &&\
24
-#        rm -rf /var/www/ &&\
25
-#        mkdir -p /var/lock/apache2 /var/run/apache2 /var/log/apache2 /var/www &&\
26
-#        chown -R www-data:www-data /var/lock/apache2 /var/run/apache2 /var/log/apache2 /var/www &&\
27
-#        chmod +x /run.sh
28
-#
29
-#EXPOSE 80
30
-#
31
-#VOLUME ["/var/www"]
32
-#
33
-#CMD ["/run.sh"]
34
-
35
-
36
-
37 1
 FROM debian:jessie
38 2
 
39 3
 MAINTAINER Robin Thoni <robin@rthoni.com>
40 4
 
41
-# persistent / runtime deps
5
+# Build php
6
+# ======================================================================================================================
42 7
 ENV PHPIZE_DEPS \
43
-		autoconf \
44
-		file \
45
-		g++ \
46
-		gcc \
47
-		libc-dev \
48
-		make \
49
-		pkg-config \
50
-		re2c
51
-RUN apt-get update && apt-get install -y \
52
-		$PHPIZE_DEPS \
53
-		ca-certificates \
54
-		curl \
55
-		libedit2 \
56
-		libsqlite3-0 \
57
-		libxml2 \
58
-	--no-install-recommends && rm -r /var/lib/apt/lists/*
59
-
60
-ENV PHP_INI_DIR /usr/local/etc/php
8
+            autoconf \
9
+            file \
10
+            g++ \
11
+            gcc \
12
+            libc-dev \
13
+            make \
14
+            pkg-config \
15
+            re2c
16
+RUN apt-get update \
17
+        && apt-get install -y \
18
+		    $PHPIZE_DEPS \
19
+		    ca-certificates \
20
+		    curl \
21
+		    libedit2 \
22
+		    libsqlite3-0 \
23
+		    libxml2 \
24
+	        --no-install-recommends \
25
+	    && rm -r /var/lib/apt/lists/*
26
+
27
+ENV PHP_INI_DIR /etc/php7.0
61 28
 RUN mkdir -p $PHP_INI_DIR/conf.d
62 29
 
63
-##<autogenerated>##
64
-RUN apt-get update && apt-get install -y apache2-bin apache2.2-common --no-install-recommends && rm -rf /var/lib/apt/lists/*
30
+RUN apt-get update \
31
+        && apt-get install -y apache2-bin apache2.2-common --no-install-recommends \
32
+        && rm -rf /var/lib/apt/lists/*
65 33
 
66
-RUN rm -rf /var/www/html && mkdir -p /var/lock/apache2 /var/run/apache2 /var/log/apache2 /var/www/html && chown -R www-data:www-data /var/lock/apache2 /var/run/apache2 /var/log/apache2 /var/www/html
34
+RUN rm -rf /var/www/html \
35
+        && mkdir -p /var/lock/apache2 /var/run/apache2 /var/log/apache2 /var/www/html \
36
+        && chown -R www-data:www-data /var/lock/apache2 /var/run/apache2 /var/log/apache2 /var/www/html
67 37
 
68
-# Apache + PHP requires preforking Apache for best results
69
-RUN a2dismod mpm_event && a2enmod mpm_prefork
38
+RUN a2dismod mpm_event \
39
+        && a2enmod mpm_prefork
70 40
 
71
-RUN mv /etc/apache2/apache2.conf /etc/apache2/apache2.conf.dist && rm /etc/apache2/conf-enabled/* /etc/apache2/sites-enabled/*
41
+RUN mv /etc/apache2/apache2.conf /etc/apache2/apache2.conf.dist \
42
+        && rm /etc/apache2/conf-enabled/* /etc/apache2/sites-enabled/*
72 43
 COPY apache2.conf /etc/apache2/apache2.conf
73
-# it'd be nice if we could not COPY apache2.conf until the end of the Dockerfile, but its contents are checked by PHP during compilation
74 44
 
75 45
 ENV PHP_EXTRA_BUILD_DEPS apache2-dev
76 46
 ENV PHP_EXTRA_CONFIGURE_ARGS --with-apxs2 --enable-maintainer-zts --enable-pthreads
77
-##</autogenerated>##
78 47
 
79 48
 ENV GPG_KEYS 1A4E8B7277C42E53DBA9C7B9BCAA30EA9C0D5763
80 49
 
@@ -83,65 +52,86 @@ ENV PHP_FILENAME php-7.0.7.tar.xz
83 52
 ENV PHP_SHA256 9cc64a7459242c79c10e79d74feaf5bae3541f604966ceb600c3d2e8f5fe4794
84 53
 
85 54
 RUN set -xe \
86
-	&& buildDeps=" \
87
-		$PHP_EXTRA_BUILD_DEPS \
88
-		libcurl4-openssl-dev \
89
-		libedit-dev \
90
-		libsqlite3-dev \
91
-		libssl-dev \
92
-		libxml2-dev \
93
-		xz-utils \
94
-	" \
95
-	&& apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \
96
-	&& curl -fSL "http://php.net/get/$PHP_FILENAME/from/this/mirror" -o "$PHP_FILENAME" \
97
-	&& echo "$PHP_SHA256 *$PHP_FILENAME" | sha256sum -c - \
98
-	&& curl -fSL "http://php.net/get/$PHP_FILENAME.asc/from/this/mirror" -o "$PHP_FILENAME.asc" \
99
-	&& export GNUPGHOME="$(mktemp -d)" \
100
-	&& for key in $GPG_KEYS; do \
101
-		gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
102
-	done \
103
-	&& gpg --batch --verify "$PHP_FILENAME.asc" "$PHP_FILENAME" \
104
-	&& rm -r "$GNUPGHOME" "$PHP_FILENAME.asc" \
105
-	&& mkdir -p /usr/src/php \
106
-	&& tar -xf "$PHP_FILENAME" -C /usr/src/php --strip-components=1 \
107
-	&& rm "$PHP_FILENAME" \
108
-	&& cd /usr/src/php \
109
-	&& ./configure \
110
-		--with-config-file-path="$PHP_INI_DIR" \
111
-		--with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \
112
-		$PHP_EXTRA_CONFIGURE_ARGS \
113
-		--disable-cgi \
114
-# --enable-mysqlnd is included here because it's harder to compile after the fact than extensions are (since it's a plugin for several extensions, not an extension in itself)
115
-		--enable-mysqlnd \
116
-# --enable-mbstring is included here because otherwise there's no way to get pecl to use it properly (see https://github.com/docker-library/php/issues/195)
117
-		--enable-mbstring \
118
-		--with-curl \
119
-		--with-libedit \
120
-		--with-openssl \
121
-		--with-zlib \
122
-	&& make -j"$(nproc)" \
123
-	&& make install \
124
-	&& { find /usr/local/bin /usr/local/sbin -type f -executable -exec strip --strip-all '{}' + || true; } \
125
-	&& make clean \
126
-	&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false -o APT::AutoRemove::SuggestsImportant=false $buildDeps
55
+        && buildDeps=" \
56
+            $PHP_EXTRA_BUILD_DEPS \
57
+            libcurl4-openssl-dev \
58
+            libedit-dev \
59
+            libsqlite3-dev \
60
+            libssl-dev \
61
+            libxml2-dev \
62
+            xz-utils \
63
+        " \
64
+        && apt-get update \
65
+        && apt-get install -y $buildDeps --no-install-recommends \
66
+        && rm -rf /var/lib/apt/lists/* \
67
+        && curl -fSL "http://php.net/get/$PHP_FILENAME/from/this/mirror" -o "$PHP_FILENAME" \
68
+        && echo "$PHP_SHA256 *$PHP_FILENAME" | sha256sum -c - \
69
+        && curl -fSL "http://php.net/get/$PHP_FILENAME.asc/from/this/mirror" -o "$PHP_FILENAME.asc" \
70
+        && export GNUPGHOME="$(mktemp -d)" \
71
+        && for key in $GPG_KEYS; do \
72
+            gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
73
+            done \
74
+        && gpg --batch --verify "$PHP_FILENAME.asc" "$PHP_FILENAME" \
75
+        && rm -r "$GNUPGHOME" "$PHP_FILENAME.asc" \
76
+        && mkdir -p /usr/src/php \
77
+        && tar -xf "$PHP_FILENAME" -C /usr/src/php --strip-components=1 \
78
+        && rm "$PHP_FILENAME" \
79
+        && cd /usr/src/php \
80
+        && ./configure \
81
+            --with-config-file-path="$PHP_INI_DIR" \
82
+            --with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \
83
+            $PHP_EXTRA_CONFIGURE_ARGS \
84
+            --disable-cgi \
85
+            --enable-mysqlnd \
86
+            --enable-mbstring \
87
+            --with-curl \
88
+            --with-libedit \
89
+            --with-openssl \
90
+            --with-zlib \
91
+        && make -j"$(nproc)" \
92
+        && make install \
93
+        && { find /usr/local/bin /usr/local/sbin -type f -executable -exec strip --strip-all '{}' + || true; } \
94
+        && make clean \
95
+        && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false -o APT::AutoRemove::SuggestsImportant=false $buildDeps
127 96
 
128 97
 RUN ln -sf /dev/stdout /var/log/apache2/access.log \
129
-	&& ln -sf /dev/stderr /var/log/apache2/error.log \
130
-	&& ln -sf /dev/stdout /var/log/websocket.log \
131
-    && ln -sf /dev/stderr /var/log/websocket.err \
132
-	&& a2enmod rewrite \
133
-	&& rm -rf /var/www/* \
134
-	&& chown -R www-data:www-data /var/www
98
+        && ln -sf /dev/stderr /var/log/apache2/error.log \
99
+        && ln -sf /dev/stdout /var/log/websocket.log \
100
+        && ln -sf /dev/stderr /var/log/websocket.err \
101
+        && a2enmod rewrite \
102
+        && rm -rf /var/www/* \
103
+        && chown -R www-data:www-data /var/www
104
+
105
+COPY php-cli.ini "${PHP_INI_DIR}"/
106
+COPY php-apache.ini "${PHP_INI_DIR}"/php-apache2handler.ini
135 107
 
136
-RUN curl https://getcomposer.org/composer.phar -o /usr/local/bin/composer && chmod +x /usr/local/bin/composer
108
+RUN pecl install pthreads
137 109
 
138
-RUN apt-get update && apt-get install -y git unzip --no-install-recommends && rm -rf /var/lib/apt/lists/*
110
+# Install Composer
111
+# ======================================================================================================================
112
+RUN curl https://getcomposer.org/composer.phar -o /usr/local/bin/composer \
113
+        && chmod +x /usr/local/bin/composer
139 114
 
140
-COPY php-cli.ini /etc/php7.0/cli/php.ini
115
+RUN apt-get update \
116
+        && apt-get install -y git unzip --no-install-recommends \
117
+        && rm -rf /var/lib/apt/lists/*
141 118
 
142
-RUN pecl install pthreads && mkdir -p /etc/php7.0/cli
119
+# Add pdo and db drivers
120
+# ======================================================================================================================
121
+
122
+COPY docker-php-ext-* /usr/local/bin/
123
+
124
+RUN buildDeps="libpq-dev libzip-dev " \
125
+        && apt-get update \
126
+        && apt-get install -y $buildDeps --no-install-recommends \
127
+        && rm -rf /var/lib/apt/lists/* \
128
+        && docker-php-ext-install pdo pdo_pgsql pgsql
129
+
130
+# Run everything
131
+# ======================================================================================================================
143 132
 
144 133
 COPY run.sh /usr/local/bin/
134
+
145 135
 WORKDIR /var/www
146 136
 
147 137
 EXPOSE 8180

+ 19
- 0
docker/docker-php-ext-configure 查看文件

@@ -0,0 +1,19 @@
1
+#!/bin/sh
2
+set -e
3
+
4
+ext="$1"
5
+extDir="/usr/src/php/ext/$ext"
6
+if [ -z "$ext" ] || ! [ -d "$extDir" ]; then
7
+	echo >&2 "usage: $0 ext-name [configure flags]"
8
+	echo >&2 "   ie: $0 gd --with-jpeg-dir=/usr/local/something"
9
+	echo >&2
10
+	echo >&2 'Possible values for ext-name:'
11
+	echo >&2 $(find /usr/src/php/ext -mindepth 2 -maxdepth 2 -type f -name 'config.m4' | cut -d/ -f6 | sort)
12
+	exit 1
13
+fi
14
+shift
15
+
16
+set -x
17
+cd "$extDir"
18
+phpize
19
+./configure "$@"

+ 83
- 0
docker/docker-php-ext-enable 查看文件

@@ -0,0 +1,83 @@
1
+#!/bin/sh
2
+set -e
3
+
4
+cd "$(php -r 'echo ini_get("extension_dir");')"
5
+
6
+usage() {
7
+	echo "usage: $0 [options] module-name [module-name ...]"
8
+	echo "   ie: $0 gd mysqli"
9
+	echo "       $0 pdo pdo_mysql"
10
+	echo "       $0 --ini-name 0-apc.ini apcu apc"
11
+	echo
12
+	echo 'Possible values for module-name:'
13
+	echo $(find -maxdepth 1 -type f -name '*.so' -exec basename '{}' ';' | sort)
14
+}
15
+
16
+opts="$(getopt -o 'h?' --long 'help,ini-name:' -- "$@" || { usage >&2 && false; })"
17
+eval set -- "$opts"
18
+
19
+iniName=
20
+while true; do
21
+	flag="$1"
22
+	shift
23
+	case "$flag" in
24
+		--help|-h|'-?') usage && exit 0 ;;
25
+		--ini-name) iniName="$1" && shift ;;
26
+		--) break ;;
27
+		*)
28
+			{
29
+				echo "error: unknown flag: $flag"
30
+				usage
31
+			} >&2
32
+			exit 1
33
+			;;
34
+	esac
35
+done
36
+
37
+modules=
38
+for module; do
39
+	if [ -z "$module" ]; then
40
+		continue
41
+	fi
42
+	if [ -f "$module.so" ] && ! [ -f "$module" ]; then
43
+		# allow ".so" to be optional
44
+		module="$module.so"
45
+	fi
46
+	if ! [ -f "$module" ]; then
47
+		echo >&2 "error: $(readlink -f "$module") does not exist"
48
+		echo >&2
49
+		usage >&2
50
+		exit 1
51
+	fi
52
+	modules="$modules $module"
53
+done
54
+
55
+if [ -z "$modules" ]; then
56
+	usage >&2
57
+	exit 1
58
+fi
59
+
60
+for module in $modules; do
61
+	if nm -g "$module" | grep -q ' zend_extension_entry$'; then
62
+		# https://wiki.php.net/internals/extensions#loading_zend_extensions
63
+		line="zend_extension=$(readlink -f "$module")"
64
+	else
65
+		line="extension=$module"
66
+	fi
67
+
68
+	ext="$(basename "$module")"
69
+	ext="${ext%.*}"
70
+	if php -r 'exit(extension_loaded("'"$ext"'") ? 0 : 1);'; then
71
+		# this isn't perfect, but it's better than nothing
72
+		# (for example, 'opcache.so' presents inside PHP as 'Zend OPcache', not 'opcache')
73
+		echo >&2
74
+		echo >&2 "warning: $ext ($module) is already loaded!"
75
+		echo >&2
76
+		continue
77
+	fi
78
+
79
+	ini="${PHP_INI_DIR}/conf.d/${iniName:-"docker-php-ext-$ext.ini"}"
80
+	if ! grep -q "$line" "$ini" 2>/dev/null; then
81
+		echo "$line" >> "$ini"
82
+	fi
83
+done

+ 79
- 0
docker/docker-php-ext-install 查看文件

@@ -0,0 +1,79 @@
1
+#!/bin/sh
2
+set -e
3
+
4
+cd /usr/src/php/ext
5
+
6
+usage() {
7
+	echo "usage: $0 [-jN] ext-name [ext-name ...]"
8
+	echo "   ie: $0 gd mysqli"
9
+	echo "       $0 pdo pdo_mysql"
10
+	echo "       $0 -j5 gd mbstring mysqli pdo pdo_mysql shmop"
11
+	echo
12
+	echo 'if custom ./configure arguments are necessary, see docker-php-ext-configure'
13
+	echo
14
+	echo 'Possible values for ext-name:'
15
+	echo $(find /usr/src/php/ext -mindepth 2 -maxdepth 2 -type f -name 'config.m4' | cut -d/ -f6 | sort)
16
+}
17
+
18
+opts="$(getopt -o 'h?j:' --long 'help,jobs:' -- "$@" || { usage >&2 && false; })"
19
+eval set -- "$opts"
20
+
21
+j=1
22
+while true; do
23
+	flag="$1"
24
+	shift
25
+	case "$flag" in
26
+		--help|-h|'-?') usage && exit 0 ;;
27
+		--jobs|-j) j="$1" && shift ;;
28
+		--) break ;;
29
+		*)
30
+			{
31
+				echo "error: unknown flag: $flag"
32
+				usage
33
+			} >&2
34
+			exit 1
35
+			;;
36
+	esac
37
+done
38
+
39
+exts=
40
+for ext; do
41
+	if [ -z "$ext" ]; then
42
+		continue
43
+	fi
44
+	if [ ! -d "$ext" ]; then
45
+		echo >&2 "error: $(pwd -P)/$ext does not exist"
46
+		echo >&2
47
+		usage >&2
48
+		exit 1
49
+	fi
50
+	exts="$exts $ext"
51
+done
52
+
53
+if [ -z "$exts" ]; then
54
+	usage >&2
55
+	exit 1
56
+fi
57
+
58
+if [ -e /lib/apk/db/installed ] && [ -n "$PHPIZE_DEPS" ]; then
59
+	apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS
60
+fi
61
+
62
+for ext in $exts; do
63
+	(
64
+		cd "$ext"
65
+		[ -e Makefile ] || docker-php-ext-configure "$ext"
66
+		make -j"$j"
67
+		make -j"$j" install
68
+		find modules \
69
+			-maxdepth 1 \
70
+			-name '*.so' \
71
+			-exec basename '{}' ';' \
72
+				| xargs -r docker-php-ext-enable
73
+		make -j"$j" clean
74
+	)
75
+done
76
+
77
+if [ -e /lib/apk/db/installed ] && [ -n "$PHPIZE_DEPS" ]; then
78
+	apk del .phpize-deps
79
+fi

+ 1
- 0
docker/php-apache.ini 查看文件

@@ -0,0 +1 @@
1
+[PHP]

正在加载...
取消
保存