Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mogtofu33 committed Apr 22, 2022
1 parent 1908bfc commit cf4aafe
Show file tree
Hide file tree
Showing 37 changed files with 682 additions and 93 deletions.
94 changes: 26 additions & 68 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ default:

stages:
- build
- publish

variables:
# Drupal variables.
Expand All @@ -24,6 +23,8 @@ variables:
DRUPAL_CURRENT: '9.3'
DRUPAL_CURRENT_PHP: '8.0'
DRUPAL_NEXT: '10.0-rc'
# Specific Drupal 10 rc, remove when released.
DRUPAL_NEXT_IMAGE_TAG: '10.0'
DRUPAL_NEXT_PHP: '8.1'
# Docker variables.
DOCKER_HOST: tcp://docker:2375
Expand All @@ -35,92 +36,49 @@ variables:
value: "1"
description: Publish the image to docker, set 0 to not publish.

.scripts:
tests:
- if [[ -d ./$BUILD_DIR/tests ]]; then ./.gitlab-ci/run-tests.sh $CI_REGISTRY_IMAGE/$IMAGE; fi;

.build_test:
stage: build
script:
- echo -e "\e[0Ksection_start:`date +%s`:build[collapsed=true]\r\e[0K\e[1;34m Build $CI_REGISTRY_IMAGE/$IMAGE from $BUILD_DIR"
- docker build
--tag $CI_REGISTRY_IMAGE/$IMAGE
--tag $RELEASE_IMAGE/$IMAGE
--compress
--cache-from $CI_REGISTRY_IMAGE/$IMAGE
--build-arg BUILDKIT_INLINE_CACHE=1
$BUILD_DIR
- echo -e "\e[0Ksection_end:`date +%s`:build\r\e[0K"
- docker images
- docker push --quiet $CI_REGISTRY_IMAGE/$IMAGE
- !reference [.scripts, tests]

# .publish:
# stage: publish
# rules:
# - if: '$DO_RELEASE == "1"'
# when: on_success
# - when: never
# script:
# # Tag and push to target registry.
# - docker tag $CI_REGISTRY_IMAGE/$IMAGE $RELEASE_IMAGE/$IMAGE
# - docker images
# # Login to Docker hub, tag and push.
# - |
# echo -e "\e[0Ksection_start:`date +%s`:release[collapsed=true]\r\e[0K\e[1;34m Push $RELEASE_IMAGE/$IMAGE to $RELEASE_REGISTRY with user $RELEASE_USER"
# echo "$RELEASE_PASSWORD" | docker login $RELEASE_REGISTRY --username $RELEASE_USER --password-stdin
# docker push $RELEASE_IMAGE/$IMAGE
# echo -e "\e[0Ksection_end:`date +%s`:release\r\e[0K"

# previous:
# extends: .build_test
# variables:
# IMAGE_BASE: drupal:${DRUPAL_PREVIOUS}-php${DRUPAL_PREVIOUS_PHP}
# IMAGE: drupal-ci:${CI_COMMIT_BRANCH}-${DRUPAL_PREVIOUS}
# BUILD_DIR: '${DRUPAL_PREVIOUS}'
- if [[ -d ./$BUILD_DIR/tests ]]; then ./.gitlab-ci/run-tests.sh $CI_REGISTRY_IMAGE/$IMAGE; fi;
# Login to Docker hub and push.
- echo "$RELEASE_PASSWORD" | docker login $RELEASE_REGISTRY --username $RELEASE_USER --password-stdin
- docker push --quiet $RELEASE_IMAGE/$IMAGE

# previous_publish:
# extends: .publish
# variables:
# IMAGE_BASE: drupal:${DRUPAL_PREVIOUS}-php${DRUPAL_PREVIOUS_PHP}
# IMAGE: drupal-ci:${CI_COMMIT_BRANCH}-${DRUPAL_PREVIOUS}
prev-9-2:
extends: .build_test
variables:
IMAGE_BASE: drupal:${DRUPAL_PREVIOUS}-php${DRUPAL_PREVIOUS_PHP}
IMAGE: drupal-ci:${CI_COMMIT_BRANCH}-${DRUPAL_PREVIOUS}
BUILD_DIR: '${DRUPAL_PREVIOUS}'

current:
cur-9-3:
extends: .build_test
variables:
IMAGE_BASE: drupal:${DRUPAL_CURRENT}-php${DRUPAL_CURRENT_PHP}
IMAGE: drupal-ci:${CI_COMMIT_BRANCH}-${DRUPAL_CURRENT}
BUILD_DIR: '${DRUPAL_CURRENT}'

# current_publish:
# extends: .publish
# variables:
# IMAGE_BASE: drupal:${DRUPAL_CURRENT}-php${DRUPAL_CURRENT_PHP}
# IMAGE: drupal-ci:${CI_COMMIT_BRANCH}-${DRUPAL_CURRENT}

