diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index bf4371d5..3562b261 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -24,8 +24,11 @@ "ghcr.io/devcontainers/features/node:1": { "version": "14" }, - "ghcr.io/devcontainers/features/docker-in-docker:2": {}, - "ghcr.io/devcontainers/features/git:1": {} + "ghcr.io/devcontainers/features/docker-in-docker:2": { + "dockerDashComposeVersion": "v2" + }, + "ghcr.io/devcontainers/features/git:1": {}, + "ghcr.io/devcontainers/features/github-cli:1": {} }, // Use 'forwardPorts' to make a list of ports inside the container available locally. diff --git a/.devcontainer/install.sh b/.devcontainer/install.sh new file mode 100644 index 00000000..69c335b2 --- /dev/null +++ b/.devcontainer/install.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env sh + +set -eux + +echo "Installing wp-cli..." +curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar +sudo chmod +x wp-cli.phar +sudo mv wp-cli.phar /usr/local/bin/wp + +# Copy the welcome message +sudo cp .devcontainer/welcome-message.txt /usr/local/etc/vscode-dev-containers/first-run-notice.txt diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh new file mode 100644 index 00000000..bad0f172 --- /dev/null +++ b/.devcontainer/setup.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env sh + +set -eux + +if [ -z ${CODESPACE_NAME+x} ]; then + SITE_HOST="http://localhost:8080" +else + SITE_HOST="https://${CODESPACE_NAME}-8080.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}" +fi + +PLUGIN_DIR=/workspaces/openid-connect-generic + +# Install Composer dependencies. +cd "${PLUGIN_DIR}" +composer install + +# Install Composer dependencies. +cd "${PLUGIN_DIR}" +npm ci + +# Setup the WordPress environment. +cd /var/www/html +echo "Setting up WordPress at $SITE_HOST" +wp core install --url="$SITE_HOST" --title="WordPress Trunk" --admin_user="admin" --admin_email="admin@example.com" --admin_password="password" --skip-email diff --git a/.devcontainer/welcome-message.txt b/.devcontainer/welcome-message.txt new file mode 100644 index 00000000..5b7bf05e --- /dev/null +++ b/.devcontainer/welcome-message.txt @@ -0,0 +1,6 @@ +👋 Welcome to "OpenID Connect for WP Development" in Codespaces! + +🛠️ Your environment is fully setup with all the required software. + +🚀 To get started, wait for the "postCreateCommand" to finish setting things up, then open the portforwarded URL and append '/wp-admin'. + diff --git a/dev-cli b/dev-cli new file mode 100755 index 00000000..be5df668 --- /dev/null +++ b/dev-cli @@ -0,0 +1,32 @@ +#!/usr/bin/env sh +## Description: Run local development commands. +## Usage: ./dev-cli [flags] [command] +## Example: "./dev-cli phpcs" + +WORKSPACE_DIR=./ + +# Check for the devcontainer CLI. +# TODO: Add a devcontainer CLI check and provide a docker compose fallback. + +case $1 in + build) + devcontainer --workspace-folder ${WORKSPACE_DIR} build "${@:2}" + ;; + start) + devcontainer --workspace-folder ${WORKSPACE_DIR} up "${@:2}" + ;; + composer) + devcontainer exec --workspace-folder ${WORKSPACE_DIR} composer "${@:2}" + ;; + npm) + devcontainer exec --workspace-folder ${WORKSPACE_DIR} npm "${@:2}" + ;; + phpcs|phpcbf|phpstan|phpunit) + devcontainer exec --workspace-folder ${WORKSPACE_DIR} composer "$@" + ;; + "") + echo "Usage: ./dev-cli [flags] [command]" + ;; + *) + ;; +esac diff --git a/docker-compose.yml b/docker-compose.yml index fa528d5c..6ef82d68 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,7 @@ services: app: image: wordpressdevelop/php:8.0-fpm restart: always - working_dir: /var/www/html + working_dir: /app depends_on: - db environment: @@ -16,10 +16,7 @@ services: WORDPRESS_DB_USER: wordpress_test WORDPRESS_DB_PASSWORD: wordpress_test volumes: - - ./wordpress:/var/www/html/wp:cached - - .:/var/www/html/wp-content/plugins/daggerhart-openid-connect-generic:cached - - ./tools/local-env/mu-plugins:/var/www/html/wp-content/mu-plugins:cached - - ./tools/local-env/wp-config.dev.php:/var/www/html/wp-config.php:cached + - ../..:/workspaces:cached - ~/.composer:/root/.composer:cached networks: - oidcwp-net @@ -38,10 +35,8 @@ services: WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress volumes: - - ./wordpress:/var/www/html/wp:cached - - .:/var/www/html/wp-content/plugins/daggerhart-openid-connect-generic:cached - - ./tools/local-env/mu-plugins:/var/www/html/wp-content/mu-plugins:cached - - ./tools/local-env/wp-config.dev.php:/var/www/html/wp-config.php:cached + - ./tools/local-env:/var/www/html:cached + - .:/var/www/html/wp-content/plugins/daggerhart-openid-connect-generic:cached,ro networks: - oidcwp-net diff --git a/tools/local-env/phpunit-wp-config.php b/tools/local-env/phpunit-wp-config.php deleted file mode 100644 index 556672df..00000000 --- a/tools/local-env/phpunit-wp-config.php +++ /dev/null @@ -1,133 +0,0 @@ -