Skip to content

Commit 79d1a57

Browse files
authored
feat: add php container which contains all currently supported versions (#175)
1 parent cab90fb commit 79d1a57

4 files changed

Lines changed: 151 additions & 3 deletions

File tree

php/README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
> The docker images for running PHP Kokoro builds for Cloud repositories.
33
44
## Docker Registry
5-
This image is available at `gcr.io/cloud-devrel-kokoro-resources/php##`. You can try it out by running:
5+
The images for individual versions of PHP are available at `gcr.io/cloud-devrel-kokoro-resources/php##`.
6+
You can try them out by running:
67

78
```sh
89
$ docker run --rm -it gcr.io/cloud-devrel-kokoro-resources/php72
@@ -11,6 +12,23 @@ $ docker run --rm -it gcr.io/cloud-devrel-kokoro-resources/php74
1112
$ docker run --rm -it gcr.io/cloud-devrel-kokoro-resources/php80
1213
```
1314

15+
An image containing all [supported versions][php-version-support] of PHP is available
16+
at `gcr.io/cloud-devrel-kokoro-resources/php`. You can try it out by running"
17+
18+
```sh
19+
$ docker run --rm -it gcr.io/cloud-devrel-kokoro-resources/php
20+
```
21+
22+
When using the image, switching between versions of PHP is done using [PHPBrew][phpbrew]:
23+
24+
```sh
25+
# Switch to PHP 8.0
26+
phpbrew switch $(phpbrew list | grep 8.0)
27+
```
28+
29+
[php-version-support]: https://www.php.net/supported-versions.php
30+
[phpbrew]: https://github.com/phpbrew/phpbrew
31+
1432
## Questions
1533
Please reach out to `php-cloud@google.com` with any questions!
1634

php/cloudbuild-test.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
timeout: 14400s # 4 hours
15+
timeout: 28800s # 6 hours
1616
steps:
1717

1818
# PHP 7.2
@@ -38,3 +38,9 @@ steps:
3838
args: ['build', '-t', 'gcr.io/cloud-devrel-kokoro-resources/php80', '.']
3939
dir: 'php/php80'
4040
waitFor: ['-']
41+
42+
# PHP 7.3 / 7.4 / 8.0
43+
- name: gcr.io/cloud-builders/docker
44+
args: ['build', '-t', 'gcr.io/cloud-devrel-kokoro-resources/php', '.']
45+
dir: 'php/php'
46+
waitFor: ['-']

php/cloudbuild.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
timeout: 14400s # 4 hours
15+
timeout: 21600s # 6 hours
1616
steps:
1717

1818
# PHP 7.2
@@ -39,8 +39,15 @@ steps:
3939
dir: 'php/php80'
4040
waitFor: ['-']
4141

42+
# PHP 7.3 / 7.4 / 8.0
43+
- name: gcr.io/cloud-builders/docker
44+
args: ['build', '-t', 'gcr.io/cloud-devrel-kokoro-resources/php', '.']
45+
dir: 'php/php'
46+
waitFor: ['-']
47+
4248
images:
4349
- gcr.io/cloud-devrel-kokoro-resources/php72
4450
- gcr.io/cloud-devrel-kokoro-resources/php73
4551
- gcr.io/cloud-devrel-kokoro-resources/php74
4652
- gcr.io/cloud-devrel-kokoro-resources/php80
53+
- gcr.io/cloud-devrel-kokoro-resources/php

php/php/Dockerfile

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
FROM gcr.io/gcp-runtimes/ubuntu_18_0_4
2+
3+
ENV PHPBREW_ROOT /root/.phpbrew
4+
ENV PHPBREW_HOME /root/.phpbrew
5+
ENV PHPBREW_SET_PROMPT 1
6+
7+
# ENV DEBIAN_FRONTEND noninteractive
8+
RUN apt-get update \
9+
&& apt-get -qqy install git \
10+
&& apt-get -qqy install wget \
11+
&& apt-get -qqy install curl \
12+
&& apt-get -qqy install ant ant-contrib sqlite3 \
13+
&& apt-get -qqy install \
14+
autoconf \
15+
build-essential \
16+
libbz2-dev \
17+
libreadline-dev \
18+
libsqlite3-dev \
19+
libssl-dev \
20+
libxml2-dev \
21+
libxslt1-dev \
22+
libonig-dev \
23+
php7.2-cli \
24+
php7.2-bz2 \
25+
pkg-config \
26+
libcurl4-gnutls-dev \
27+
libzip-dev zip \
28+
libmagickwand-dev \
29+
php-imagick \
30+
jq \
31+
&& apt-get clean -y \
32+
&& apt-get autoclean -y \
33+
&& apt-get autoremove -y \
34+
&& rm -rf /var/lib/{apt,dpkg,cache,log}/ \
35+
&& rm -rf /var/lib/apt/lists/*
36+
37+
# Use a better shell
38+
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
39+
40+
# Install and initialize PHPBrew
41+
RUN mkdir -p /usr/bin/ \
42+
&& wget -q -O /usr/bin/phpbrew https://github.com/phpbrew/phpbrew/raw/master/phpbrew \
43+
&& chmod +x /usr/bin/phpbrew \
44+
&& phpbrew init \
45+
&& echo 'source $HOME/.phpbrew/bashrc' >> /root/.bashrc
46+
47+
# Install PHP 7.3
48+
RUN phpbrew install "7.3" \
49+
+default +bcmath +bz2 +calendar +cli +ctype +dom +fileinfo +filter +json \
50+
+mbregex +mbstring +mhash +pcntl +pcre +pdo +phar +posix +readline +sockets \
51+
+tokenizer +xml +curl +zip +openssl=yes +opcache +fpm +sqlite +mysql \
52+
+default +intl +gettext
53+
54+
# Install PHP 7.4
55+
RUN phpbrew install "7.4" \
56+
+default +bcmath +bz2 +calendar +cli +ctype +dom +fileinfo +filter +json \
57+
+mbregex +mbstring +mhash +pcntl +pcre +pdo +phar +posix +readline +sockets \
58+
+tokenizer +xml +curl +zip +openssl=yes +opcache +fpm +sqlite +mysql \
59+
+default +intl +gettext
60+
61+
# Install PHP 8.0
62+
RUN phpbrew install "8.0" \
63+
+default +bcmath +bz2 +calendar +cli +ctype +dom +fileinfo +filter +json \
64+
+mbregex +mbstring +mhash +pcntl +pcre +pdo +phar +posix +readline +sockets \
65+
+tokenizer +xml +curl +zip +openssl=yes +opcache +fpm +sqlite +mysql \
66+
+default +intl +gettext
67+
68+
# Install and enable Imagemagick extension for PHP 7.3, 7.4, and 8.0
69+
RUN source ~/.phpbrew/bashrc \
70+
&& phpbrew switch $(phpbrew list | grep 7.3) && phpbrew ext install imagick \
71+
&& phpbrew switch $(phpbrew list | grep 7.4) && phpbrew ext install imagick \
72+
# On PHP 8.0, Imagemagick must be compiled from src because it is not yet
73+
# available via PECL
74+
&& phpbrew switch $(phpbrew list | grep 8.0) \
75+
&& git clone https://github.com/Imagick/imagick /tmp/imagick \
76+
&& cd /tmp/imagick \
77+
&& phpize \
78+
&& ./configure \
79+
&& make \
80+
&& make install \
81+
&& phpbrew ext enable imagick
82+
83+
# Install and enable gRPC/memcache/opcache extensions for PHP 7.3, 7.4, and 8.0
84+
RUN source ~/.phpbrew/bashrc \
85+
&& phpbrew each phpbrew ext install grpc \
86+
&& phpbrew each phpbrew ext install memcache \
87+
&& phpbrew each phpbrew ext enable opcache
88+
89+
# Install composer
90+
RUN wget -q -O /usr/bin/composer https://getcomposer.org/composer.phar && chmod +x /usr/bin/composer
91+
92+
# Install Google Cloud SDK
93+
RUN curl https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz \
94+
-o ${HOME}/google-cloud-sdk.tar.gz \
95+
&& tar xzf ${HOME}/google-cloud-sdk.tar.gz -C $HOME \
96+
&& ${HOME}/google-cloud-sdk/install.sh \
97+
--usage-reporting false \
98+
--path-update false \
99+
--command-completion false \
100+
&& source ${HOME}/google-cloud-sdk/path.bash.inc
101+
102+
# Install Cloud SQL proxy
103+
RUN wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy \
104+
&& chmod +x cloud_sql_proxy \
105+
&& mv cloud_sql_proxy /usr/local/bin
106+
107+
# Make composer and gcloud bins available via the PATH variable
108+
ENV PATH="$PATH:/root/.config/composer/vendor/bin:/root/google-cloud-sdk/bin"
109+
110+
# Configure Google Cloud SDK
111+
RUN gcloud config set app/promote_by_default false && \
112+
gcloud config set disable_prompts true && \
113+
gcloud -q components install app-engine-python && \
114+
gcloud -q components update
115+
116+
# Install php-cs-fixer
117+
RUN composer global require friendsofphp/php-cs-fixer

0 commit comments

Comments
 (0)