Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 9.0, "buster" aliases, and use "drupal/recommended-project" layout #176

Merged
merged 5 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion 7/apache/Dockerfile → 7/apache-buster/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# from https://www.drupal.org/docs/8/system-requirements/drupal-8-php-requirements
FROM php:7.4-apache-buster
# TODO switch to buster once https://github.com/docker-library/php/issues/865 is resolved in a clean way (either in the PHP image or in PHP itself)

# install the PHP extensions we need
RUN set -eux; \
Expand Down
2 changes: 1 addition & 1 deletion 7/fpm-alpine/Dockerfile → 7/fpm-alpine3.12/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# from https://www.drupal.org/docs/8/system-requirements/drupal-8-php-requirements
FROM php:7.4-fpm-alpine
FROM php:7.4-fpm-alpine3.12

# install the PHP extensions we need
# postgresql-dev is needed for https://bugs.alpinelinux.org/issues/3642
Expand Down
1 change: 0 additions & 1 deletion 7/fpm/Dockerfile → 7/fpm-buster/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# from https://www.drupal.org/docs/8/system-requirements/drupal-8-php-requirements
FROM php:7.4-fpm-buster
# TODO switch to buster once https://github.com/docker-library/php/issues/865 is resolved in a clean way (either in the PHP image or in PHP itself)

# install the PHP extensions we need
RUN set -eux; \
Expand Down
23 changes: 14 additions & 9 deletions 8.8/apache/Dockerfile → 8.8/apache-buster/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# from https://www.drupal.org/docs/8/system-requirements/drupal-8-php-requirements
FROM php:7.4-apache-buster
# TODO switch to buster once https://github.com/docker-library/php/issues/865 is resolved in a clean way (either in the PHP image or in PHP itself)

