Skip to content

Commit

Permalink
switched from phpdockerio/php72-fpm to official php image (in version…
Browse files Browse the repository at this point in the history
… 7.2-fpm-alpine)

- Alpine linux uses apk instead of apt-get
- default UID for user "www-data" is 82 on Alpine linux instead of 33
- there is no bash installed, use sh instead
  • Loading branch information
PetrHeinz authored and MattCzerner committed May 14, 2018
1 parent c2e767d commit 013978d
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 75 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Docker installation supported on Linux, MacOS and Windows 10 Pro and higher (recommended way of installing the application)
- native installation is also supported (recommended on Windows 10 Home and lower)
- as a rule, using minor versions of docker images (eg. `1.2` or `1.2-alpine`) if possible (@MattCzerner)
- docs and `docker-compose.yml` templates reflect [changes of Docker images in shopsys/project-base](./project-base/CHANGELOG.md) (@PetrHeinz, @MattCzerner)

### Fixed
- documentation: missing redis extension in required php extensions (@pk16011990)
Expand Down
2 changes: 1 addition & 1 deletion docker/conf/docker-compose-mac.yml.dist
Expand Up @@ -29,7 +29,7 @@ services:
working_dir: /var/www/shopsys-framework
volumes:
- shopsys-framework-sync:/var/www/shopsys-framework
- ./project-base/docker/php-fpm/php-ini-overrides.ini:/etc/php/7.1/fpm/conf.d/99-overrides.ini
- ./project-base/docker/php-fpm/php-ini-overrides.ini:/usr/local/etc/php/php.ini
links:
- postgres
- redis
Expand Down
2 changes: 1 addition & 1 deletion docker/conf/docker-compose.yml.dist
Expand Up @@ -29,7 +29,7 @@ services:
working_dir: /var/www/shopsys-framework
volumes:
- .:/var/www/shopsys-framework
- ./project-base/docker/php-fpm/php-ini-overrides.ini:/etc/php/7.1/fpm/conf.d/99-overrides.ini
- ./project-base/docker/php-fpm/php-ini-overrides.ini:/usr/local/etc/php/php.ini
links:
- postgres
- redis
Expand Down
6 changes: 3 additions & 3 deletions docs/cookbook/jenkins-configuration.md
Expand Up @@ -357,9 +357,9 @@ correct permissions for all application files.

We can use `setfacl` command, which can apply multiple permission rules onto folder and make it accessible for multiple users.
```
# Allow user with UID 33 (user "www-data" in container "php-fpm") read and write all project files
/usr/bin/docker exec $JOB_NAME-shopsys-framework-php-fpm setfacl -R -m user:33:rwX -m mask:rwX .
/usr/bin/docker exec $JOB_NAME-shopsys-framework-php-fpm setfacl -dR -m user:33:rwX -m mask:rwX .
# Allow user with UID 82 (user "www-data" in container "php-fpm") read and write all project files
/usr/bin/docker exec $JOB_NAME-shopsys-framework-php-fpm setfacl -R -m user:82:rwX -m mask:rwX .
/usr/bin/docker exec $JOB_NAME-shopsys-framework-php-fpm setfacl -dR -m user:82:rwX -m mask:rwX .
# Allow user with UID 100 (user "nginx" in container "webserver") read files in "web" directory
/usr/bin/docker exec $JOB_NAME-shopsys-framework-php-fpm setfacl -R -m user:100:rX ./project-base/web
Expand Down
2 changes: 1 addition & 1 deletion docs/docker/docker-troubleshooting.md
Expand Up @@ -83,7 +83,7 @@ Remember that after changing these you need to do few things differently.
for instance, if your new container name is `my-new-project-name-php-fpm` you need to execute

```
docker exec -it my-new-project-name-php-fpm bash
docker exec -it my-new-project-name-php-fpm sh
```

## Update of Dockerfile is not Reflected
Expand Down
Expand Up @@ -8,7 +8,7 @@ Now that the Docker environment is prepared we can setup the application itself.

### 1.1. Connect into terminal of the Docker container
```
docker exec -it shopsys-framework-php-fpm bash
docker exec -it shopsys-framework-php-fpm sh
```

### 1.2. Install dependencies and configure parameters
Expand Down
8 changes: 4 additions & 4 deletions docs/installation/installation-using-docker-linux.md
Expand Up @@ -48,13 +48,13 @@ sudo setfacl -dR -m user:`whoami`:rwX -m mask:rwX .
#### 4.2. Grant system users inside the container the required permissions
##### Connect into terminal of the Docker container
```
docker exec -it shopsys-framework-php-fpm bash
docker exec -it shopsys-framework-php-fpm sh
```

##### Allow user with UID 33 ("www-data" in "php-fpm" container) read and write all project files
##### Allow user with UID 82 ("www-data" in "php-fpm" container) read and write all project files
```
setfacl -R -m user:33:rwX -m mask:rwX .
setfacl -dR -m user:33:rwX -m mask:rwX .
setfacl -R -m user:82:rwX -m mask:rwX .
setfacl -dR -m user:82:rwX -m mask:rwX .
```

##### Allow user with UID 100 ("nginx" in "webserver" container) read files in "web" directory
Expand Down
8 changes: 4 additions & 4 deletions docs/installation/installation-using-docker-macos.md
Expand Up @@ -50,13 +50,13 @@ docker-compose up -d
Grant system users inside the container the required permissions
#### Connect into terminal of the Docker container
```
docker exec -it shopsys-framework-php-fpm bash
docker exec -it shopsys-framework-php-fpm sh
```

#### Allow user with UID 33 ("www-data" in "php-fpm" container) read and write all project files
#### Allow user with UID 82 ("www-data" in "php-fpm" container) read and write all project files
```
setfacl -R -m user:33:rwX -m mask:rwX .
setfacl -dR -m user:33:rwX -m mask:rwX .
setfacl -R -m user:82:rwX -m mask:rwX .
setfacl -dR -m user:82:rwX -m mask:rwX .
```

#### Allow user with UID 100 ("nginx" in "webserver" container) read files in "web" directory
Expand Down
2 changes: 1 addition & 1 deletion docs/introduction/running-acceptance-tests.md
Expand Up @@ -5,7 +5,7 @@ There is `selenium-server` container with installed Selenium hub and Google Chro

You should run all command mentioned below while logged into your `php-fpm` container via command:
```
docker exec -it shopsys-framework-php-fpm bash
docker exec -it shopsys-framework-php-fpm sh
```

*Note: For `selenium-server` to be able to connect to you `webserver` container and access your application, all domains should have URL set to `http://webserver:8000`.*
Expand Down
6 changes: 6 additions & 0 deletions project-base/CHANGELOG.md
Expand Up @@ -15,6 +15,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Dependency Injection strict mode is now enabled (@EdoBarnas)
- disables autowiring features that were removed in Symfony 4
- as a rule, using minor versions of docker images (eg. `1.2` or `1.2-alpine`) if possible (@MattCzerner)
- switched to Docker image `php:7.2-fpm-alpine` instead of `phpdockerio/php72-fpm:latest` (@PetrHeinz, @MattCzerner)
- official PHP Docker image is much more stable and provides tags other than `latest`
- built on Alpine linux which uses `apk` instead of `apt-get`
- in the container there is no `bash` installed, use `sh` instead
- the default UID for user `www-data` is 82 on Alpine linux instead of 33