# next:
# extends: .build_test
# variables:
# IMAGE_BASE: drupal:${DRUPAL_NEXT}-php${DRUPAL_NEXT_PHP}
# IMAGE: drupal-ci:${CI_COMMIT_BRANCH}-10.0
# BUILD_DIR: '${DRUPAL_NEXT}'

# next_publish:
# extends: .publish
# variables:
# IMAGE_BASE: drupal:${DRUPAL_NEXT}-php${DRUPAL_NEXT_PHP}
# IMAGE: drupal-ci:${CI_COMMIT_BRANCH}-10.0

# chrome-headless:
# extends: .build_test
# variables:
# IMAGE_BASE: debian:bullseye-slim
# IMAGE: chrome-headless:${CI_COMMIT_BRANCH}
# BUILD_DIR: chrome-headless
# NO_TESTS: 1
next-10:
extends: .build_test
variables:
IMAGE_BASE: drupal:${DRUPAL_NEXT}-php${DRUPAL_NEXT_PHP}
IMAGE: drupal-ci:${CI_COMMIT_BRANCH}-${DRUPAL_NEXT_IMAGE_TAG}
BUILD_DIR: '${DRUPAL_NEXT}'

# chrome-headless_publish:
# extends: .publish
# variables:
# IMAGE_BASE: debian:bullseye-slim
# IMAGE: chrome-headless:${CI_COMMIT_BRANCH}
# NO_TESTS: 1
chrome-headless:
extends: .build_test
variables:
IMAGE_BASE: debian:bullseye-slim
IMAGE: chrome-headless:${CI_COMMIT_BRANCH}
BUILD_DIR: chrome-headless
113 changes: 113 additions & 0 deletions 10.0-rc/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# https://github.com/docker-library/drupal/blob/master/10.0-rc/php8.1/apache-buster/Dockerfile
FROM drupal:10.0-rc-php8.1

LABEL maintainer="dev-drupal.com"
LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.name="gitlab-ci-drupal/drupal-ci-images"
LABEL org.label-schema.description="Drupal CI images for project https://gitlab.com/mog33/gitlab-ci-drupal"
LABEL org.label-schema.url="https://mog33.gitlab.io/gitlab-ci-drupal"
LABEL org.label-schema.vcs-url="https://gitlab.com/gitlab-ci-drupal/drupal-ci-images"
LABEL org.label-schema.vendor="dev-drupal.com"

# Install needed programs.
RUN apt-get update && apt-get install --no-install-recommends -y \
apt-transport-https \
bc \
ca-certificates \
curl \
gettext-base \
git \
gnupg2 \
jq \
software-properties-common \
ssh \
sudo \
unzip \
vim \
xsltproc \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

#==================
# Install Nodejs, Yarn.
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash - \
&& curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update && apt-get install --no-install-recommends -y \
nodejs \
yarn \
# Required for Drush sql commands.
mariadb-client \
postgresql-client \
# Install PHP extensions.
libicu-dev \
imagemagick \
libmagickwand-dev \
libnss3-dev \
libssl-dev \
libxslt-dev \
# https://github.com/mlocati/docker-php-extension-installer
&& docker-php-ext-install intl xsl mysqli bcmath calendar sockets pcntl opcache exif ftp \
&& pecl channel-update pecl.php.net && pecl install imagick xdebug \
&& docker-php-ext-enable imagick xdebug \
# Cleanup.
&& docker-php-source delete \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

#==================
# Install composer third party.
RUN /usr/local/bin/composer selfupdate
COPY --chown=www-data:www-data composer.json /var/www/.composer/composer.json

USER www-data

# Manage Composer.
WORKDIR /var/www/.composer

# Install our tools, see composer.json
RUN COMPOSER_MEMORY_LIMIT=-1 composer install -n \
&& composer clear-cache

WORKDIR /opt/drupal

USER root

#==================
# Install Drupal core:dev, Drush for a module.
# @todo remove phpspec/prophecy-phpunit when Drupal 9 is deprecated.
RUN COMPOSER_MEMORY_LIMIT=-1 \
composer require -n --dev --working-dir="/opt/drupal" \
"drupal/core-dev:10.0.x-dev" "drush/drush:^11" "phpspec/prophecy-phpunit:^2" \
&& composer clear-cache

#==================
# Include testing code.
COPY --chown=www-data:www-data ./tests/ /tests/

#==================
# Manage final tasks.
RUN chmod 777 /var/www \
&& chown -R www-data:www-data /var/www \
# Symlink composer downloaded binaries.
&& ln -sf /var/www/.composer/vendor/bin/* /usr/local/bin \
# Phpunit 9+ cache.
&& chown www-data:www-data /opt/drupal/web/core \
# Tests scripts.
&& chmod +x /tests/*.sh \
# Fix Php performances.
&& mv /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini \
&& sed -i "s#memory_limit = 128M#memory_limit = 4G#g" /usr/local/etc/php/php.ini \
&& sed -i "s#max_execution_time = 30#max_execution_time = 90#g" /usr/local/etc/php/php.ini \
&& sed -i "s#;max_input_nesting_level = 64#max_input_nesting_level = 512#g" /usr/local/etc/php/php.ini \
# Convenient alias for root and www-data.
&& echo "alias ls='ls --color=auto -lAh'" >> /root/.bashrc \
&& echo "alias l='ls --color=auto -lAh'" >> /root/.bashrc \
&& echo "alias dr='drush --root=/opt/drupal/web'" >> /root/.bashrc \
&& cp /root/.bashrc /var/www/.bashrc \
&& chown www-data:www-data /var/www/.bashrc

#==================
# Stay as root becasue it's a ci image.
# For obvious security reason, this image is NOT meant to be used by any production system.
# USER www-data
24 changes: 24 additions & 0 deletions 10.0-rc/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "mog33/drupal8ci",
"description": "Packages for CI with Drupal 10.0-rc for https://gitlab.com/mog33/drupal8ci.",
"type": "project",
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"edgedesign/phpqa": "^1.25",
"consolidation/robo": "^3",
"drupal/coder": "^8.3",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"phpstan/phpstan": "^1.4",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"mglaman/phpstan-drupal": "^1.1",
"php-parallel-lint/php-parallel-lint": "^1.3"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
}
}
}
42 changes: 42 additions & 0 deletions 10.0-rc/tests/prepare-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
set -eu

_install_packages() {

if ! [ -x "$(command -v python3)" ]; then
if [ -f "/etc/alpine-release" ]; then
apk add --no-cache --no-progress --quiet python3
else
apt update && apt install -y python3
fi
fi

if ! [ -x "$(command -v pip3)" ]; then
# https://pip.pypa.io/en/stable/installing/
curl -s https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --quiet
fi

if [ -f "/etc/alpine-release" ]; then
# nettoolsis needed for infratest 'socket' using netstat.
# default one on Alpine (busybox) is a limited versions.
apk add --no-cache --no-progress --quiet net-tools
fi
}

_install_testinfra() {
if ! [ -x "$(command -v pytest)" ]; then
# https://github.com/pytest-dev/pytest-testinfra
pip3 install pytest-testinfra --quiet
fi
}

_main() {
echo -e "[notice] Install packages for tests..."
_install_packages
_install_testinfra
echo -e "[notice] Done!"
}

# Call `_main` after everything has been defined.
_main
2 changes: 2 additions & 0 deletions 10.0-rc/tests/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
console_output_style = classic
1 change: 1 addition & 0 deletions 10.0-rc/tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testinfra
27 changes: 27 additions & 0 deletions 10.0-rc/tests/test_composer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pytest

def test_composer(host):
assert host.check_output('composer -V').startswith('Composer version 2')
assert host.file("/var/www/.composer/composer.json").exists

@pytest.mark.parametrize("bin", [
("parallel-lint"),
("pdepend"),
("phpcs"),
("phploc"),
("phpmd"),
("phpmetrics"),
("phpqa"),
("phpstan"),
("robo"),
])
def test_composer_bin(host, bin):
''' Test bin exist '''
assert host.file("/var/www/.composer/vendor/bin/" + bin).exists
assert host.file("/usr/local/bin/" + bin).is_symlink
assert host.file("/usr/local/bin/" + bin).mode == 0o777

def test_phpcs_standard(host):
'''' Test phpcs standards '''
assert host.check_output('phpcs -i').__contains__('Drupal')
assert host.check_output('phpcs -i').__contains__('DrupalPractice')
8 changes: 8 additions & 0 deletions 10.0-rc/tests/test_drush.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pytest

def test_drush(host):
''' Test drush exist '''
assert host.file("/opt/drupal/vendor/bin/drush").exists
assert host.file("/opt/drupal/vendor/bin/drush").mode == 0o755
assert host.check_output("drush --version").startswith("Drush Commandline Tool")
assert host.check_output("drush --root=/opt/drupal/web status --field=drupal-version").startswith("10.0-rc")
20 changes: 20 additions & 0 deletions 10.0-rc/tests/test_packages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest

@pytest.mark.parametrize("name", [
("bash"),
("bc"),
("curl"),
("git"),
("jq"),
("gettext-base"),
("ssh"),
("xsltproc"),
("mariadb-client"),
("postgresql-client"),
("nodejs"),
("yarn"),
])
def test_packages_installed(host, name):
''' Test a minimum of required packages '''
pkg = host.package(name)
assert pkg.is_installed
13 changes: 13 additions & 0 deletions 10.0-rc/tests/test_permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest

@pytest.mark.parametrize("folder", [
("/opt/drupal/web/core"),
("/opt/drupal/web/modules"),
("/opt/drupal/web/themes"),
("/opt/drupal/web/sites"),
("/var/www"),
])
def test_permissions(host, folder):
''' Test folder permissions '''
assert host.file(folder).user == "www-data"
assert host.file(folder).group == "www-data"
Loading

0 comments on commit cf4aafe

Please sign in to comment.