# install the PHP extensions we need
RUN set -eux; \
Expand Down Expand Up @@ -57,17 +56,23 @@ RUN { \
echo 'opcache.fast_shutdown=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini

WORKDIR /var/www/html

# https://www.drupal.org/node/3060/release
ENV DRUPAL_VERSION 8.8.8
ENV DRUPAL_MD5 c8265f0228ca0306de7b2755e4731a3d

# https://github.com/drupal/drupal/blob/9.0.1/composer.lock#L4052-L4053
COPY --from=composer:1.10 /usr/bin/composer /usr/local/bin/
RUN set -eux; \
curl -fSL "https://ftp.drupal.org/files/projects/drupal-${DRUPAL_VERSION}.tar.gz" -o drupal.tar.gz; \
echo "${DRUPAL_MD5} *drupal.tar.gz" | md5sum -c -; \
tar -xz --strip-components=1 -f drupal.tar.gz; \
rm drupal.tar.gz; \
chown -R www-data:www-data sites modules themes
export COMPOSER_HOME="$(mktemp -d)"; \
cd /var/www/; \
# composer won't install to a non-empty dir: 'Project directory "/var/www/" is not empty.'
rmdir /var/www/html; \
composer create-project --no-install "drupal/recommended-project:$DRUPAL_VERSION" ./; \
Copy link
Member

Choose a reason for hiding this comment

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

Hopefully the time period between releases to https://github.com/drupal/drupal/releases (and I guess more relevantly, new version numbers presented in the update API we're scraping) and new tags on https://github.com/drupal/recommended-project/releases is short. 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

This repository is auto-generated based on https://git.drupalcode.org/project/drupal/-/tree/8.8.x/composer%2FTemplate%2FRecommendedProject

So, I would hope this will be updated in a timely fashion on each release.

sed -i 's!web/!html/!g' composer.json; \
Copy link
Member

Choose a reason for hiding this comment

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

Should we maybe not do this for 9.0+? (I understand why we would do it for 8.x to keep backwards compatibility, but if it's the "recommended" layout, perhaps we should follow it for the new versions and update our Apache configuration instead?)

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking to always do it so that we don't have the weird transition for users where they get confused that their mount for /var/www/html/modules no longer works (https://github.com/docker-library/docs/tree/2d2443ed9d71dafa0f328b546c39f6562603ce7d/drupal#volumes)

(honestly the "recommended" layout should have some way to choose the target subdirectory)

I guess we could do both by installing to web and making html a symlink?

Copy link
Member

Choose a reason for hiding this comment

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

Letting it install where they "recommend" and having our own symlink seems sane IMO -- gives us a good balance of following their official layout and not breaking users.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can provide it like:

composer create-project --no-install "drupal/recommended-project:$DRUPAL_VERSION"  /var/www/html

per the documentation:
https://www.drupal.org/docs/develop/using-composer/using-composer-to-install-drupal-and-manage-dependencies#s-create-a-project

Copy link
Contributor

Choose a reason for hiding this comment

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

or am I misunderstanding the problem?

Copy link
Contributor

@davidbarratt davidbarratt Aug 5, 2020

Choose a reason for hiding this comment

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

as far as I know, the "root" composer.json file is "customizable" by the user (i.e. you would not use it to load modules or themes or whatever). So I think it's fine to modify it when you build it. Personally... it seems a little gross, but better than having a symlink that I might not know about....

Copy link
Contributor

Choose a reason for hiding this comment

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

it might be weird if someone mounts the /var/www folder and expects the web subdirectory to work, but I would just document that they need to change web to html in their composer.json

Copy link
Member

Choose a reason for hiding this comment

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

What it sounds like is that we're maybe looking at the problem in the wrong way -- what if we instead install to something like /opt/drupal, and then make /var/www/html a symlink out to /opt/drupal/web? Then we get the best of both hacks, without all the weird edge cases:

  • bind mounts into /var/www/html/... will still work
  • no Apache configuration changes required
  • users can still provide all of /var/www/html or even use /opt/drupal themselves to manage (and the standard "recommended" layout will Just Work)

Maybe there's even an official upstream-recommended location for a "system" install (rather than inventing /opt/drupal ourselves)?

Copy link
Contributor

Choose a reason for hiding this comment

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

That seems reasonable to me. That means /opt/drupal will point to it's subdirectory web and /var/html wont contain the composer.json file in the first place. :)

I do not know of a system install location convention, so whatever you think is best. Is there a convention in Docker? maybe /app?

The documentation should probably be updated to use/mount /opt/drupal (and I suppose that should be the WORKDIR ?) instead of /var/www.

It would be nice if I could extend the image, and do something like:

 composer require 'drupal/paragraphs:^1.12'

and have it install the Paragraphs module as is described in the documentation:
https://www.drupal.org/project/paragraphs/releases/8.x-1.12

Copy link
Member Author

Choose a reason for hiding this comment

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

Great example usage! After some tweaks that I'll push up shorty, this will work just fine.

$ docker build -
FROM drupal:8.9-new
RUN composer require 'drupal/paragraphs:^1.12'

Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM drupal:8.9-new
 ---> 82e0b578fbc4
Step 2/2 : RUN composer require 'drupal/paragraphs:^1.12'
 ---> Running in d7ad66c57f7b
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
As there is no 'unzip' command installed zip files are being unpacked using the PHP zip extension.
This may cause invalid reports of corrupted archives. Besides, any UNIX permissions (e.g. executable) defined in the archives will be lost.
Installing 'unzip' may remediate them.
  - Installing drupal/entity_reference_revisions (1.8.0): Downloading (100%)         
  - Installing drupal/paragraphs (1.12.0): Downloading (100%)         
drupal/paragraphs suggests installing drupal/entity_browser (Recommended for an improved user experience when using the Paragraphs library module)
Writing lock file
Generating autoload files
23 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
Removing intermediate container d7ad66c57f7b
 ---> fc0923aa982b
Successfully built fc0923aa982b

composer install; \
yosifkit marked this conversation as resolved.
Show resolved Hide resolved
cd html; \
chown -R www-data:www-data sites modules themes; \
# delete composer cache
rm -rf "$COMPOSER_HOME"

WORKDIR /var/www/html
yosifkit marked this conversation as resolved.
Show resolved Hide resolved
# vim:set ft=dockerfile:
24 changes: 15 additions & 9 deletions 8.8/fpm-alpine/Dockerfile → 8.8/fpm-alpine3.12/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# from https://www.drupal.org/docs/8/system-requirements/drupal-8-php-requirements
FROM php:7.4-fpm-alpine
FROM php:7.4-fpm-alpine3.12

# install the PHP extensions we need
# postgresql-dev is needed for https://bugs.alpinelinux.org/issues/3642
Expand Down Expand Up @@ -46,17 +46,23 @@ RUN { \
echo 'opcache.fast_shutdown=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini

WORKDIR /var/www/html

# https://www.drupal.org/node/3060/release
ENV DRUPAL_VERSION 8.8.8
ENV DRUPAL_MD5 c8265f0228ca0306de7b2755e4731a3d

# https://github.com/drupal/drupal/blob/9.0.1/composer.lock#L4052-L4053
COPY --from=composer:1.10 /usr/bin/composer /usr/local/bin/
RUN set -eux; \
curl -fSL "https://ftp.drupal.org/files/projects/drupal-${DRUPAL_VERSION}.tar.gz" -o drupal.tar.gz; \
echo "${DRUPAL_MD5} *drupal.tar.gz" | md5sum -c -; \
tar -xz --strip-components=1 -f drupal.tar.gz; \
rm drupal.tar.gz; \
chown -R www-data:www-data sites modules themes
export COMPOSER_HOME="$(mktemp -d)"; \
cd /var/www/; \
# composer won't install to a non-empty dir: 'Project directory "/var/www/" is not empty.'
rmdir /var/www/html; \
composer create-project --no-install "drupal/recommended-project:$DRUPAL_VERSION" ./; \
sed -i 's!web/!html/!g' composer.json; \
composer install; \
cd html; \
chown -R www-data:www-data sites modules themes; \
# delete composer cache
rm -rf "$COMPOSER_HOME"

WORKDIR /var/www/html
# vim:set ft=dockerfile:
23 changes: 14 additions & 9 deletions 8.8/fpm/Dockerfile → 8.8/fpm-buster/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# from https://www.drupal.org/docs/8/system-requirements/drupal-8-php-requirements
FROM php:7.4-fpm-buster
# TODO switch to buster once https://github.com/docker-library/php/issues/865 is resolved in a clean way (either in the PHP image or in PHP itself)

# install the PHP extensions we need
RUN set -eux; \
Expand Down Expand Up @@ -57,17 +56,23 @@ RUN { \
echo 'opcache.fast_shutdown=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini

WORKDIR /var/www/html

# https://www.drupal.org/node/3060/release
ENV DRUPAL_VERSION 8.8.8
ENV DRUPAL_MD5 c8265f0228ca0306de7b2755e4731a3d

# https://github.com/drupal/drupal/blob/9.0.1/composer.lock#L4052-L4053
COPY --from=composer:1.10 /usr/bin/composer /usr/local/bin/
RUN set -eux; \
curl -fSL "https://ftp.drupal.org/files/projects/drupal-${DRUPAL_VERSION}.tar.gz" -o drupal.tar.gz; \
echo "${DRUPAL_MD5} *drupal.tar.gz" | md5sum -c -; \
tar -xz --strip-components=1 -f drupal.tar.gz; \
rm drupal.tar.gz; \
chown -R www-data:www-data sites modules themes
export COMPOSER_HOME="$(mktemp -d)"; \
cd /var/www/; \
# composer won't install to a non-empty dir: 'Project directory "/var/www/" is not empty.'
rmdir /var/www/html; \
composer create-project --no-install "drupal/recommended-project:$DRUPAL_VERSION" ./; \
sed -i 's!web/!html/!g' composer.json; \
composer install; \
cd html; \
chown -R www-data:www-data sites modules themes; \
# delete composer cache
rm -rf "$COMPOSER_HOME"

WORKDIR /var/www/html
# vim:set ft=dockerfile:
23 changes: 14 additions & 9 deletions 8.9/apache/Dockerfile → 8.9/apache-buster/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# from https://www.drupal.org/docs/8/system-requirements/drupal-8-php-requirements
FROM php:7.4-apache-buster
# TODO switch to buster once https://github.com/docker-library/php/issues/865 is resolved in a clean way (either in the PHP image or in PHP itself)

# install the PHP extensions we need
RUN set -eux; \
Expand Down Expand Up @@ -57,17 +56,23 @@ RUN { \
echo 'opcache.fast_shutdown=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini

WORKDIR /var/www/html

# https://www.drupal.org/node/3060/release
ENV DRUPAL_VERSION 8.9.2
ENV DRUPAL_MD5 f3f64fbef97831efd1c943f392975f45

# https://github.com/drupal/drupal/blob/9.0.1/composer.lock#L4052-L4053
COPY --from=composer:1.10 /usr/bin/composer /usr/local/bin/
RUN set -eux; \
curl -fSL "https://ftp.drupal.org/files/projects/drupal-${DRUPAL_VERSION}.tar.gz" -o drupal.tar.gz; \
echo "${DRUPAL_MD5} *drupal.tar.gz" | md5sum -c -; \
tar -xz --strip-components=1 -f drupal.tar.gz; \
rm drupal.tar.gz; \
chown -R www-data:www-data sites modules themes
export COMPOSER_HOME="$(mktemp -d)"; \
tianon marked this conversation as resolved.
Show resolved Hide resolved
cd /var/www/; \
# composer won't install to a non-empty dir: 'Project directory "/var/www/" is not empty.'
rmdir /var/www/html; \
composer create-project --no-install "drupal/recommended-project:$DRUPAL_VERSION" ./; \
sed -i 's!web/!html/!g' composer.json; \
composer install; \
cd html; \
chown -R www-data:www-data sites modules themes; \
# delete composer cache
rm -rf "$COMPOSER_HOME"

WORKDIR /var/www/html
# vim:set ft=dockerfile:
24 changes: 15 additions & 9 deletions 8.9/fpm-alpine/Dockerfile → 8.9/fpm-alpine3.12/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# from https://www.drupal.org/docs/8/system-requirements/drupal-8-php-requirements
FROM php:7.4-fpm-alpine
FROM php:7.4-fpm-alpine3.12

# install the PHP extensions we need
# postgresql-dev is needed for https://bugs.alpinelinux.org/issues/3642
Expand Down Expand Up @@ -46,17 +46,23 @@ RUN { \
echo 'opcache.fast_shutdown=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini

WORKDIR /var/www/html

# https://www.drupal.org/node/3060/release
ENV DRUPAL_VERSION 8.9.2
ENV DRUPAL_MD5 f3f64fbef97831efd1c943f392975f45

# https://github.com/drupal/drupal/blob/9.0.1/composer.lock#L4052-L4053
COPY --from=composer:1.10 /usr/bin/composer /usr/local/bin/
RUN set -eux; \
curl -fSL "https://ftp.drupal.org/files/projects/drupal-${DRUPAL_VERSION}.tar.gz" -o drupal.tar.gz; \
echo "${DRUPAL_MD5} *drupal.tar.gz" | md5sum -c -; \
tar -xz --strip-components=1 -f drupal.tar.gz; \
rm drupal.tar.gz; \
chown -R www-data:www-data sites modules themes
export COMPOSER_HOME="$(mktemp -d)"; \
cd /var/www/; \
# composer won't install to a non-empty dir: 'Project directory "/var/www/" is not empty.'
rmdir /var/www/html; \
composer create-project --no-install "drupal/recommended-project:$DRUPAL_VERSION" ./; \
sed -i 's!web/!html/!g' composer.json; \
composer install; \
cd html; \
chown -R www-data:www-data sites modules themes; \
# delete composer cache
rm -rf "$COMPOSER_HOME"

WORKDIR /var/www/html
# vim:set ft=dockerfile:
23 changes: 14 additions & 9 deletions 8.9/fpm/Dockerfile → 8.9/fpm-buster/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# from https://www.drupal.org/docs/8/system-requirements/drupal-8-php-requirements
FROM php:7.4-fpm-buster
# TODO switch to buster once https://github.com/docker-library/php/issues/865 is resolved in a clean way (either in the PHP image or in PHP itself)

# install the PHP extensions we need
RUN set -eux; \
Expand Down Expand Up @@ -57,17 +56,23 @@ RUN { \
echo 'opcache.fast_shutdown=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini

WORKDIR /var/www/html

# https://www.drupal.org/node/3060/release
ENV DRUPAL_VERSION 8.9.2
ENV DRUPAL_MD5 f3f64fbef97831efd1c943f392975f45

# https://github.com/drupal/drupal/blob/9.0.1/composer.lock#L4052-L4053
COPY --from=composer:1.10 /usr/bin/composer /usr/local/bin/
RUN set -eux; \
curl -fSL "https://ftp.drupal.org/files/projects/drupal-${DRUPAL_VERSION}.tar.gz" -o drupal.tar.gz; \
echo "${DRUPAL_MD5} *drupal.tar.gz" | md5sum -c -; \
tar -xz --strip-components=1 -f drupal.tar.gz; \
rm drupal.tar.gz; \
chown -R www-data:www-data sites modules themes
export COMPOSER_HOME="$(mktemp -d)"; \
cd /var/www/; \
# composer won't install to a non-empty dir: 'Project directory "/var/www/" is not empty.'
rmdir /var/www/html; \
composer create-project --no-install "drupal/recommended-project:$DRUPAL_VERSION" ./; \
sed -i 's!web/!html/!g' composer.json; \
composer install; \
cd html; \
chown -R www-data:www-data sites modules themes; \
# delete composer cache
rm -rf "$COMPOSER_HOME"

WORKDIR /var/www/html
# vim:set ft=dockerfile:
78 changes: 78 additions & 0 deletions 9.0/apache-buster/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# from https://www.drupal.org/docs/8/system-requirements/drupal-8-php-requirements
FROM php:7.4-apache-buster

# install the PHP extensions we need
RUN set -eux; \
\
if command -v a2enmod; then \
a2enmod rewrite; \
fi; \
\
savedAptMark="$(apt-mark showmanual)"; \
\
apt-get update; \
apt-get install -y --no-install-recommends \
libfreetype6-dev \
libjpeg-dev \
libpng-dev \
libpq-dev \
libzip-dev \
; \
\
docker-php-ext-configure gd \
--with-freetype \
--with-jpeg=/usr \
; \
\
docker-php-ext-install -j "$(nproc)" \
gd \
opcache \
pdo_mysql \
pdo_pgsql \
zip \
; \
\
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
apt-mark auto '.*' > /dev/null; \
apt-mark manual $savedAptMark; \
ldd "$(php -r 'echo ini_get("extension_dir");')"/*.so \
| awk '/=>/ { print $3 }' \
| sort -u \
| xargs -r dpkg-query -S \
| cut -d: -f1 \
| sort -u \
| xargs -rt apt-mark manual; \
\
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
rm -rf /var/lib/apt/lists/*

# set recommended PHP.ini settings
# see https://secure.php.net/manual/en/opcache.installation.php
RUN { \
echo 'opcache.memory_consumption=128'; \
echo 'opcache.interned_strings_buffer=8'; \
echo 'opcache.max_accelerated_files=4000'; \
echo 'opcache.revalidate_freq=60'; \
echo 'opcache.fast_shutdown=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini

# https://www.drupal.org/node/3060/release
ENV DRUPAL_VERSION 9.0.2

# https://github.com/drupal/drupal/blob/9.0.1/composer.lock#L4052-L4053
COPY --from=composer:1.10 /usr/bin/composer /usr/local/bin/
RUN set -eux; \
export COMPOSER_HOME="$(mktemp -d)"; \
cd /var/www/; \
# composer won't install to a non-empty dir: 'Project directory "/var/www/" is not empty.'
rmdir /var/www/html; \
composer create-project --no-install "drupal/recommended-project:$DRUPAL_VERSION" ./; \
sed -i 's!web/!html/!g' composer.json; \
composer install; \
cd html; \
chown -R www-data:www-data sites modules themes; \
# delete composer cache
rm -rf "$COMPOSER_HOME"

WORKDIR /var/www/html
# vim:set ft=dockerfile:
Loading