### Removed
- support of installation using Docker for Windows 10 Home and lower (@TomasLudvik)
Expand All @@ -25,6 +30,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- see https://github.com/symfony/swiftmailer-bundle/commit/5edfbd39eaefb176922a346c16b0ae3aaeec87e0
- the new setting requires array instead of string so the parameter `mailer_master_email_address` is wrapped into array in config
- `FpJsFormValidator` error in console on FE order pages (@vitek-rostislav)
- failure during Docker image build triggered by `E: Unable to locate package postgresql-client-9.5` (@PetrHeinz, @MattCzerner)

## 7.0.0-alpha1 - 2018-04-12
- We are releasing version 7 (open-source project known as Shopsys Framework) to better distinguish it from Shopsys 6
Expand Down
2 changes: 1 addition & 1 deletion project-base/docker/conf/docker-compose-mac.yml.dist
Expand Up @@ -29,7 +29,7 @@ services:
working_dir: /var/www/shopsys-framework
volumes:
- shopsys-framework-sync:/var/www/shopsys-framework
- ./docker/php-fpm/php-ini-overrides.ini:/etc/php/7.1/fpm/conf.d/99-overrides.ini
- ./docker/php-fpm/php-ini-overrides.ini:/usr/local/etc/php/php.ini
links:
- postgres
- redis
Expand Down
2 changes: 1 addition & 1 deletion project-base/docker/conf/docker-compose.yml.dist
Expand Up @@ -29,7 +29,7 @@ services:
working_dir: /var/www/shopsys-framework
volumes:
- .:/var/www/shopsys-framework
- ./docker/php-fpm/php-ini-overrides.ini:/etc/php/7.1/fpm/conf.d/99-overrides.ini
- ./docker/php-fpm/php-ini-overrides.ini:/usr/local/etc/php/php.ini
links:
- postgres
- redis
Expand Down
103 changes: 48 additions & 55 deletions project-base/docker/php-fpm/Dockerfile
@@ -1,58 +1,51 @@
FROM phpdockerio/php72-fpm:latest

# Switch to non-interactive mode during image build to silence some warnings.
# See https://github.com/moby/moby/issues/4032
ARG DEBIAN_FRONTEND=noninteractive

# Install packages are useful when working in the container in interactive mode.
RUN apt-get update && apt-get -y install apt-utils dialog

# Install ACL support (ie. tools like "setfacl").
RUN apt-get update && apt-get -y install acl

