Skip to content

Commit

Permalink
Drupal 10 symlink fix + composer-drupal-lenient (#102)
Browse files Browse the repository at this point in the history
* fix: request specific versions

* fix: run composer update to create symlink

* fix: update ddev to DDEV in comments and docs

Co-authored-by: tyler36 <7234392+tyler36@users.noreply.github.com>

* adding support for composer-drupal-lenient

Co-authored-by: tyler36 <tyler36@users.noreply.github.com>
Co-authored-by: tyler36 <7234392+tyler36@users.noreply.github.com>
  • Loading branch information
3 people committed Nov 16, 2022
1 parent 7677032 commit 636e782
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .ddev/docker-compose.ports.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Expose port 3000 of ddev's web container.
# Expose port 3000 and 5000 of DDEV's web container.
version: '3.6'
services:
web:
Expand Down
6 changes: 3 additions & 3 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
image: drupalpod/drupalpod-gitpod-base:20221021

# ddev and composer are running as part of the prebuild
# DDEV and composer are running as part of the prebuild
# when starting a workspace all docker images are ready
tasks:
- init: |
Expand Down Expand Up @@ -44,7 +44,7 @@ ports:
# Used by JS projects
- port: 3000
onOpen: ignore
# Used by ddev - local db clients
# Used by DDEV - local db clients
- port: 3306
name: Database
description: Access for local database clients
Expand All @@ -62,7 +62,7 @@ ports:
name: phpMyAdmin
description: phpMyAdmin
onOpen: ignore
# Direct-connect ddev-webserver port that is the main port
# Direct-connect DDEV-webserver port that is the main port
- port: 8080
name: website
description: website
Expand Down
2 changes: 1 addition & 1 deletion .gitpod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

1. Confirm latest setup
1. Open new workspace (it will load ready-made environments with same name as current branch).
1. Check if there are any updates (ie. ddev's default settings files).
1. Check if there are any updates (ie. DDEV's default settings files).
1. Recreate ready-made environments if needed.

1. Test various scenarios with DrupalPod browser extension
Expand Down
31 changes: 24 additions & 7 deletions .gitpod/drupal/drupalpod-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,26 @@ fi

# Check if additional modules should be installed
export DEVEL_NAME="devel"
export DEVEL_PACKAGE="drupal/devel"
export DEVEL_PACKAGE="drupal/devel:^5"

export ADMIN_TOOLBAR_NAME="admin_toolbar_tools"
export ADMIN_TOO
export ADMIN_TOOLBAR_PACKAGE="drupal/admin_toolbar:^3.1"

# TODO: once Drupalpod extension supports additional modules - remove these 2 lines
export DP_EXTRA_DEVEL=1
export DP_EXTRA_ADMIN_TOOLBAR=1

# Adding support for composer-drupal-lenient - https://packagist.org/packages/mglaman/composer-drupal-lenient
if [[ "$DP_CORE_VERSION" == 10* ]]; then
# admin_toolbar not compatible yet with Drupal 10
unset DP_EXTRA_ADMIN_TOOLBAR
if [ "$DP_PROJECT_TYPE" != "project_core" ]; then
export COMPOSER_DRUPAL_LENIENT=mglaman/composer-drupal-lenient
else
export COMPOSER_DRUPAL_LENIENT=''
fi
fi

# Use PHP 8.1 for Drupal 10.0.x
if [ -n "$DP_PHP" ] && [ "$DP_PHP" != '8.1' ]; then
# Dynamically generate .ddev/config.gitpod.yaml file
Expand Down Expand Up @@ -117,7 +128,7 @@ GITMODULESEND
fi
done

# Make sure ddev is running
# Make sure DDEV is running
ddev start

# Restoring requested environment + profile installation
Expand All @@ -139,7 +150,7 @@ GITMODULESEND
# Copying the ready-made environment of requested Drupal core version
cd "$GITPOD_REPO_ROOT" && cp -rT ../ready-made-envs/"$DP_CORE_VERSION"/. .
else
# If not, run composer create-proejct with the requested version
# If not, run composer create-project with the requested version

# For versions end with x - add `-dev` suffix (ie. 9.3.x-dev)
# For versions without x - add `~` prefix (ie. ~9.2.0)
Expand All @@ -161,7 +172,7 @@ GITMODULESEND
fi

# Check if snapshot can be used (when no full reinstall needed)
# Run it before any other ddev command (to avoid ddev restart)
# Run it before any other DDEV command (to avoid ddev restart)

if [ ! "$DP_REINSTALL" ] && [ "$DP_INSTALL_PROFILE" != "''" ]; then
if [ "$ready_made_env_exist" ]; then
Expand All @@ -185,6 +196,8 @@ GITMODULESEND
ddev composer config --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
ddev composer config --no-plugins allow-plugins.phpstan/extension-installer true

ddev composer config --no-plugins allow-plugins.mglaman/composer-drupal-lenient true

# Add project source code as symlink (to repos/name_of_project)
# double quotes explained - https://stackoverflow.com/a/1250279/5754049
if [ -n "$DP_PROJECT_NAME" ]; then
Expand Down Expand Up @@ -257,7 +270,6 @@ GITMODULESEND
if [ "$ready_made_env_exist" ]; then
cd "${GITPOD_REPO_ROOT}" && time ddev composer update
else
cd "${GITPOD_REPO_ROOT}" && time ddev composer config repositories.lenient composer https://packages.drupal.org/lenient
"${GITPOD_REPO_ROOT}"/.gitpod/drupal/install-essential-packages.sh
fi
elif [ -n "$DP_PROJECT_NAME" ]; then
Expand All @@ -282,8 +294,13 @@ PROJECTASYMLINK
echo "$(cat composer.json | jq '.scripts."post-install-cmd" |= . + ["repos/add-project-as-symlink.sh"]')" > composer.json
echo "$(cat composer.json | jq '.scripts."post-update-cmd" |= . + ["repos/add-project-as-symlink.sh"]')" > composer.json

if [ -n "$COMPOSER_DRUPAL_LENIENT" ]; then
# Add composer_drupal_lenient for modules on Drupal 10
cd "${GITPOD_REPO_ROOT}" && ddev composer config --merge --json extra.drupal-lenient.allowed-list '["drupal/'"$DP_PROJECT_NAME"'"]'
cd "${GITPOD_REPO_ROOT}" && time ddev . composer require "$COMPOSER_DRUPAL_LENIENT"
fi
# Add the project to composer (it will get the version according to the branch under `/repo/name_of_project`)
cd "${GITPOD_REPO_ROOT}" && time ddev composer require drupal/"$DP_PROJECT_NAME"
cd "${GITPOD_REPO_ROOT}" && time ddev . composer require drupal/"$DP_PROJECT_NAME"
fi

"${GITPOD_REPO_ROOT}"/.gitpod/drupal/install-essential-packages.sh
Expand Down
1 change: 1 addition & 0 deletions .gitpod/drupal/envs-prep/all-drupal-supported-versions.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
10.1.x
10.0.x
9.5.x
9.4.x
Expand Down
38 changes: 24 additions & 14 deletions .gitpod/drupal/envs-prep/create-environments.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fi
# https://console.cloud.google.com/storage/browser
echo "*** Rebuilding ready-made environments from scratch, this will take 8 minutes... (2 minutes per drupal version)"

# Stop and unlist current ddev project
# Stop and unlist current DDEV project
ddev stop --unlist drupalpod

# Empty existing ready-made-envs directory
Expand All @@ -25,10 +25,10 @@ allProfiles=(minimal standard demo_umami)

# Run through each Drupal Supported Versions - a
# Install minimal, standard and umami profiles
# Create a ddev snapshot
# Create a DDEV snapshot

for d in "${allDrupalSupportedVersions[@]}"; do
# Create ddev config
# Create DDEV config
mkdir -p "$WORK_DIR"/"$d"
cd "$WORK_DIR"/"$d" && ddev config --docroot=web --create-docroot --project-type=drupal9 --php-version=8.1 --project-name=drupalpod --database=mariadb:10.3

Expand All @@ -43,6 +43,14 @@ for d in "${allDrupalSupportedVersions[@]}"; do
;;
esac

# @todo: update when admin_toolbar becomes compatible with Drupal 10
if [[ "$d" == 10* ]]; then
unset ADMIN_TOOLBAR_PACKAGE
else
export ADMIN_TOOLBAR_NAME="admin_toolbar_tools"
export ADMIN_TOOLBAR_PACKAGE="drupal/admin_toolbar"
fi

echo "*** composer install"
cd "$WORK_DIR"/"$d" && ddev composer create -y --no-install drupal/recommended-project:"$install_version"

Expand All @@ -55,6 +63,8 @@ for d in "${allDrupalSupportedVersions[@]}"; do
ddev composer config --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
ddev composer config --no-plugins allow-plugins.phpstan/extension-installer true

ddev composer config --no-plugins allow-plugins.mglaman/composer-drupal-lenient true

# Install additional packages

rm "$WORK_DIR"/"$d"/composer.lock
Expand All @@ -63,11 +73,7 @@ for d in "${allDrupalSupportedVersions[@]}"; do
cd "$WORK_DIR"/"$d" && ddev composer require --dev phpspec/prophecy-phpunit:^2 drupal/core-dev:* -W --no-install

cd "$WORK_DIR"/"$d" && \
ddev composer require \
drupal/admin_toolbar \
drush/drush \
drupal/coder \
drupal/devel
time ddev . composer require drush/drush drupal/coder drupal/devel "$ADMIN_TOOLBAR_PACKAGE"

for p in "${allProfiles[@]}"; do
echo Building drupal-"$d"-"$p"
Expand All @@ -79,22 +85,26 @@ for d in "${allDrupalSupportedVersions[@]}"; do

echo "*** Adding extra modules"

cd "$WORK_DIR"/"$d" && \
ddev drush en -y \
admin_toolbar \
devel
# Enable extra modules
if [ -n "$ADMIN_TOOLBAR_NAME" ]; then
cd "$WORK_DIR"/"$d" && \
ddev drush en -y \
"$ADMIN_TOOLBAR_NAME"
fi

cd "$WORK_DIR"/"$d" && ddev drush en -y devel

# Enable Claro as default admin theme
echo "*** Enable Claro theme"
cd "$WORK_DIR"/"$d" && \
ddev drush then claro && \
ddev drush config-set -y system.theme admin claro

echo "*** Save a ddev snapshot"
echo "*** Save a DDEV snapshot"
cd "$WORK_DIR"/"$d" && ddev snapshot -n "$p"
done

# Stop any existing 'drupalpod' ddev project
# Stop any existing 'drupalpod' DDEV project
cd "$WORK_DIR"/"$d" && ddev stop --unlist drupalpod

done
Expand Down
3 changes: 2 additions & 1 deletion .gitpod/drupal/install-essential-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ fi

cd "${GITPOD_REPO_ROOT}" && time ddev composer require --dev drupal/core-dev:* -W --no-install
cd "${GITPOD_REPO_ROOT}" && time ddev composer require --dev phpspec/prophecy-phpunit:^2 --no-install
cd "${GITPOD_REPO_ROOT}" && time ddev composer require drush/drush:^11.0 drupal/coder:^8.3 $DEVEL_PACKAGE $ADMIN_TOOLBAR_PACKAGE
cd "${GITPOD_REPO_ROOT}" && time ddev . composer require drush/drush:^11.0 drupal/coder:^8.3 "$DEVEL_PACKAGE" "$ADMIN_TOOLBAR_PACKAGE" --no-install
cd "${GITPOD_REPO_ROOT}" && time ddev composer update
2 changes: 1 addition & 1 deletion .gitpod/images/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN sudo apt-get -qq update
# Install dialog (interactive script)
RUN sudo apt-get -qq install -y dialog

# Install ddev
# Install DDEV
USER gitpod
# RUN brew install drud/ddev/ddev
RUN wget -P /tmp https://raw.githubusercontent.com/drud/ddev/master/scripts/install_ddev.sh && bash /tmp/install_ddev.sh
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ No computer is needed because it is all running in the cloud.
## The secret sauce

* [Gitpod](https://www.gitpod.io) - development environment in the cloud
* [Ddev](https://ddev.readthedocs.io/en/stable) - easy setup for PHP projects using Docker
* [DDEV](https://ddev.readthedocs.io/en/stable) - easy setup for PHP projects using Docker
* [DrupalPod](https://chrome.google.com/webstore/detail/drupalpod-helper-extensio/pjfjhkcfkhbemnbpkakjhmboacefmjjl?hl=en
) Browser Extension
* [Drupal Core Development Project](https://github.com/joachim-n/drupal-core-development-project)
Expand Down Expand Up @@ -63,7 +63,7 @@ If SSH keys are valid, it stores your private SSH key as an environment variable
[WIP - making a friendlier interactive dialog](https://github.com/shaal/DrupalPod/issues/4).

* If you prefer working locally - you can clone this repo to your computer.\
The only 2 requirements are [Docker](https://ddev.readthedocs.io/en/stable/users/docker_installation/) and [Ddev](https://ddev.readthedocs.io/en/stable/#installation).
The only 2 requirements are [Docker](https://ddev.readthedocs.io/en/stable/users/docker_installation/) and [DDEV](https://ddev.readthedocs.io/en/stable/#installation).

<br>

Expand Down

0 comments on commit 636e782

Please sign in to comment.