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

fix: support drupal 11 #146

Merged
merged 12 commits into from
Apr 22, 2024
30 changes: 18 additions & 12 deletions .ddev/config.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
name: DrupalPod
type: drupal10
type: drupal
docroot: web
php_version: "8.1"
php_version: "8.3"
webserver_type: nginx-fpm
xdebug_enabled: false
additional_hostnames: []
additional_fqdns: []
database:
type: mariadb
version: "10.4"
version: "10.6"
use_dns_when_possible: true
composer_version: "2"
web_environment: []
corepack_enable: false

# Key features of DDEV's config.yaml:

# name: <projectname> # Name of the project, automatically provides
# http://projectname.ddev.site and https://projectname.ddev.site

# type: <projecttype> # backdrop, craftcms, django4, drupal6/7/8/9/10, laravel, magento, magento2, php, python, shopware6, silverstripe, typo3, wordpress
# See https://ddev.readthedocs.io/en/latest/users/quickstart/ for more
# type: <projecttype> # backdrop, craftcms, django4, drupal, drupal6, drupal7, laravel, magento, magento2, php, python, shopware6, silverstripe, typo3, wordpress
# See https://ddev.readthedocs.io/en/stable/users/quickstart/ for more
# information on the different project types
# "drupal" covers recent Drupal 8+

# docroot: <relative_path> # Relative path to the directory containing index.php.

# php_version: "8.1" # PHP version to use, "5.6", "7.0", "7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3"
# php_version: "8.2" # PHP version to use, "5.6", "7.0", "7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3"

# You can explicitly specify the webimage but this
# is not recommended, as the images are often closely tied to DDEV's' behavior,
Expand All @@ -34,7 +36,7 @@ web_environment: []

# database:
# type: <dbtype> # mysql, mariadb, postgres
# version: <version> # database version, like "10.4" or "8.0"
# version: <version> # database version, like "10.11" or "8.0"
# MariaDB versions can be 5.5-10.8 and 10.11, MySQL versions can be 5.5-8.0
# PostgreSQL versions can be 9-16.

Expand Down Expand Up @@ -75,7 +77,7 @@ web_environment: []
# Alternatively, an explicit Composer version may be specified, for example "2.2.18".
# To reinstall Composer after the image was built, run "ddev debug refresh".

# nodejs_version: "18"
# nodejs_version: "20"
# change from the default system Node.js version to any other version.
# Numeric version numbers can be complete (i.e. 18.15.0) or
# incomplete (18, 17.2, 16). 'lts' and 'latest' can be used as well along with
Expand All @@ -84,6 +86,9 @@ web_environment: []
# Note that you can continue using 'ddev nvm' or nvm inside the web container
# to change the project's installed node version if you need to.

# corepack_enable: false
# Change to 'true' to 'corepack enable' and gain access to latest versions of yarn/pnpm

# additional_hostnames:
# - somename
# - someothername
Expand Down Expand Up @@ -141,8 +146,8 @@ web_environment: []
# - "mutagen": enables Mutagen for this project.
# - "nfs": enables NFS for this project.
#
# See https://ddev.readthedocs.io/en/latest/users/install/performance/#nfs
# See https://ddev.readthedocs.io/en/latest/users/install/performance/#mutagen
# See https://ddev.readthedocs.io/en/stable/users/install/performance/#nfs
# See https://ddev.readthedocs.io/en/stable/users/install/performance/#mutagen

# fail_on_hook_fail: False
# Decide whether 'ddev start' should be interrupted by a failing hook
Expand Down Expand Up @@ -274,5 +279,6 @@ web_environment: []
# for them. Example:
#hooks:
# post-import-db:
# - exec: drush cr
# - exec: drush updb
# - exec: drush sql:sanitize
# - exec: drush updatedb
# - exec: drush cache:rebuild
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ src/**/out/
src/**/*.vsix
src/**/.vscode-test/
drush/
.ddev/config.gitpod.yaml
21 changes: 1 addition & 20 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
image: drupalpod/drupalpod-gitpod-base:20231222
image: drupalpod/drupalpod-gitpod-base:20240419

# DDEV and composer are running as part of the prebuild
# when starting a workspace all docker images are ready
Expand Down Expand Up @@ -76,22 +76,3 @@ ports:
name: xdebug
description: xdebug
onOpen: ignore

github:
prebuilds:
# enable for the master/default branch (defaults to true)
master: true
# enable for all branches in this repo (defaults to false)
branches: true
# enable for pull requests coming from this repo (defaults to true)
pullRequests: true
# enable for pull requests coming from forks (defaults to false)
pullRequestsFromForks: false
# add a check to pull requests (defaults to true)
addCheck: true
# add a "Review in Gitpod" button as a comment to pull requests (defaults to false)
addComment: false
# add a "Review in Gitpod" button to the pull request's description (defaults to false)
addBadge: true
# add a label once the prebuild is ready to pull requests (defaults to false)
addLabel: true
2 changes: 2 additions & 0 deletions .gitpod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

1. Update `.gitpod/images/Dockerfile`:

1. Update `ddev` latest version.
1. Update `minio` latest version.
1. Update `gitui` latest version.
1. Update `lazygit` latest version.

1. Generate new custom docker image:

Expand Down
8 changes: 7 additions & 1 deletion .gitpod/drupal/drupalpod-setup/drupal_setup_core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ cd "${GITPOD_REPO_ROOT}" &&
# Removing the conflict part of composer
echo "$(cat composer.json | jq 'del(.conflict)' --indent 4)" >composer.json

# If a core issue branch was chosen, we want the version of Drupal core that is in that issue branch
# This is very helpful for issues that started with previous Drupal core versions, and the issue version automatically got updated to latest current drupal version
if [ "$DP_PROJECT_TYPE" == "project_core" ] && [ -n "$DP_ISSUE_BRANCH" ]; then
time composer require drupal/core-recommended:* drupal/core-project-message:* drupal/core-composer-scaffold:* --no-update
fi

# Only after composer update, /web/core get symlinked to /repos/drupal/core
# repos/drupal/core -> web/core
time composer update --lock
time composer update

# vendor -> repos/drupal/vendor
if [ ! -L "$GITPOD_REPO_ROOT"/repos/drupal/vendor ]; then
Expand Down
4 changes: 2 additions & 2 deletions .gitpod/drupal/drupalpod-setup/drupal_version_specifics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ fi
# Adding support for composer-drupal-lenient - https://packagist.org/packages/mglaman/composer-drupal-lenient
if [[ "$DP_CORE_VERSION" =~ ^11(\..*)?$ ]]; then
# admin_toolbar and devel are not compatible yet with Drupal 11
DP_EXTRA_ADMIN_TOOLBAR=
DP_EXTRA_DEVEL=
export DP_EXTRA_ADMIN_TOOLBAR=
export DP_EXTRA_DEVEL=
if [ "$DP_PROJECT_TYPE" != "project_core" ]; then
export COMPOSER_DRUPAL_LENIENT=mglaman/composer-drupal-lenient
else
Expand Down
24 changes: 24 additions & 0 deletions .gitpod/drupal/drupalpod-setup/drupalpod-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@ if [ -n "$DEBUG_SCRIPT" ] || [ -n "$GITPOD_HEADLESS" ]; then
set -x
fi

convert_version() {
local version=$1
if [[ $version =~ "-" ]]; then
# Remove the part after the dash and replace the last numeric segment with 'x'
local base_version=${version%-*}
echo "${base_version%.*}.x"
else
echo "$version"
fi
}

# Test cases
# echo $(convert_version "9.2.5-dev1") # Output: 9.2.x
# echo $(convert_version "9.2.5") # Output: 9.2.5
# echo $(convert_version "10.1.0-beta1") # Output: 10.1.x
# echo $(convert_version "11.0-dev") # Output: 11.x

# If this is an issue fork of Drupal core - set the drupal core version based on that issue fork
if [ "$DP_PROJECT_TYPE" == "project_core" ] && [ -n "$DP_ISSUE_FORK" ]; then
VERSION_FROM_GIT=$(grep 'const VERSION' repos/drupal/core/lib/Drupal.php | awk -F "'" '{print $2}')
DP_CORE_VERSION=$(convert_version "$VERSION_FROM_GIT")
export DP_CORE_VERSION
fi

time ddev start

# Measure the time it takes to go through the script
Expand Down
8 changes: 5 additions & 3 deletions .gitpod/drupal/drupalpod-setup/setup_env.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env bash

