Docker: Try updating base image to php apache and allowing multiple PHP versions#9252
Docker: Try updating base image to php apache and allowing multiple PHP versions#9252
Conversation
7e8ff06 to
c5ad023
Compare
c5ad023 to
ddae6b2
Compare
| build: | ||
| context: . | ||
| args: | ||
| PHP_VERSION: ${DOCKER_PHP_VERSION} |
There was a problem hiding this comment.
We could also add a default to this when env variable doesn't exist: ${DOCKER_PHP_VERSION:-7.2-apache}
— thus not needing .env file in the root folder?
There was a problem hiding this comment.
We do have a default in the Dockerfile here:
https://github.com/Automattic/jetpack/pull/9252/files#diff-ebacf6f6ae4ee68078bb16454b23247dR1
There was a problem hiding this comment.
Now that I think about it, it doesn't seem like we need the .env file at all for this thing given that the yarn docker:up:version commands will be setting the env var
There was a problem hiding this comment.
Now that I think about it, it doesn't seem like we need the
.envfile at all for this thing given that theyarn docker:up:versioncommands will be setting the env var
If you take out the .env and don't have a default defined in docker-compose.yml, you'll see a warning:
WARNING: The DOCKER_PHP_VERSION variable is not set. Defaulting to a blank string.
Things would still work but defining a default would take care of the warning:
build:
context: .
args:
PHP_VERSION: ${DOCKER_PHP_VERSION:-7.0-apache}
image: jetpack_wordpress:${DOCKER_PHP_VERSION:-7.0-apache}I wonder what happens to other docker-compose commands if PHP version change isn't persistent in .env file.
If after initial yarn docker:up:version you want to run any other command, wouldn't they pick the default PHP version and re-build the image?
There was a problem hiding this comment.
yeah you're right. I think I didn't prepend an evn to the regular yarn docker:up either. I like your solution
There was a problem hiding this comment.
Adding to this that e.g. yarn docker:clean script failed for me after playing with versions:
ERROR: Failed to remove image for service wordpress: 404 Client Error: Not Found ("No such image: jetpack_wordpress:7.0")
| @@ -46,12 +39,8 @@ RUN curl https://phar.phpunit.de/phpunit-5.7.5.phar -L -o phpunit.phar \ | |||
| && chmod +x phpunit.phar \ | |||
There was a problem hiding this comment.
We'll have to install different versions of phpunit depending on php-version:
Specifically phpunit-5.7.5 won't work with php-7.2.
Not sure if our tests support phpunit6 yet, though. I remember fiddling with them a bit to get them work some months ago.
| @@ -1,38 +1,31 @@ | |||
| FROM ubuntu:xenial | |||
| ARG PHP_VERSION=7.0-apache | |||
| FROM php:${PHP_VERSION} | |||
There was a problem hiding this comment.
What do you think if we do this here instead:
ARG PHP_VERSION=7.0
FROM php:${PHP_VERSION}-apache
...because we're not really supporting any other types of images but -apache so manually typing it in everywhere doesn't make sense?
If this would just be a version number, it would be compatible with existing configs and commands (i.e. DOCKER_PHP_VERSION=5 yarn docker:up) if we ever decide to change the way PHP gets installed.
| build: | ||
| context: . | ||
| args: | ||
| PHP_VERSION: ${DOCKER_PHP_VERSION} |
There was a problem hiding this comment.
What do you think if we drop DOCKER_ out from this?
I'd love to be able to type PHP_VERSION=5 yarn docker:up where 5 could be any version we didn't include in yarn scripts.
There was a problem hiding this comment.
Noting here also that variables modifying Docker/Docker-compose CLI all start with DOCKER_ so we shouldn't create names that can be confused with those.
| "docker:up": "yarn docker:compose up", | ||
| "docker:up:php7.2": "DOCKER_PHP_VERSION=7.2-apache yarn docker:compose up", | ||
| "docker:up:php7.1": "DOCKER_PHP_VERSION=7.1-apache yarn docker:compose up", | ||
| "docker:up:php7.0": "DOCKER_PHP_VERSION=7.0-apache yarn docker:compose up", |
There was a problem hiding this comment.
Shall we add v5 here? https://hub.docker.com/_/php/
I was exploring if it would be possible to do yarn docker:up --php=7.1 or something similar but I didn't really find a way to grab those args in a way that would work windows/linux/mac and wouldn't require adding extra node/bash scripts.
There was a problem hiding this comment.
Yeah we should. It's just that some build step was throwing an error for me with 5.6 and I was lazy to solve it at the moment.
Just wanted to get the flow of multi php working with this image and prove if it sucked or not to switch versions in this way. Not still quite sure if it's comfortable or not. It did come in handy to have it since I pushed this changes.
There was a problem hiding this comment.
Yeah, developer experience definitely is a big part of this so I wouldn't rush this in just when it technically already works.
There was a problem hiding this comment.
indeed, neither would I.
| # Set the working directory for the next commands | ||
| WORKDIR /var/www/html | ||
|
|
||
| CMD ["/usr/local/bin/run"] |
There was a problem hiding this comment.
I almost feel like having ENTRYPOINT echo "PHP: $PHP_VERSION" or something along those lines would make it clear what version of PHP I'm running each time.
|
This PR has been marked as stale. This happened because:
No further action is needed. But it's worth checking if this PR has clear testing instructions, is it up to date with master, and it is still valid. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation. |

Changes proposed in this Pull Request:
FROM) to depend on thephpofficial image and an ENVIRONMENT variableDOCKER_PHP_VERSION..envfile in the root directory definingDOCKER_PHP_VERSIONto be7.0:apache.yarn docker:up:php7.0,yarn docker:up:php7.1andyarn docker:up:php7.2Testing instructions:
yarn docker:up. Expect your WordPress env to be running on PHP 7.2yarn docker:stop.yarn docker:up:php7.0. Expect your WordPress env to be running on PHP 7.0yarn docker:stop.yarn docker:up:php7.2. Expect your WordPress env to be running on PHP 7.2yarn docker:stop.yarn docker:up:php7.1. Expect your WordPress env to be running on PHP 7.1yarn docker:stop.Proposed changelog entry for your changes: