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

devops improvement: Don't add command warning to standard output. #150

Open
wants to merge 6 commits into
base: main
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
54 changes: 36 additions & 18 deletions .ddev/config.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +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: []
nodejs_version: "18"
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> # drupal6/7/8, backdrop, typo3, wordpress, php
# 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 @@ -33,9 +36,9 @@ nodejs_version: "18"

# 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-15.
# PostgreSQL versions can be 9-16.

# router_http_port: <port> # Port to be used for http (defaults to global configuration, usually 80)
# router_https_port: <port> # Port for https (defaults to global configuration, usually 443)
Expand Down Expand Up @@ -74,10 +77,17 @@ nodejs_version: "18"
# 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"
# change from the default system Node.js version to another supported version, like 14, 16, 18, 20.
# Note that you can use 'ddev nvm' or nvm inside the web container to provide nearly any
# Node.js version, including v6, etc.
# 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
# other named releases.
# see https://www.npmjs.com/package/n#specifying-nodejs-versions
# 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
Expand Down Expand Up @@ -105,6 +115,13 @@ nodejs_version: "18"
# If true, turns off the normal warning that says
# "You have Mutagen enabled and your 'php' project type doesn't have upload_dirs set"

# ddev_version_constraint: ""
# Example:
# ddev_version_constraint: ">= 1.22.4"
# This will enforce that the running ddev version is within this constraint.
# See https://github.com/Masterminds/semver#checking-version-constraints for
# supported constraint formats

# working_dir:
# web: /var/www/html
# db: /home
Expand All @@ -129,8 +146,8 @@ nodejs_version: "18"
# - "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 @@ -241,10 +258,10 @@ nodejs_version: "18"
# override_config: false
# By default, config.*.yaml files are *merged* into the configuration
# But this means that some things can't be overridden
# For example, if you have 'nfs_mount_enabled: true'' you can't override it with a merge
# For example, if you have 'use_dns_when_possible: true'' you can't override it with a merge
# and you can't erase existing hooks or all environment variables.
# However, with "override_config: true" in a particular config.*.yaml file,
# 'nfs_mount_enabled: false' can override the existing values, and
# 'use_dns_when_possible: false' can override the existing values, and
# hooks:
# post-start: []
# or
Expand All @@ -262,5 +279,6 @@ nodejs_version: "18"
# for them. Example:
#hooks:
# post-import-db:
# - exec: drush cr
# - exec: drush updb
# - exec: drush sql:sanitize
# - exec: drush updatedb
# - exec: drush cache:rebuild
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ src/**/package-lock.json
src/**/out/
src/**/*.vsix
src/**/.vscode-test/
drush/
.ddev/config.gitpod.yaml
22 changes: 1 addition & 21 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
image: drupalpod/drupalpod-gitpod-base:20230922
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 All @@ -7,7 +7,6 @@ tasks:
.gitpod/utils/send-a-message-gcs.sh > /tmp/output1.txt
.gitpod/utils/ddev-in-gitpod-setup.sh
.gitpod/utils/set-base-environment.sh
time ddev start
command: |
# Temporary fix for wrong value of GITPOD_REPO_ROOT when opening a Gitpod snapshot
# Todo: remove this when this issue is resolved - https://github.com/gitpod-io/gitpod/issues/9804
Expand Down Expand Up @@ -76,22 +75,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: 8 additions & 0 deletions .gitpod/drupal/drupalpod-setup/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -eu -o pipefail

# Remove site that was installed before (for debugging)
rm -rf "${GITPOD_REPO_ROOT}"/web
rm -rf "${GITPOD_REPO_ROOT}"/vendor
rm -f "${GITPOD_REPO_ROOT}"/composer.json
rm -f "${GITPOD_REPO_ROOT}"/composer.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
#!/usr/bin/env bash
set -eu -o pipefail

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

export ADMIN_TOOLBAR_NAME="admin_toolbar_tools"
export ADMIN_TOOLBAR_PACKAGE="drupal/admin_toolbar"

# 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
Expand All @@ -12,8 +24,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
20 changes: 20 additions & 0 deletions .gitpod/drupal/drupalpod-setup/ddev_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -eu -o pipefail

# set PHP version, based on https://www.drupal.org/docs/getting-started/system-requirements/php-requirements#versions
major_version=$(echo "$DP_CORE_VERSION" | cut -d '.' -f 1)
minor_version=$(echo "$DP_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"
else
php_version="8.3"
fi

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

time ddev start
2 changes: 1 addition & 1 deletion .gitpod/drupal/drupalpod-setup/drupal_setup_contrib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ if [ -n "$COMPOSER_DRUPAL_LENIENT" ]; then
cd "${GITPOD_REPO_ROOT}" && time ddev . composer require "$COMPOSER_DRUPAL_LENIENT" --no-install
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" --no-install
cd "${GITPOD_REPO_ROOT}" && time ddev . composer require drupal/"$DP_PROJECT_NAME" --no-interaction --no-install
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
108 changes: 31 additions & 77 deletions .gitpod/drupal/drupalpod-setup/drupalpod-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,93 +26,47 @@ if [ -n "$DEBUG_SCRIPT" ] || [ -n "$GITPOD_HEADLESS" ]; then
set -x
fi

time ddev start

# Measure the time it takes to go through the script
script_start_time=$(date +%s)
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
}

source "$DIR/setup_env.sh"
source "$DIR/install_modules.sh"
source "$DIR/drupal_version_specifics.sh"
# 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

# Skip setup if it already ran once and if no special setup is set by DrupalPod extension
if [ ! -f "${GITPOD_REPO_ROOT}"/.drupalpod_initiated ] && [ -n "$DP_PROJECT_TYPE" ]; then

# Add git.drupal.org to known_hosts
if [ -z "$GITPOD_HEADLESS" ]; then
mkdir -p ~/.ssh
host=git.drupal.org
SSHKey=$(ssh-keyscan $host 2>/dev/null)
echo "$SSHKey" >>~/.ssh/known_hosts
if [ ! -f "${GITPOD_REPO_ROOT}"/.drupalpod_initiated ]; then

# Set a default setup if project type wasn't specified
if [ -z "$DP_PROJECT_TYPE" ]; then
source "$DIR/fallback_setup.sh"
fi

# Ignore specific directories during Drupal core development
cp "${GITPOD_REPO_ROOT}"/.gitpod/drupal/templates/git-exclude.template "${GITPOD_REPO_ROOT}"/.git/info/exclude
source "$DIR/git_setup.sh"

# Get the required repo ready
if [ "$DP_PROJECT_TYPE" == "project_core" ]; then
# Find if requested core version is dev or stable
d="$DP_CORE_VERSION"
case $d in
*.x)
# If dev - use git checkout origin/*
checkout_type=origin
;;
*)
# stable - use git checkout tags/*
checkout_type=tags
;;
esac

# Use origin or tags in git checkout command
cd "${GITPOD_REPO_ROOT}"/repos/drupal &&
git fetch origin &&
git fetch --all --tags &&
git checkout "$checkout_type"/"$DP_CORE_VERSION"

# Ignore specific directories during Drupal core development
cp "${GITPOD_REPO_ROOT}"/.gitpod/drupal/templates/git-exclude.template "${GITPOD_REPO_ROOT}"/repos/drupal/.git/info/exclude
else
# If not core - clone selected project into /repos and remove drupal core
rm -rf "${GITPOD_REPO_ROOT}"/repos/drupal
if [ ! -d repos/"${DP_PROJECT_NAME}" ]; then
mkdir -p repos
cd "${GITPOD_REPO_ROOT}"/repos && time git clone https://git.drupalcode.org/project/"$DP_PROJECT_NAME".git
fi
# 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' "${GITPOD_REPO_ROOT}"/repos/drupal/core/lib/Drupal.php | awk -F "'" '{print $2}')
DP_CORE_VERSION=$(convert_version "$VERSION_FROM_GIT")
export DP_CORE_VERSION
fi

# Set WORK_DIR
export WORK_DIR="${GITPOD_REPO_ROOT}"/repos/$DP_PROJECT_NAME

# Dynamically generate .gitmodules file
cat <<GITMODULESEND >"${GITPOD_REPO_ROOT}"/.gitmodules
# This file was dynamically generated by a script
[submodule "$DP_PROJECT_NAME"]
path = repos/$DP_PROJECT_NAME
url = https://git.drupalcode.org/project/$DP_PROJECT_NAME.git
ignore = dirty
GITMODULESEND

# Checkout specific branch only if there's issue_branch
if [ -n "$DP_ISSUE_BRANCH" ]; then
# If branch already exist only run checkout,
if cd "${WORK_DIR}" && git show-ref -q --heads "$DP_ISSUE_BRANCH"; then
cd "${WORK_DIR}" && git checkout "$DP_ISSUE_BRANCH"
else
cd "${WORK_DIR}" && git remote add "$DP_ISSUE_FORK" https://git.drupalcode.org/issue/"$DP_ISSUE_FORK".git
cd "${WORK_DIR}" && git fetch "$DP_ISSUE_FORK"
cd "${WORK_DIR}" && git checkout -b "$DP_ISSUE_BRANCH" --track "$DP_ISSUE_FORK"/"$DP_ISSUE_BRANCH"
fi
elif [ -n "$DP_MODULE_VERSION" ] && [ "$DP_PROJECT_TYPE" != "project_core" ]; then
cd "${WORK_DIR}" && git checkout "$DP_MODULE_VERSION"
fi
source "$DIR/ddev_setup.sh"

# Remove site that was installed before (for debugging)
rm -rf "${GITPOD_REPO_ROOT}"/web
rm -rf "${GITPOD_REPO_ROOT}"/vendor
rm -f "${GITPOD_REPO_ROOT}"/composer.json
rm -f "${GITPOD_REPO_ROOT}"/composer.lock
# Measure the time it takes to go through the script
script_start_time=$(date +%s)

source "$DIR/contrib_modules_setup.sh"
source "$DIR/cleanup.sh"
source "$DIR/composer_setup.sh"

if [ -n "$DP_PATCH_FILE" ]; then
Expand Down
10 changes: 10 additions & 0 deletions .gitpod/drupal/drupalpod-setup/fallback_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -eu -o pipefail

# Set a default setup (when project type is not specified)
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
Loading