# Install Git - it is necessary for code diffs
RUN apt-get update && apt-get -y install git
FROM php:7.2-fpm-alpine

# install git for computing diffs
RUN apk add --update git

# install Composer
COPY docker-install-composer /usr/local/bin/docker-install-composer
RUN chmod +x /usr/local/bin/docker-install-composer && docker-install-composer

# libpng-dev needed by "gd" extension
# icu-dev needed by "intl" extension
# postgresql-dev needed by "pgsql" extension
# libzip-dev needed by "zip" extension
# autoconf needed by "redis" extension
RUN apk add --update \
libpng-dev \
icu-dev \
postgresql-dev \
libzip-dev \
autoconf

# "zip" extension warns about deprecation if we do not use a system library
RUN docker-php-ext-configure zip --with-libzip

# install necessary PHP extensions requested by Composer
RUN docker-php-ext-install \
bcmath \
gd \
intl \
opcache \
pgsql \
pdo_pgsql \
zip

# redis PHP extension is not provided with the PHP source and must be installed via PECL, build-base used only for installation
RUN apk add --update build-base && pecl install redis-4.0.2 && docker-php-ext-enable redis && apk del build-base

# install npm
RUN apk add --update nodejs-npm

# install grunt-cli using npm to be able to run grunt watch
RUN npm install -g grunt-cli

# Install PostgreSQL client for dumping database
RUN apt-get update && apt-get -y install postgresql-client-9.5
# install postgresql to allow execution of pg_dump for acceptance tests (using older repository to install version 9.5)
RUN apk add --update --no-cache --repository https://dl-3.alpinelinux.org/alpine/v3.4/main "postgresql<9.6"

# Install locales and switch to en_US.utf8 in order to enable UTF-8 support.
# See https://perlgeek.de/en/article/set-up-a-clean-utf8-environment
RUN apt-get update && apt-get -y install locales-all
# install locales and switch to en_US.utf8 in order to enable UTF-8 support
# see https://github.com/docker-library/php/issues/240#issuecomment-305038173
RUN apk add --update --no-cache --repository https://dl-3.alpinelinux.org/alpine/edge/testing gnu-libiconv
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php
ENV LC_ALL=en_US.utf8 LANG=en_US.utf8 LANGUAGE=en_US.utf8

# Install required PHP extensions
RUN apt-get update && apt-get -y --no-install-recommends install \
php7.2-bcmath \
php7.2-ctype \
php7.2-curl \
php7.2-fpm \
php7.2-gd \
php7.2-iconv \
php7.2-intl \
php7.2-json \
php7.2-mbstring \
php7.2-opcache \
php7.2-pdo \
php7.2-pgsql \
php7.2-redis \
php7.2-simplexml \
php7.2-soap \
php7.2-xml \
php7.2-zip

# Install Composer
RUN php -r "copy('https://getcomposer.org/download/1.5.1/composer.phar', '/usr/local/bin/composer');" \
&& php -r "if (hash_file('SHA384', '/usr/local/bin/composer') === 'fd3800adeff12dde28e9238d2bb82ba6f887bc6d718eee3e3a5d4f70685a236b9e96afd01aeb0dbab8ae6211caeb1cbe') {echo 'Composer installed';} else {echo 'Hash invalid for downloaded composer.phar'; exit(1);}" \
&& chmod 0755 /usr/local/bin/composer \
&& /usr/local/bin/composer selfupdate --stable

# Install Node.js v6 from NodeSource repository that also contains NPM.
# See https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - \
&& apt-get update && apt-get -y install nodejs=6.*

# Install grunt-cli using npm to be able to run grunt watch.
RUN npm install -g grunt-cli

WORKDIR "/var/www/shopsys-framework"
20 changes: 20 additions & 0 deletions project-base/docker/php-fpm/docker-install-composer
@@ -0,0 +1,20 @@
#!/bin/sh

# copied from https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md
# option --filename=composer is used so it can be called without the .phar extension

EXPECTED_SIGNATURE="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE="$(php -r "echo hash_file('SHA384', 'composer-setup.php');")"

if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
then
>&2 echo 'ERROR: Invalid installer signature'
rm composer-setup.php
exit 1
fi

php composer-setup.php --quiet --install-dir=/usr/local/bin --filename=composer
RESULT=$?
rm composer-setup.php
exit $RESULT
4 changes: 2 additions & 2 deletions project-base/docker/php-fpm/php-ini-overrides.ini
@@ -1,5 +1,5 @@
date.timezone = ${TIMEZONE}
memory_limit = 256M;
memory_limit = 512M;

; do not allow <?
short_open_tag = Off
Expand Down Expand Up @@ -33,4 +33,4 @@ opcache.revalidate_path=1

; nescessary for file uploads
upload_max_filesize = 32M
post_max_size = 32M
post_max_size = 32M

0 comments on commit 013978d

Please sign in to comment.