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

feat(docker): Own the docker configuration instead of clone #474

Open
wants to merge 1 commit into
base: 1.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ jobs:
run: |
export DB_TYPE=mysql
export DB_PORT=3306
git clone --branch 10.1.x-php8.1 https://github.com/drupalwxt/docker-scaffold.git docker
# Cloned this repository so you own it
# git clone --branch 10.1.x-php8.1 https://github.com/drupalwxt/docker-scaffold.git docker
make build
docker compose -f docker-compose.ci.yml up -d
docker ps -a
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ jobs:
run: |
export DB_TYPE=mysql
export DB_PORT=3306
git clone --branch 10.1.x-php8.1 https://github.com/drupalwxt/docker-scaffold.git docker
# Cloned this repository so you own it
# git clone --branch 10.1.x-php8.1 https://github.com/drupalwxt/docker-scaffold.git docker
make build
docker compose -f docker-compose.ci.yml up -d
docker ps -a
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ ddev-cron-log.txt
**/sass/*.css

# Custom
docker
config/sync/openid_connect.client.keycloak.yml
files-private
6 changes: 6 additions & 0 deletions docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.git
LICENSE
VERSION
README.md
Changelog.md
Makefile
1 change: 1 addition & 0 deletions docker/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
1 change: 1 addition & 0 deletions docker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
27 changes: 27 additions & 0 deletions docker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# CHANGELOG

## 10.0.x

- TBD

## 9.5.x

- Instead of running `docker-compose` you must now call `docker compose`
- The default password for a Drupal install is now set to the current year
- You will need to update your symlinks to the new naming of the docker-compose files

```sh
ln -s docker/docker-compose.base.yml docker-compose.base.yml
ln -s docker/docker-compose.ci.yml docker-compose.ci.yml
ln -s docker/docker-compose.yml docker-compose.yml
```

- Please take not that docker images now using hyphens instead of underscores

> "${DOCKER_IMAGE}_cli" in the `bin` folder now is called "${DOCKER_IMAGE}-cli"

- The `settings.php` is no longer hardcoded and uses getenv for most parameters
- The $DB_TYPE environment variable now controls which database is used
- The $DB_PORT environment variable now controls which database port is used

> You can see this in use by the [WxT CI Builds](https://github.com/drupalwxt/wxt/blob/4.5.x/.github/workflows/build.yml#L36)
117 changes: 117 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# https://github.com/docker-library/drupal/blob/master/10.0/php8.1/fpm-alpine3.16/Dockerfile
FROM drupal:10.0-php8.1-fpm-alpine

ARG SSH_PRIVATE_KEY
ARG GIT_USERNAME
ARG GIT_PASSWORD

RUN apk --update add fcgi \
&& curl -o /usr/local/bin/php-fpm-healthcheck https://raw.githubusercontent.com/renatomefi/php-fpm-healthcheck/master/php-fpm-healthcheck \
&& chmod +x /usr/local/bin/php-fpm-healthcheck
COPY docker/conf/php-fpm/status.conf /usr/local/etc/php-fpm.d/

HEALTHCHECK --interval=5s --timeout=10s --start-period=5s --retries=3 CMD [ "php-fpm-healthcheck" ]

# Install additional extensions
RUN apk --update add --no-cache bash \
git \
gzip \
mysql-client \
patch \
postgresql-client \
ssmtp \
zlib-dev

COPY docker/conf/ssmtp.conf /etc/ssmtp/ssmtp.conf
RUN echo "hostname=drupalwxt.github.io" >> /etc/ssmtp/ssmtp.conf
RUN echo 'sendmail_path = "/usr/sbin/ssmtp -t"' > /usr/local/etc/php/conf.d/mail.ini
COPY docker/conf/php.ini /usr/local/etc/php/php.ini

# Install additional php extensions
RUN apk add --update --no-cache autoconf \
icu \
icu-libs \
libzip-dev \
gcc \
g++ \
make \
libffi-dev \
openssl-dev; \
\
apk add --no-cache --virtual .build-deps icu-dev; \
\
docker-php-ext-configure zip \
--with-zlib-dir=/usr; \
\
docker-php-ext-install -j "$(nproc)" \
bcmath \
intl \
zip; \
\
apk del .build-deps

COPY docker/certs/BaltimoreCyberTrustRoot.crt.pem /etc/ssl/mysql/BaltimoreCyberTrustRoot.crt.pem

# Redis
ENV PHPREDIS_VERSION 5.3.7
RUN mkdir -p /usr/src/php/ext/redis \
&& curl -L https://github.com/phpredis/phpredis/archive/$PHPREDIS_VERSION.tar.gz | tar xvz -C /usr/src/php/ext/redis --strip 1 \
&& echo 'redis' >> /usr/src/php-available-exts \
&& docker-php-ext-install redis

# Composer recommended settings
ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_VERSION 2.4.4
ENV COMPOSER_MEMORY_LIMIT -1
ENV COMPOSER_EXIT_ON_PATCH_FAILURE 1

# Check Composer
RUN curl -o /tmp/composer-setup.php https://getcomposer.org/installer; \
curl -o /tmp/composer-setup.sig https://composer.github.io/installer.sig; \
php -r "if (hash('SHA384', file_get_contents('/tmp/composer-setup.php')) !== trim(file_get_contents('/tmp/composer-setup.sig'))) { unlink('/tmp/composer-setup.php'); echo 'Invalid installer' . PHP_EOL; exit(1); }"

# Install Composer
RUN php /tmp/composer-setup.php --no-ansi \
--install-dir=/usr/local/bin \
--filename=composer \
--version=${COMPOSER_VERSION}; \
rm -rf /tmp/composer-setup.php

# Install Drupal WxT
RUN rm -f /var/www/composer.lock; \
rm -rf /root/.composer
RUN rm -rf /var/www/*
COPY scripts/ /var/www/scripts/
COPY composer.json composer.lock /var/www/
# Copy possible custom modules and custom themes
COPY html/modules/custom/ /var/www/html/modules/custom/
COPY html/themes/custom/ /var/www/html/themes/custom/
# Copy possible config/sync and other config
COPY config/ /var/www/config/
# Copy possible load.environment.php
COPY load.environment.php /var/www/

WORKDIR /var/www

RUN apk --update --no-cache add git openssh-client; \
mkdir -p /root/.ssh; echo $SSH_PRIVATE_KEY | base64 -d > /root/.ssh/id_rsa; \
chmod 700 /root/.ssh; chmod 600 /root/.ssh/id_rsa; \
ssh-keyscan github.com > /root/.ssh/known_hosts; \
composer install --prefer-dist \
--ignore-platform-reqs \
--no-interaction && \
rm -rf /root/.ssh && \
apk del openssh-client

# Permissions
WORKDIR /var/www/html
RUN chown -R www-data:www-data sites/default

# See: https://github.com/docker/docker/issues/9299
RUN echo "export TERM=xterm" >> ~/.bashrc

# Drush
RUN ln -s /var/www/vendor/drush/drush/drush /usr/local/bin/drush

# Reset Cache
RUN php -r 'opcache_reset();'
185 changes: 185 additions & 0 deletions docker/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
include .env

NAME := $(or $(BASE_IMAGE),$(BASE_IMAGE),drupalwxt/site-wxt)
VERSION := $(or $(VERSION),$(VERSION),'latest')
PLATFORM := $(shell uname -s)

DB_NAME := $(or $(DB_NAME),$(DB_NAME),'wxt')
DB_TYPE := $(or $(DB_TYPE),$(DB_TYPE),'mysql')
DB_PORT := $(or $(DB_PORT),$(DB_PORT),'3306')
PROFILE_NAME := $(or $(PROFILE_NAME),$(PROFILE_NAME),'wxt')

all: base

base:
mkdir -p config/sync html/modules/custom html/themes/custom
docker build -f docker/Dockerfile \
-t $(NAME):$(VERSION) \
--build-arg SSH_PRIVATE_KEY="$$(test -f $$HOME/.ssh/id_rsa && base64 $$HOME/.ssh/id_rsa)" \
--no-cache \
--build-arg http_proxy=$$HTTP_PROXY \
--build-arg HTTP_PROXY=$$HTTP_PROXY \
--build-arg https_proxy=$$HTTP_PROXY \
--build-arg HTTPS_PROXY=$$HTTP_PROXY \
--build-arg no_proxy=$$NO_PROXY \
--build-arg NO_PROXY=$$NO_PROXY \
--build-arg GIT_USERNAME=$(GIT_USERNAME) \
--build-arg GIT_PASSWORD=$(GIT_PASSWORD) .

behat:
./docker/bin/behat -vv -c behat.yml --colors

build: all

clean: clean_composer

clean_composer:
rm -rf html
rm -rf vendor
rm -f composer.lock
composer clear-cache

clean_docker:
rm -rf docker
git clone $(DOCKER_REPO) docker
[ "$(shell docker images -q --filter "dangling=true")" = "" ] || docker rmi -f $(shell docker images -q --filter "dangling=true")
[ "$(shell docker ps -a -q -f name=${DOCKER_NAME}_)" = "" ] || docker rm -f $(shell docker ps -a -q -f name=${DOCKER_NAME}_)
[ "$(shell docker images -q -f reference=${DOCKER_IMAGE}_*)" = "" ] || docker rmi -f $(shell docker images -q -f reference=*${DOCKER_IMAGE}_*)
[ "$(shell docker images -q -f reference=${NAME})" = "" ] || docker rmi -f $(shell docker images -q -f reference=${NAME})

clean_drupal: clean_composer composer_install docker_stop docker_start drupal_install

clean_site: clean_composer composer_install clean_docker base docker_build drupal_install
./docker/bin/drush cr

composer_install:
composer install

docker_build:
docker compose build --no-cache
docker compose up -d

docker_start:
docker compose up -d

docker_stop:
docker compose down

drupal_cs:
mkdir -p html/core/
cp docker/conf/drupal/phpcs.xml html/core/phpcs.xml
cp docker/conf/drupal/phpunit.xml html/core/phpunit.xml

drupal_install:
if [ "$(CI)" ]; then \
docker compose exec -T cli bash /var/www/docker/bin/cli drupal-first-run $(DB_NAME) $(DB_TYPE) $(DB_PORT) $(PROFILE_NAME); \
else \
docker compose exec cli bash /var/www/docker/bin/cli drupal-first-run $(DB_NAME) $(DB_TYPE) $(DB_PORT) $(PROFILE_NAME); \
fi

drupal_init:
if [ "$(CI)" ]; then \
docker compose exec -T cli bash /var/www/docker/bin/cli drupal-init $(DB_NAME) $(DB_TYPE) $(DB_PORT) $(PROFILE_NAME); \
else \
docker compose exec cli bash /var/www/docker/bin/cli drupal-init $(DB_NAME) $(DB_TYPE) $(DB_PORT) $(PROFILE_NAME); \
fi

drupal_migrate:
if [ "$(CI)" ]; then \
docker compose exec -T cli bash /var/www/docker/bin/cli drupal-migrate $(DB_NAME) $(DB_TYPE) $(DB_PORT) $(PROFILE_NAME); \
else \
docker compose exec cli bash /var/www/docker/bin/cli drupal-migrate $(DB_NAME) $(DB_TYPE) $(DB_PORT) $(PROFILE_NAME); \
fi

drupal_perm:
if [ "$(CI)" ]; then \
docker compose exec -T cli bash /var/www/docker/bin/cli drupal-perm $(DB_NAME) $(DB_TYPE) $(DB_PORT) $(PROFILE_NAME); \
else \
docker compose exec cli bash /var/www/docker/bin/cli drupal-perm $(DB_NAME) $(DB_TYPE) $(DB_PORT) $(PROFILE_NAME); \
fi

drush_archive:
./docker/bin/drush archive-dump --destination="/var/www/files_private/drupal$$(date +%Y%m%d_%H%M%S).tgz" \
--generator="Drupal"

lint:
./docker/bin/lint

# http://stackoverflow.com/questions/4219255/how-do-you-get-the-list-of-targets-in-a-makefile
list:
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs

phpcs: drupal_cs
./docker/bin/phpcs --config-set installed_paths /var/www/vendor/drupal/coder/coder_sniffer

./docker/bin/phpcs --standard=/var/www/html/core/phpcs.xml \
--extensions=php,module,inc,install,test,profile,theme \
--report=full \
--colors \
--ignore=/var/www/html/profiles/$(PROFILE_NAME)/modules/custom/wxt_test \
--ignore=*.css \
--ignore=*.txt \
--ignore=*.md \
--ignore=/var/www/html/*/custom/*/*.info.yml \
/var/www/html/modules/contrib/wxt_library \
/var/www/html/themes/contrib/wxt_bootstrap \
/var/www/html/profiles/$(PROFILE_NAME)/modules/custom

./docker/bin/phpcs --standard=/var/www/html/core/phpcs.xml \
--extensions=php,module,inc,install,test,profile,theme \
--report=full \
--colors \
--ignore=*.md \
-l \
/var/www/html/profiles/$(PROFILE_NAME)

phpunit:
./docker/bin/phpunit --colors=always \
-c /var/www/html/core/phpunit.xml \
--testsuite=kernel \
--group=$(PROFILE_NAME)

./docker/bin/phpunit --colors=always \
-c /var/www/html/core/phpunit.xml \
--testsuite=unit \
--group=$(PROFILE_NAME)

release: tag_latest
@if ! docker images $(NAME) | awk '{ print $$2 }' | grep -q -F $(VERSION); then echo "$(NAME) version $(VERSION) is not yet built. Please run 'make base'"; false; fi
docker push $(NAME)
@echo "*** Don't forget to create a tag. git tag rel-$(VERSION) && git push origin rel-$(VERSION)"

tag_latest:
docker tag -f $(NAME):$(VERSION) $(NAME):latest

test: phpcs phpunit behat

update: base
git pull origin 8.x
composer update
docker compose build --no-cache
docker compose up -d

.PHONY: \
all \
base \
behat \
build \
clean \
clean_composer \
clean_docker \
clean_site \
composer_install \
docker_build \
drupal_cs \
drupal_install \
drupal_migrate \
drush_archive \
lint \
list \
phpcs \
phpunit \
release \
tag_latest \
test \
update
Loading