# Set the default setup during prebuild process
if [ -n "$GITPOD_HEADLESS" ]; then
# Set a default setup if project type wasn't specified
if [ -z "$DP_PROJECT_TYPE" ]; then
export DP_INSTALL_PROFILE='demo_umami'
export DP_PROJECT_TYPE='project_core'
export DP_PROJECT_NAME="drupal"
export DP_CORE_VERSION='10.2.5'
export DP_EXTRA_DEVEL=1
export DP_EXTRA_ADMIN_TOOLBAR=1
export DP_PROJECT_TYPE='default_drupalpod'
fi
23 changes: 19 additions & 4 deletions .gitpod/images/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,35 @@ RUN sudo apt-get -qq install -y dialog

# Install DDEV
USER gitpod
# Add DDEV’s GPG key to your keyring
RUN sudo sh -c 'echo ""'
RUN sudo install -m 0755 -d /etc/apt/keyrings
RUN curl -fsSL https://pkg.ddev.com/apt/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/ddev.gpg > /dev/null
RUN sudo chmod a+r /etc/apt/keyrings/ddev.gpg

# Add DDEV releases to your package repository
RUN sudo sh -c 'echo ""'
RUN echo "deb [signed-by=/etc/apt/keyrings/ddev.gpg] https://pkg.ddev.com/apt/ * *" | sudo tee /etc/apt/sources.list.d/ddev.list >/dev/null

Comment on lines +11 to +20
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid using sudo in Dockerfiles to enhance security.

Using sudo in Dockerfiles can lead to potential security vulnerabilities and configuration errors. Consider running these commands as a non-root user or ensuring that the user context is appropriately managed without sudo.

# Update package information and install DDEV
RUN sudo sh -c 'echo ""'
RUN sudo apt update && sudo apt install -y ddev

# Install GitUI (terminal-ui for git)
RUN wget https://github.com/extrawurst/gitui/releases/download/v0.24.3/gitui-linux-musl.tar.gz -P /tmp
RUN sudo tar xzf /tmp/gitui-linux-musl.tar.gz -C /usr/bin
ARG GITUI_VERSION=v0.26.1
RUN wget https://github.com/extrawurst/gitui/releases/download/${GITUI_VERSION}/gitui-linux-x86_64.tar.gz -P /tmp
RUN sudo tar xzf /tmp/gitui-linux-x86_64.tar.gz -C /usr/bin

# Install LazyGit (terminal-ui for git)
RUN wget https://github.com/jesseduffield/lazygit/releases/download/v0.41.0/lazygit_0.41.0_Linux_x86_64.tar.gz -P /tmp
RUN tar -C /tmp -xf /tmp/lazygit_0.41.0_Linux_x86_64.tar.gz
RUN sudo install /tmp/lazygit /usr/local/bin

# (get latest Minio version from https://dl.min.io/client/mc/release/linux-amd64/)
# Install Minio client
RUN wget https://dl.min.io/client/mc/release/linux-amd64/mcli_20231220071422.0.0_amd64.deb
RUN sudo dpkg -i mcli_20231220071422.0.0_amd64.deb
ARG MINIO_CLIENT_VERSION=mcli_20240418164529.0.0_amd64.deb
RUN wget https://dl.min.io/client/mc/release/linux-amd64/${MINIO_CLIENT_VERSION}
RUN sudo dpkg -i ${MINIO_CLIENT_VERSION}
RUN sudo mv /usr/local/bin/mcli /usr/local/bin/mc

# End workspace-base
Expand Down
26 changes: 22 additions & 4 deletions .gitpod/utils/ddev-in-gitpod-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,28 @@ if [ -n "$DEBUG_SCRIPT" ] || [ -n "$GITPOD_HEADLESS" ]; then
set -x
fi

# Set the default PHP version to 8.1
if [ -z "$DP_PHP_VERSION" ]; then
DP_PHP_VERSION="8.1"
# If this is an issue fork of Drupal core - set the drupal core version based on that issue fork
if [ "$DP_PROJECT_TYPE" == "project_core" ] && [ -n "$DP_ISSUE_FORK" ]; then
DRUPAL_CORE_VERSION=$(grep 'const VERSION' repos/drupal/core/lib/Drupal.php | awk -F "'" '{print $2}')
else
DRUPAL_CORE_VERSION=$DP_CORE_VERSION
fi

# set PHP version, based on https://www.drupal.org/docs/getting-started/system-requirements/php-requirements#versions
major_version=$(echo $DRUPAL_CORE_VERSION | cut -d '.' -f 1)
minor_version=$(echo $DRUPAL_CORE_VERSION | cut -d '.' -f 2)

