Skip to content

Docker: Try updating base image to php apache and allowing multiple PHP versions#9252

Closed
oskosk wants to merge 3 commits intomasterfrom
update/docker-set-base-image-to-php-apache
Closed

Docker: Try updating base image to php apache and allowing multiple PHP versions#9252
oskosk wants to merge 3 commits intomasterfrom
update/docker-set-base-image-to-php-apache

Conversation

@oskosk
Copy link
Copy Markdown
Contributor

@oskosk oskosk commented Apr 7, 2018

Changes proposed in this Pull Request:

  • Sets base image (FROM) to depend on the php official image and an ENVIRONMENT variable DOCKER_PHP_VERSION.
  • Introduces a .env file in the root directory defining DOCKER_PHP_VERSION to be 7.0:apache.
  • Introduces the npm commans yarn docker:up:php7.0, yarn docker:up:php7.1 and yarn docker:up:php7.2

Testing instructions:

  • Check this branch
  • Run yarn docker:up. Expect your WordPress env to be running on PHP 7.2
    • Stop with yarn docker:stop.
  • Run yarn docker:up:php7.0. Expect your WordPress env to be running on PHP 7.0
    • Stop with yarn docker:stop.
  • Run yarn docker:up:php7.2. Expect your WordPress env to be running on PHP 7.2
    • Stop with yarn docker:stop.
  • Run yarn docker:up:php7.1. Expect your WordPress env to be running on PHP 7.1
    • Stop with yarn docker:stop.

Proposed changelog entry for your changes:

@oskosk oskosk force-pushed the update/docker-set-base-image-to-php-apache branch 4 times, most recently from 7e8ff06 to c5ad023 Compare April 7, 2018 14:43
@oskosk oskosk force-pushed the update/docker-set-base-image-to-php-apache branch from c5ad023 to ddae6b2 Compare April 7, 2018 14:43
build:
context: .
args:
PHP_VERSION: ${DOCKER_PHP_VERSION}
Copy link
Copy Markdown
Member

@simison simison Apr 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

@oskosk oskosk Apr 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

@oskosk oskosk Apr 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

@simison simison Apr 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah you're right. I think I didn't prepend an evn to the regular yarn docker:up either. I like your solution

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll have to install different versions of phpunit depending on php-version:

image

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.

via https://phpunit.de

@@ -1,38 +1,31 @@
FROM ubuntu:xenial
ARG PHP_VERSION=7.0-apache
FROM php:${PHP_VERSION}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, developer experience definitely is a big part of this so I wouldn't rush this in just when it technically already works.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, neither would I.

# Set the working directory for the next commands
WORKDIR /var/www/html

CMD ["/usr/local/bin/run"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@simison simison changed the title Docker: Try updating base image base image to php apache and allowing multiple PHP versions Docker: Try updating base image to php apache and allowing multiple PHP versions Apr 11, 2018
@brbrr brbrr added the Enhancement Changes to an existing feature — removing, adding, or changing parts of it label Jun 20, 2018
@stale
Copy link
Copy Markdown

stale bot commented Sep 18, 2018

This PR has been marked as stale. This happened because:

  • It has been inactive in the past 3 months.
  • It hasn’t been labeled `[Pri] Blocker`, `[Pri] High`.

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.

@stale stale bot added the [Status] Stale label Sep 18, 2018
@oskosk oskosk closed this Apr 24, 2019
@kraftbj kraftbj deleted the update/docker-set-base-image-to-php-apache branch May 24, 2019 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Docker Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] Proposal Touches WP.com Files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants