Skip to content

Commit

Permalink
Merge pull request #29 from inpsyde/feat/ddev
Browse files Browse the repository at this point in the history
Add DDEV Config
  • Loading branch information
Biont authored May 4, 2023
2 parents 219e1ae + b8d9d75 commit 3e09db0
Show file tree
Hide file tree
Showing 32 changed files with 633 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .ddev/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
WP_STASH_DRIVER=\Stash\Driver\Apc
WP_STASH_DRIVER_ARGS='{"ttl":3600}'
37 changes: 37 additions & 0 deletions .ddev/commands/web/orchestrate
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
## Description: Set up the development environment
## Usage: orchestrate
## Example: "ddev orchestrate"

mkdir -p "${DDEV_DOCROOT}"
pushd "${DDEV_DOCROOT}"
PLUGIN_FOLDER="${DDEV_DOCROOT}/wp-content/mu-plugins/${PLUGIN_NAME:-$DDEV_PROJECT}"
VALID_ARGS=$(getopt -o fp: --long force,plugin: -- "$@")
if [[ $? -ne 0 ]]; then
exit 1;
fi

eval set -- "$VALID_ARGS"
while [ : ]; do
case "$1" in
-f | --force)
echo "Removing WordPress installation"
shift
export RECREATE_ENV=1;
popd
find "${DDEV_DOCROOT}" -mindepth 1 ! -regex "^${PLUGIN_FOLDER}\(/.*\)?" -delete
pushd "${DDEV_DOCROOT}"
;;
--) shift;
break
;;
esac
done

# Execute all fragments from orchestrate.d
if [ -d "${0}.d" ]; then
for FN in ${0}.d/*.sh ; do
echo $FN
source "${FN}"
done
fi
6 changes: 6 additions & 0 deletions .ddev/commands/web/orchestrate.d/00_download_wordpress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

if ! wp core download --version="${WP_VERSION}"; then
echo 'WordPress is already installed.'
exit
fi
6 changes: 6 additions & 0 deletions .ddev/commands/web/orchestrate.d/01_gitignore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

cat << 'EOF' > ".gitignore"
# Ignores everything in the docroot (docroot in config.yaml); this path may not be included in the standard .ddev/.gitignore.
*
EOF
22 changes: 22 additions & 0 deletions .ddev/commands/web/orchestrate.d/05_wp_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# Create wp-config.php
# the PHP snippet avoids some notices during CLI calls
# https://make.wordpress.org/cli/handbook/guides/common-issues/#php-notice-undefined-index-on-_server-superglobal
printf '
if ( defined( "WP_CLI" ) && WP_CLI && ! isset( $_SERVER["HTTP_HOST"] ) ) {
$_SERVER["HTTP_HOST"] = "%s";
}
' "${DDEV_HOSTNAME}" | wp config create \
--dbname=db \
--dbuser=db \
--dbpass=db \
--dbhost=db \
--force \
--extra-php

wp config set WP_DEBUG false --raw
wp config set WP_DEBUG_DISPLAY true --raw
wp config set WP_DEBUG_LOG true --raw
wp config set WP_SITEURL '(isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] ? "https://" : "http://") . $_SERVER["HTTP_HOST"]' --raw
wp config set WP_HOME '(isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] ? "https://" : "http://") . $_SERVER["HTTP_HOST"]' --raw
32 changes: 32 additions & 0 deletions .ddev/commands/web/orchestrate.d/10_wp_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

if [ ! -z "${RECREATE_ENV}" ]; then
echo "Deleting database before creating a new one"
wp db clean --yes --skip-packages
fi

if [ "${WP_MULTISITE}" = "true" ]; then
wp core multisite-install \
--title="${WP_TITLE}" \
--admin_user="${ADMIN_USER}" \
--admin_password="${ADMIN_PASS}" \
--url="${DDEV_PRIMARY_URL}" \
--admin_email="${ADMIN_EMAIL}" \
--skip-email

readarray -d , -t slugs <<< "${WP_MULTISITE_SLUGS},"; unset "slugs[-1]";
for slug in "${slugs[@]}"; do
if [ ! -z "${slug}" ]; then
wp site create --slug="${slug}"
fi
done

else
wp core install \
--title="${WP_TITLE}" \
--admin_user="${ADMIN_USER}" \
--admin_password="${ADMIN_PASS}" \
--url="${DDEV_PRIMARY_URL}" \
--admin_email="${ADMIN_EMAIL}" \
--skip-email
fi
16 changes: 16 additions & 0 deletions .ddev/commands/web/orchestrate.d/11_htaccess.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

cat << 'EOF' >> ".htaccess"
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
EOF
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

wp plugin is-installed akismet && wp plugin uninstall akismet
wp plugin is-installed hello && wp plugin uninstall hello
17 changes: 17 additions & 0 deletions .ddev/commands/web/orchestrate.d/25_mu_loader.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

MU_PLUGIN_LOADER_DIR="wp-content/mu-plugins"
MU_PLUGIN_LOADER_FILE="wp-content/mu-plugins/loader.php"

mkdir -p "${MU_PLUGIN_LOADER_DIR}"
touch "${MU_PLUGIN_LOADER_FILE}"

echo "Placing MU Loader at ${MU_PLUGIN_LOADER_FILE}"

cat << 'EOF' > "${MU_PLUGIN_LOADER_FILE}"
<?php
require_once __DIR__ . '/wp-stash/wp-stash.php';
EOF
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

popd

composer install
#npm install
11 changes: 11 additions & 0 deletions .ddev/commands/web/orchestrate.d/45_setup_whoops.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

pushd "${DDEV_DOCROOT}" || exit

flags="--activate"
if [ "${WP_MULTISITE}" = "true" ]; then
flags+=" --network"
fi


wp plugin install https://github.com/Rarst/wps/releases/latest/download/wps.zip $flags
4 changes: 4 additions & 0 deletions .ddev/commands/web/orchestrate.d/60_flush_rewrites.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

wp rewrite structure '/%postname%'
wp rewrite flush
7 changes: 7 additions & 0 deletions .ddev/commands/web/wp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
## Description: Run WordPress CLI inside the web container. DDEV core only provides this for the "wordpress" project type for some reason
## Usage: wp [flags] [args]
## Example: "ddev wp core version" or "ddev wp plugin install user-switching --activate"
## ProjectTypes: php

wp "$@" --path=.ddev/wordpress
32 changes: 32 additions & 0 deletions .ddev/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: wp-stash
type: php
docroot: .ddev/wordpress
php_version: "8.0"
webserver_type: nginx-fpm
router_http_port: "80"
router_https_port: "443"
xdebug_enabled: true
additional_hostnames: []
additional_fqdns: []
database:
type: mariadb
version: "10.4"
nfs_mount_enabled: false
mutagen_enabled: false
use_dns_when_possible: true
composer_version: "2"
nodejs_version: "16"
web_environment:
- WP_VERSION=6.2
- WP_LOCALE=en_US
- WP_TITLE=Inpsyde WP Stash
- ADMIN_USER=admin
- ADMIN_PASS=admin
- ADMIN_EMAIL=admin@example.com
- PLUGIN_NAME=wp-stash

hooks:
pre-start:
- exec-host: |
mkdir -p .ddev/wordpress/wp-content/mu-plugins/${DDEV_PROJECT}
mkdir -p .ddev/wordpress/wp-content/plugins/wp-stash-test-plugin
11 changes: 11 additions & 0 deletions .ddev/docker-compose.wp-plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3.6'
services:
web:
volumes:
- source: ../
target: /var/www/html/.ddev/wordpress/wp-content/mu-plugins/${DDEV_PROJECT}
type: bind
- source: ../wp-stash-test-plugin
target: /var/www/html/.ddev/wordpress/wp-content/plugins/wp-stash-test-plugin
type: bind

46 changes: 46 additions & 0 deletions .ddev/homeadditions/.bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
source /usr/lib/git-core/git-sh-prompt

# Ignore duplicate commands, ignore commands starting with a space
export HISTCONTROL=erasedups
# Keep the last 5000 entries
export HISTSIZE=5000

# Add global and "project root level" Composer executables to the PATH
export PATH="$HOME/.composer/vendor/bin:$PATH"
export PATH="/var/www/html/vendor/bin:$PATH"

# Append to the history instead of overwriting (good for multiple connections)
shopt -s histappend

export PS1="\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$\[$(tput sgr0)\] "

export PHP_IDE_CONFIG='serverName=wp-stash.ddev.site'
#export XDEBUG_CONFIG="mode=debug client_host=127.0.0.1 client_port=9003 start_with_request=yes"

alias ls='ls --group-directories-first'
alias cp='cp -aiv'
alias grep='grep --color=always'
alias tgz='tar -pczf'

profile(){
XDEBUG_MODE=profile "$1"
}

# All files in homeadditions/bashrc.d/*.sh will be
# interpreted as shell script so you can use these to
# customize your bash
if [ -d "${HOME}/bashrc.d" ]; then
for FN in ${HOME}/bashrc.d/*.sh ; do
source "${FN}"
done
fi

cd "${DDEV_DOCROOT}"

ngrok-url(){
curl -s localhost:4040/api/tunnels | jq -r .tunnels[0].public_url | awk -F'^http[s]?://' '{print $2}'
}

wp-replace(){
wp search-replace "${1}" "${2}" --network --precise --recurse-objects --verbose
}
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
* text eol=lf
.idea export-ignore
.gitattributes export-ignore
.github export-ignore
.gitignore export-ignore
Expand All @@ -7,3 +8,4 @@ phpcs.xml.dist export-ignore
phpunit.xml.dist export-ignore
README.md export-ignore
tests export-ignore
wp-stash-test-plugin export-ignore
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.idea/
/vendor
composer.lock
tmp
tmp
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/DdevIntegration.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions .idea/WP-Stash.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/codeception.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3e09db0

Please sign in to comment.