# Before Drupal 10.2, we should use php 8.2, otherwise use php 8.3
if (( major_version < 10 )) || { (( major_version == 10 )) && (( minor_version < 2 )); }; then
php_version="8.2"
Copy link
Contributor

Choose a reason for hiding this comment

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

The php_version seems to always get set to 8.2 when I launch with https://gitpod.io/#DP_PROJECT_NAME=drupal,DP_ISSUE_FORK=,DP_ISSUE_BRANCH=,DP_PROJECT_TYPE=project_core,DP_MODULE_VERSION=10.2.x,DP_CORE_VERSION=11.x,DP_PATCH_FILE=,DP_INSTALL_PROFILE='standard'/https://github.com/shaal/DrupalPod/tree/issue/NT-Drupal11-update or https://gitpod.io/#DP_PROJECT_NAME=drupal,DP_ISSUE_FORK=,DP_ISSUE_BRANCH=,DP_PROJECT_TYPE=project_core,DP_MODULE_VERSION=11.x,DP_CORE_VERSION=11.x,DP_PATCH_FILE=,DP_INSTALL_PROFILE='standard'/https://github.com/shaal/DrupalPod/tree/issue/NT-Drupal11-update maybe because drupal core has not been checked out to DP_CORE_VERSION yet?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess https://gitpod.io/#DP_PROJECT_NAME=drupal,DP_PROJECT_TYPE=project_core,DP_MODULE_VERSION=11.x,DP_CORE_VERSION=11.x,DP_PATCH_FILE=,DP_INSTALL_PROFILE='standard'/https://github.com/shaal/DrupalPod/tree/issue/NT-Drupal11-update should work.

I think that maybe then the condition on line 6 should check emptiness of DP_ISSUE_FORK.

Copy link
Contributor

@mradcliffe mradcliffe Apr 19, 2024

Choose a reason for hiding this comment

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

I stand corrected, it still chose 8.2 rather than 8.3.

So I think we should not rely on the codebase checkout because it hasn't happened yet?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or maybe if DP_CORE_VERSION does not match what is currently checked out, then ignore the current checkout for this script since it's an init script?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please see the Drupal 11 quickstart. If you ddev config --update it sets to php8.3. But it can obviously be done with --php-version

Copy link
Owner Author

Choose a reason for hiding this comment

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

@rfay thank you! I am trying to support multiple drupal versions in drupalpod, and I thought adding .ddev/config.gitpod.yaml based on what's needed is the easiest way, but I am open to change that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Tested Drupal core 11.x: https://gitpod.io/#DP_PROJECT_NAME=drupal,DP_ISSUE_FORK=,DP_ISSUE_BRANCH=,DP_PROJECT_TYPE=project_core,DP_MODULE_VERSION=11.x,DP_CORE_VERSION=11.x,DP_PATCH_FILE=,DP_INSTALL_PROFILE='standard'/https://github.com/shaal/DrupalPod/pull/146 - success

Tested freelinking 4.0.x using Drupal core 11.x: https://gitpod.io/#DP_PROJECT_NAME=freelinking,DP_ISSUE_FORK=,DP_ISSUE_BRANCH=,DP_PROJECT_TYPE=project_module,DP_MODULE_VERSION=4.0.x,DP_CORE_VERSION=11.x,DP_PATCH_FILE=,DP_INSTALL_PROFILE=standard/https://github.com/shaal/drupalpod/pull/146 - success

I haven't done any manual regression testing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Drupal 10.2.x issue with issue fork branch: https://gitpod.io/new/#DP_PROJECT_NAME=drupal,DP_ISSUE_FORK=drupal-3440560,DP_ISSUE_BRANCH=3440560-menu-is-created,DP_PROJECT_TYPE=project_core,DP_MODULE_VERSION=10.2.x,DP_CORE_VERSION=10.2.x,DP_PATCH_FILE=,DP_INSTALL_PROFILE=standard/https://github.com/shaal/drupalpod/pull/146 failed because composer tried to install 11.x, but couldn't, and it also chose php_version 8.3.

else
php_version="8.3"
fi

cat <<CONFIGEND > .ddev/config.gitpod.yaml
#ddev-gitpod-generated
php_version: "$php_version"
CONFIGEND

# Misc housekeeping before start
ddev config global --instrumentation-opt-in=false
ddev config global --instrumentation-opt-in=true
Loading
Loading