diff --git a/.gitignore b/.gitignore index 01209a267c2ed..831eaffba439d 100644 --- a/.gitignore +++ b/.gitignore @@ -28,8 +28,9 @@ phpcs.xml .phpunit.result.cache ## Things for docker-composer -/tools/docker/data/mysql/* -!/tools/docker/data/mysql/.gitkeep +/tools/docker/data/* +!/tools/docker/data/.gitkeep +!/tools/docker/data/ssh.keys/ /tools/docker/logs/* !/tools/docker/logs/.gitkeep # Custom environment for docker containers diff --git a/package.json b/package.json index 10fa61c75f72d..d007d4fe4ec09 100644 --- a/package.json +++ b/package.json @@ -34,33 +34,32 @@ "cli-unlink": "jetpack cli unlink", "distclean": "printf '\\e[30;43m`pnpm run distclean` is deprecated.\\e[0m\\n'; rm -rf node_modules vendor && cd projects/plugins/jetpack && pnpm run distclean", "distclean-jetpack": "printf '\\e[30;43m`pnpm run distclean-jetpack` is deprecated.\\e[0m\\n'; cd projects/plugins/jetpack && pnpm run distclean", - "docker:build": "docker run -it --rm -v \"${PWD}:/usr/src/app\" -w /usr/src/app \"node:$(cat .nvmrc)\" bash -c 'pnpm install && jetpack build packages && jetpack build plugins/jetpack'", - "docker:build-image": "docker build -t automattic/jetpack-wordpress-dev tools/docker", - "docker:clean": "pnpm run docker:compose -- down --rmi all -v && rm -rf tools/docker/wordpress/* tools/docker/wordpress/.htaccess tools/docker/wordpress-develop/* tools/docker/logs/* tools/docker/data/mysql/*", - "docker:compose": "pnpm run docker:env && pnpm run docker:compose-volumes && pnpm run docker:compose-extras && docker-compose -f tools/docker/docker-compose.yml -f tools/docker/compose-volumes.built.yml -f tools/docker/compose-extras.yml", - "docker:compose-extras": "[ -f tools/docker/compose-extras.yml ] || cp tools/docker/compose-extras.yml.sample tools/docker/compose-extras.yml", - "docker:compose-volumes": "[ -f tools/docker/compose-volumes.yml ] || cp tools/docker/compose-volumes.yml.sample tools/docker/compose-volumes.yml; bash ./tools/compose-volumes.sh tools/docker/compose-volumes.yml > tools/docker/compose-volumes.built.yml", - "docker:db": "pnpm run docker:compose -- exec wordpress bash -c \"mysql --defaults-group-suffix=docker\"", - "docker:down": "pnpm run docker:compose -- down", - "docker:env": "node -e \"require('fs').createWriteStream( 'tools/docker/.env', { flags: 'a' } );\"", - "docker:install": "pnpm run docker:compose -- exec wordpress bash -c \"/var/scripts/install.sh\"", - "docker:jt-config": "[ -f ./tools/docker/bin/jt/config.sh ] || { echo 'Tunneling scripts are not installed. See the section \"Jurassic Tube Tunneling Service\" in tools/docker/README.md.'; exit; }; ./tools/docker/bin/jt/config.sh", - "docker:jt-down": "[ -f ./tools/docker/bin/jt/tunnel.sh ] || { echo 'Tunneling scripts are not installed. See the section \"Jurassic Tube Tunneling Service\" in tools/docker/README.md.'; exit; }; ./tools/docker/bin/jt/tunnel.sh break", - "docker:jt-up": "[ -f ./tools/docker/bin/jt/tunnel.sh ] || { echo 'Tunneling scripts are not installed. See the section \"Jurassic Tube Tunneling Service\" in tools/docker/README.md.'; exit; }; ./tools/docker/bin/jt/tunnel.sh", - "docker:multisite-convert": "pnpm run docker:compose -- exec wordpress bash -c \"/var/scripts/multisite-convert.sh\"", - "docker:ngrok": "pnpm run docker:compose -- -f tools/docker/docker-compose-ngrok.yml", - "docker:ngrok-down": "pnpm run docker:ngrok -- down", - "docker:ngrok-up": "pnpm run docker:ngrok -- up", - "docker:phpunit": "pnpm run docker:compose -- exec wordpress phpunit --configuration=/var/www/html/wp-content/plugins/jetpack/phpunit.xml.dist", - "docker:phpunit:multisite": "pnpm run docker:compose -- exec wordpress phpunit --configuration=/var/www/html/wp-content/plugins/jetpack/tests/php.multisite.xml", - "docker:run-extras": "pnpm run docker:compose -- exec wordpress bash -c \"chmod +x /var/scripts/run-extras.sh && . /var/scripts/run-extras.sh\"", - "docker:sh": "pnpm run docker:compose -- exec wordpress bash", - "docker:stop": "pnpm run docker:compose -- stop", - "docker:tail": "pnpm run docker:compose -- exec wordpress bash -c \"/var/scripts/tail.sh\"", - "docker:uninstall": "pnpm run docker:compose -- exec wordpress bash -c \"/var/scripts/uninstall.sh\"", - "docker:up": "pnpm run docker:compose -- up", - "docker:update-core-unit-tests": "pnpm run docker:compose -- exec wordpress svn up /tmp/wordpress-develop/tests/phpunit/data/ /tmp/wordpress-develop/tests/phpunit/includes", - "docker:wp": "pnpm run docker:compose -- exec wordpress wp --allow-root --path=/var/www/html/", + "docker:build": "printf '\\e[30;43m`pnpm run docker:build` is deprected. Use the Jetpack CLI instead.\\e[0m\\n'; jetpack docker build", + "docker:build-image": "printf '\\e[30;43m`pnpm run docker:build-image` is deprected. Use the Jetpack CLI instead.\\e[0m\\n'; jetpack docker build-image", + "docker:clean": "printf '\\e[30;43m`pnpm run docker:clean` is deprected. Use the Jetpack CLI instead.\\e[0m\\n'; jetpack docker clean", + "docker:compose": "printf '\\e[30;43m`pnpm run docker:compose` is deprected. Now it is integrated into relevant Jetpack CLI commands.\\e[0m\\n';", + "docker:compose-extras": "printf '\\e[30;43m`pnpm run docker:compose-extras` is deprected. Now it is integrated into relevant Jetpack CLI commands\\e[0m\\n';", + "docker:compose-volumes": "printf '\\e[30;43m`pnpm run docker:compose-volumes` is deprected. Now it is integrated into relevant Jetpack CLI commands\\e[0m\\n';", + "docker:db": "printf '\\e[30;43m`pnpm run docker:db` is deprected. Use the Jetpack CLI instead.\\e[0m\\n'; jetpack docker db", + "docker:down": "printf '\\e[30;43m`pnpm run docker:down` is deprected. Use the Jetpack CLI instead.\\e[0m\\n'; jetpack docker down", + "docker:env": "printf '\\e[30;43m`pnpm run docker:env` is deprected. Now it is integrated into relevant Jetpack CLI commands.\\e[0m\\n';", + "docker:install": "printf '\\e[30;43m`pnpm run docker:install` is deprected. Use the Jetpack CLI instead.\\e[0m\\n'; jetpack docker install", + "docker:jt-config": "printf '\\e[30;43m`pnpm run docker:jt-config` is deprected. Use the Jetpack CLI instead.\\e[0m\\n'; jetpack docker jt-config", + "docker:jt-down": "printf '\\e[30;43m`pnpm run docker:jt-down` is deprected. Use the Jetpack CLI instead.\\e[0m\\n'; jetpack docker jt-down", + "docker:jt-up": "printf '\\e[30;43m`pnpm run docker:jt-up` is deprected. Use the Jetpack CLI instead.\\e[0m\\n'; jetpack docker jt-up", + "docker:multisite-convert": "printf '\\e[30;43m`pnpm run docker:multisite-convert` is deprected. Use the Jetpack CLI instead.\\e[0m\\n'; jetpack docker multisite-convert", + "docker:ngrok-down": "printf '\\e[30;43m`pnpm run docker:ngrok-down` is deprected. Use the Jetpack CLI instead.\\e[0m\\n'; jetpack docker down --ngrok", + "docker:ngrok-up": "printf '\\e[30;43m`pnpm run docker:ngrok-up` is deprected. Use the Jetpack CLI instead.\\e[0m\\n'; jetpack docker up --ngrok", + "docker:phpunit": "printf '\\e[30;43m`pnpm run docker:phpunit` is deprected. Use the Jetpack CLI instead.\\e[0m\\n'; jetpack docker phpunit", + "docker:phpunit:multisite": "printf '\\e[30;43m`pnpm run docker:phpunit:multisite` is deprected. Use the Jetpack CLI instead.\\e[0m\\n'; jetpack docker phpunit-multisite", + "docker:run-extras": "printf '\\e[30;43m`pnpm run docker:run-extras` is deprected. Use the Jetpack CLI instead.\\e[0m\\n'; jetpack docker run-extras", + "docker:sh": "printf '\\e[30;43m`pnpm run docker:sh` is deprected. Use the Jetpack CLI instead.\\e[0m\\n'; jetpack docker sh", + "docker:stop": "printf '\\e[30;43m`pnpm run docker:stop` is deprected. Use the Jetpack CLI instead.\\e[0m\\n'; jetpack docker stop", + "docker:tail": "printf '\\e[30;43m`pnpm run docker:tail` is deprected. Use the Jetpack CLI instead.\\e[0m\\n'; jetpack docker tail", + "docker:uninstall": "printf '\\e[30;43m`pnpm run docker:uninstall` is deprected. Use the Jetpack CLI instead.\\e[0m\\n'; jetpack docker uninstall", + "docker:up": "printf '\\e[30;43m`pnpm run docker:up` is deprected. Use the Jetpack CLI instead.\\e[0m\\n'; jetpack docker up", + "docker:update-core-unit-tests": "printf '\\e[30;43m`pnpm run docker:update-core-unit-tests` is deprected. Use the Jetpack CLI instead.\\e[0m\\n'; jetpack docker update-core-unit-tests", + "docker:wp": "printf '\\e[30;43m`pnpm run docker:wp` is deprected. Use the Jetpack CLI instead.\\e[0m\\n'; jetpack docker wp", "install-if-deps-outdated": "pnpm install --no-prod --frozen-lockfile", "lint": "pnpm run lint-file -- .", "lint-changed": "tools/eslint-changed.js --ext .js,.jsx --git", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7ca643a6c8bee..61f5f64494e0f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3227,7 +3227,7 @@ packages: /@kwsites/file-exists/1.1.1: resolution: {integrity: sha512-m9/5YGR18lIwxSFDwfE3oA7bWuq9kdau6ugN4H2rJeyhFQZcG9AgSHkQtSD15a8WvTgfz9aikZMrKPHvbpqFiw==} dependencies: - debug: 4.3.2 + debug: 4.3.1 transitivePeerDependencies: - supports-color dev: false @@ -3789,34 +3789,34 @@ packages: - typescript dev: true - /@typescript-eslint/experimental-utils/4.14.1_eslint@7.25.0: - resolution: {integrity: sha512-2CuHWOJwvpw0LofbyG5gvYjEyoJeSvVH2PnfUQSn0KQr4v8Dql2pr43ohmx4fdPQ/eVoTSFjTi/bsGEXl/zUUQ==} + /@typescript-eslint/experimental-utils/4.26.0_eslint@7.25.0: + resolution: {integrity: sha512-TH2FO2rdDm7AWfAVRB5RSlbUhWxGVuxPNzGT7W65zVfl8H/WeXTk1e69IrcEVsBslrQSTDKQSaJD89hwKrhdkw==} engines: {node: ^10.12.0 || >=12.0.0} peerDependencies: eslint: '*' dependencies: '@types/json-schema': 7.0.7 - '@typescript-eslint/scope-manager': 4.14.1 - '@typescript-eslint/types': 4.14.1 - '@typescript-eslint/typescript-estree': 4.14.1 + '@typescript-eslint/scope-manager': 4.26.0 + '@typescript-eslint/types': 4.26.0 + '@typescript-eslint/typescript-estree': 4.26.0 eslint: 7.25.0 eslint-scope: 5.1.1 - eslint-utils: 2.1.0 + eslint-utils: 3.0.0_eslint@7.25.0 transitivePeerDependencies: - supports-color - typescript dev: true - /@typescript-eslint/scope-manager/4.14.1: - resolution: {integrity: sha512-F4bjJcSqXqHnC9JGUlnqSa3fC2YH5zTtmACS1Hk+WX/nFB0guuynVK5ev35D4XZbdKjulXBAQMyRr216kmxghw==} + /@typescript-eslint/scope-manager/4.26.0: + resolution: {integrity: sha512-G6xB6mMo4xVxwMt5lEsNTz3x4qGDt0NSGmTBNBPJxNsrTXJSm21c6raeYroS2OwQsOyIXqKZv266L/Gln1BWqg==} engines: {node: ^8.10.0 || ^10.13.0 || >=11.10.1} dependencies: - '@typescript-eslint/types': 4.14.1 - '@typescript-eslint/visitor-keys': 4.14.1 + '@typescript-eslint/types': 4.26.0 + '@typescript-eslint/visitor-keys': 4.26.0 dev: true - /@typescript-eslint/types/4.14.1: - resolution: {integrity: sha512-SkhzHdI/AllAgQSxXM89XwS1Tkic7csPdndUuTKabEwRcEfR8uQ/iPA3Dgio1rqsV3jtqZhY0QQni8rLswJM2w==} + /@typescript-eslint/types/4.26.0: + resolution: {integrity: sha512-rADNgXl1kS/EKnDr3G+m7fB9yeJNnR9kF7xMiXL6mSIWpr3Wg5MhxyfEXy/IlYthsqwBqHOr22boFbf/u6O88A==} engines: {node: ^8.10.0 || ^10.13.0 || >=11.10.1} dev: true @@ -3840,8 +3840,8 @@ packages: - supports-color dev: true - /@typescript-eslint/typescript-estree/4.14.1: - resolution: {integrity: sha512-M8+7MbzKC1PvJIA8kR2sSBnex8bsR5auatLCnVlNTJczmJgqRn8M+sAlQfkEq7M4IY3WmaNJ+LJjPVRrREVSHQ==} + /@typescript-eslint/typescript-estree/4.26.0: + resolution: {integrity: sha512-GHUgahPcm9GfBuy3TzdsizCcPjKOAauG9xkz9TR8kOdssz2Iz9jRCSQm6+aVFa23d5NcSpo1GdHGSQKe0tlcbg==} engines: {node: ^10.12.0 || >=12.0.0} peerDependencies: typescript: '*' @@ -3849,23 +3849,22 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/types': 4.14.1 - '@typescript-eslint/visitor-keys': 4.14.1 - debug: 4.3.2 - globby: 11.0.2 + '@typescript-eslint/types': 4.26.0 + '@typescript-eslint/visitor-keys': 4.26.0 + debug: 4.3.1 + globby: 11.0.3 is-glob: 4.0.1 - lodash: 4.17.21 semver: 7.3.5 - tsutils: 3.20.0 + tsutils: 3.21.0 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/visitor-keys/4.14.1: - resolution: {integrity: sha512-TAblbDXOI7bd0C/9PE1G+AFo7R5uc+ty1ArDoxmrC1ah61Hn6shURKy7gLdRb1qKJmjHkqu5Oq+e4Kt0jwf1IA==} + /@typescript-eslint/visitor-keys/4.26.0: + resolution: {integrity: sha512-cw4j8lH38V1ycGBbF+aFiLUls9Z0Bw8QschP3mkth50BbWzgFS33ISIgBzUMuQ2IdahoEv/rXstr8Zhlz4B1Zg==} engines: {node: ^8.10.0 || ^10.13.0 || >=11.10.1} dependencies: - '@typescript-eslint/types': 4.14.1 + '@typescript-eslint/types': 4.26.0 eslint-visitor-keys: 2.0.0 dev: true @@ -5891,7 +5890,7 @@ packages: resolution: {integrity: sha512-o/HelwhuKpTj/frsOsbNLNgnNGVIFsVP/SW2BSF14gVl7kAfMOJ6/8wUAUvG1R1NHKrfG+2sHZTu0yauT1qBrA==} engines: {node: '>=6.0'} dependencies: - '@babel/runtime': 7.13.10 + '@babel/runtime': 7.14.0 '@babel/runtime-corejs3': 7.12.5 dev: true @@ -8901,7 +8900,7 @@ packages: '@typescript-eslint/eslint-plugin': optional: true dependencies: - '@typescript-eslint/experimental-utils': 4.14.1_eslint@7.25.0 + '@typescript-eslint/experimental-utils': 4.26.0_eslint@7.25.0 eslint: 7.25.0 transitivePeerDependencies: - supports-color @@ -8950,7 +8949,7 @@ packages: peerDependencies: eslint: ^3 || ^4 || ^5 || ^6 || ^7 dependencies: - '@babel/runtime': 7.13.10 + '@babel/runtime': 7.14.0 aria-query: 4.2.2 array-includes: 3.1.3 ast-types-flow: 0.0.7 @@ -9069,6 +9068,16 @@ packages: eslint-visitor-keys: 1.3.0 dev: true + /eslint-utils/3.0.0_eslint@7.25.0: + resolution: {integrity: sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==} + engines: {node: ^10.0.0 || ^12.0.0 || >= 14.0.0} + peerDependencies: + eslint: '>=5' + dependencies: + eslint: 7.25.0 + eslint-visitor-keys: 2.0.0 + dev: true + /eslint-visitor-keys/1.3.0: resolution: {integrity: sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==} engines: {node: '>=4'} @@ -10055,18 +10064,6 @@ packages: slash: 3.0.0 dev: true - /globby/11.0.2: - resolution: {integrity: sha512-2ZThXDvvV8fYFRVIxnrMQBipZQDr7MxKAmQK1vujaj9/7eF0efG7BPUKJ7jP7G5SLF37xKDXvO4S/KKLj/Z0og==} - engines: {node: '>=10'} - dependencies: - array-union: 2.1.0 - dir-glob: 3.0.1 - fast-glob: 3.2.5 - ignore: 5.1.8 - merge2: 1.4.1 - slash: 3.0.0 - dev: true - /globby/11.0.3: resolution: {integrity: sha512-ffdmosjA807y7+lA1NM0jELARVmYul/715xiILEjo3hBLPTcirgQNnXECn5g3mtR8TOLCVbkfua1Hpen25/Xcg==} engines: {node: '>=10'} @@ -10856,8 +10853,8 @@ packages: rgb-regex: 1.0.1 rgba-regex: 1.0.0 - /is-core-module/2.2.0: - resolution: {integrity: sha512-XRAfAdyyY5F5cOXn7hYQDqh2Xmii+DEfIcQGxK/uNwMHhIkPWO0g8msXcbzLe+MpGoR951MlqM/2iIlU4vKDdQ==} + /is-core-module/2.4.0: + resolution: {integrity: sha512-6A2fkfq1rfeQZjxrZJGerpLCTHRNEBiSgnu0+obeJpEPZRUooHgsizvzv0ZjJwOz3iWIHdJtVWJ/tmPr3D21/A==} dependencies: has: 1.0.3 @@ -12960,7 +12957,7 @@ packages: resolution: {integrity: sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==} dependencies: hosted-git-info: 2.8.9 - resolve: 1.19.0 + resolve: 1.20.0 semver: 5.7.1 validate-npm-package-license: 3.0.4 @@ -15167,13 +15164,19 @@ packages: /resolve/1.19.0: resolution: {integrity: sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg==} dependencies: - is-core-module: 2.2.0 + is-core-module: 2.4.0 + path-parse: 1.0.6 + + /resolve/1.20.0: + resolution: {integrity: sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==} + dependencies: + is-core-module: 2.4.0 path-parse: 1.0.6 /resolve/2.0.0-next.3: resolution: {integrity: sha512-W8LucSynKUIDu9ylraa7ueVZ7hc0uAgJBxVsQSKOXOyle8a93qXhcz+XAXZ8bIq2d6i4Ehddn6Evt+0/UwKk6Q==} dependencies: - is-core-module: 2.2.0 + is-core-module: 2.4.0 path-parse: 1.0.6 dev: true @@ -16635,6 +16638,15 @@ packages: tslib: 1.14.1 dev: true + /tsutils/3.21.0: + resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==} + engines: {node: '>= 6'} + peerDependencies: + typescript: '>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta' + dependencies: + tslib: 1.14.1 + dev: true + /tty-browserify/0.0.0: resolution: {integrity: sha1-oVe6QC2iTpv5V/mqadUk7tQpAaY=} diff --git a/tools/cli/commands/docker.js b/tools/cli/commands/docker.js index 6c5abacd9225d..5c54dc887b728 100644 --- a/tools/cli/commands/docker.js +++ b/tools/cli/commands/docker.js @@ -3,25 +3,393 @@ */ import { spawnSync } from 'child_process'; import chalk from 'chalk'; +import { createWriteStream, existsSync, copyFileSync, readFileSync, writeFileSync } from 'fs'; +import yaml from 'js-yaml'; + +const dockerFolder = `tools/docker`; /** - * Default handler for the monorepo Docker commands. + * Sets default options that are common for most of the commands * - * @param {object} argv - Arguments passed. + * @param {object} yargs - Yargs + * @returns {object} Modified Yargs object */ -const defaultDockerCmdHandler = argv => { - const args = process.argv.slice( 4 ); // node pnpm run docker [args..] +const defaultOpts = yargs => + yargs + .option( 'type', { + alias: 't', + default: 'dev', + describe: 'Container type', + } ) + .option( 'name', { + alias: 'n', + describe: 'Project name', + } ) + .option( 'port', { + alias: 'p', + describe: 'WP port', + } ) + .option( 'ngrok', { + type: 'bool', + describe: 'Flag to launch ngrok process', + } ); + +/** + * Gets a project name from the passed arguments. Defaults to 'dev' if not specified. + * + * @param {object} argv - Yargs + * @returns {string} Project name + */ +const getProjectName = argv => { + let project = 'dev'; + if ( argv.type === 'e2e' ) { + project = argv.name ? argv.name : 'e2e'; + } + + return project; +}; + +/** + * Builds a map of ENV variables for specified configuration + * + * @param {object} argv - Yargs + * @returns {object} key-value pairs of ENV variables + */ +const buildEnv = argv => { + const envOpts = {}; + if ( argv.type === 'e2e' ) { + envOpts.PORT_WORDPRESS = argv.port ? argv.port : 8889; + } + + envOpts.COMPOSE_PROJECT_NAME = 'jetpack_' + getProjectName( argv ); + return envOpts; +}; + +/** + * Creates an .env file + */ +const setEnv = () => { + createWriteStream( `${ dockerFolder }/.env`, { + flags: 'a', + } ); +}; + +/** + * Creates a default extras file if needed. + */ +const setExtras = () => { + const extrasFile = `${ dockerFolder }/compose-extras.yml`; + const extrasSampleFile = `${ dockerFolder }/compose-extras.yml.sample`; + + if ( ! existsSync( extrasFile ) ) { + copyFileSync( extrasSampleFile, extrasFile ); + } +}; + +/** + * Generates Volumes compose file + * + * @param {object} argv - Yargs + */ +const setVolumes = argv => { + const volumesFile = `${ dockerFolder }/compose-volumes.yml`; + const volumesBuiltFile = `${ dockerFolder }/compose-volumes.built.yml`; + const sampleFile = `${ dockerFolder }/compose-volumes.yml.sample`; + + if ( ! existsSync( volumesFile ) ) { + copyFileSync( sampleFile, volumesFile ); + } + + const volumes = yaml.load( readFileSync( volumesFile, 'utf8' ) ); + const volumesObj = { + version: '3.3', + services: { wordpress: { volumes } }, + }; + + if ( argv.type === 'dev' ) { + // Update the abs path to wordpress installation + volumesObj.services.sftp = { + volumes: volumes.map( vol => + vol.replace( /\/var\/www\/html/, '/home/wordpress/var/www/html' ) + ), + }; + } + + writeFileSync( volumesBuiltFile, yaml.dump( volumesObj ) ); +}; + +/** + * Checks whether the command should run in foreground + * + * @param {object} argv - argv + * @returns {boolean} whether command is running in foreground + */ +const isInForeground = argv => ! argv.detached || argv.ngrok; + +/** + * Prints some contents before command execution + * + * @param {object} argv - argv + */ +const printPreCmdMsg = argv => { + if ( argv.v ) { + console.log( argv ); + } +}; + +/** + * Prints some contents after command execution + * + * @param {object} argv - argv + */ +const printPostCmdMsg = argv => { + if ( isInForeground( argv ) ) { + return; + } + if ( argv._[ 1 ] === 'up' ) { + const port = argv.port ? argv.port : ''; + const msg = chalk.green( `Open http://localhost${ port }/ to see your site!` ); + console.log( msg ); + } +}; + +/** + * Default executor with error handler + * + * @param {object} argv - Yargs + * @param {Function} fnc - Function to execute + * @returns {any} resulting value from fnc + */ +const executor = ( argv, fnc ) => { try { - spawnSync( `pnpm`, [ 'run', `docker:${ argv._[ 1 ] }`, '--', ...args ], { stdio: 'inherit' } ); + return fnc( argv ); } catch ( error ) { - console.error( chalk.bgRed( `Failed to execute command docker:${ argv._[ 1 ] }. Error:` ) ); - console.log( error ); + console.error( chalk.bgRed( `Failed to execute the function. Error:` ) ); + console.error( error ); process.exit( 1 ); } +}; +const shellExecutor = ( argv, cmd, args, opts = {} ) => { if ( argv.v ) { - console.log( argv ); + console.log( + chalk.green( 'Running command:' ), + opts.env + ? Object.entries( opts.env ) + .map( a => `${ a[ 0 ] }=${ a[ 1 ] }` ) + .join( ' ' ) + : '', + cmd, + args.join( ' ' ) + ); } + return spawnSync( cmd, args, { + stdio: 'inherit', + ...opts, + env: { ...opts.env, ...process.env }, + } ); +}; + +/** + * Executor for `docker-compose` commands + * + * @param {object} argv - Yargs + * @param {Array} opts - Array of arguments + * @param {object} envOpts - key-value pairs of the ENV variables to set + */ +const composeExecutor = ( argv, opts, envOpts ) => { + executor( argv, () => shellExecutor( argv, 'docker-compose', opts, { env: envOpts } ) ); +}; + +/** + * Builds an array of compose files matching configuration options. + * + * @param {object} argv - Yargs + * @returns {Array} Array of shell arguments + */ +const buildComposeFiles = argv => { + const defaultCompose = [ `-f${ dockerFolder }/docker-compose.yml` ]; + const extendFiles = [ + `-f${ dockerFolder }/compose-volumes.built.yml`, + `-f${ dockerFolder }/compose-extras.yml`, + ]; + const compose = defaultCompose; + if ( argv.type !== 'e2e' ) { + compose.push( `-f${ dockerFolder }/docker-compose.dev.yml` ); + } + return compose.concat( extendFiles ); +}; + +/** + * Builds an array of opts that are required to run arbitrary compose command. + * + * @param {object} argv - Yargs + * @returns {Array} Array of options required for specified command + */ +const buildDefaultCmd = argv => { + const opts = buildComposeFiles( argv ); + if ( argv._[ 1 ] === 'up' ) { + opts.push( 'up' ); + if ( argv.detached ) { + opts.push( '-d' ); + } + } else if ( argv._[ 1 ] === 'down' ) { + opts.push( 'down' ); + } else if ( argv._[ 1 ] === 'stop' ) { + opts.push( 'stop' ); + } else if ( argv._[ 1 ] === 'clean' ) { + opts.push( 'down', '-v' ); + } + + return opts; +}; + +/** + * Creates a tunnel using globally installed ngrok and it's configuration file + * + * @param {object} argv - argv + */ +const launchNgrok = argv => { + const docsMessage = 'Please refer to Docker docs for details: tools/docker/README.md'; + const existCheck = executor( argv, () => shellExecutor( argv, 'command', [ '-v', 'ngrok' ] ) ); + if ( existCheck.status !== 0 ) { + console.error( chalk.red( `'ngrok' is not installed globally. ${ docsMessage }` ) ); + process.exit( 1 ); + } + + const ngrokArgs = [ 'start', 'jetpack' ]; + if ( argv.ngrok === 'sftp' ) { + ngrokArgs.push( 'jetpack-sftp' ); + } + const startCheck = executor( argv, () => shellExecutor( argv, 'ngrok', ngrokArgs ) ); + if ( startCheck.status !== 0 ) { + console.error( + chalk.red( + `Something is wrong with ngrok configuration. Examine ngrok errors above. ${ docsMessage }` + ) + ); + } +}; + +/** + * Default handler for the monorepo Docker commands. + * + * @param {object} argv - Arguments passed. + */ +const defaultDockerCmdHandler = argv => { + printPreCmdMsg( argv ); + + executor( argv, setEnv ); + executor( argv, setVolumes ); + executor( argv, setExtras ); + + const opts = buildDefaultCmd( argv ); + const envOpts = buildEnv( argv ); + composeExecutor( argv, opts, envOpts ); + if ( argv.type === 'dev' && argv.ngrok ) { + executor( argv, launchNgrok ); + } + printPostCmdMsg( argv ); +}; + +/** + * Builds an array of opts that are required to execute specified command in wordpress container + * + * @param {object} argv - Yargs + * @returns {Array} Array of options required for specified command + */ +const buildExecCmd = argv => { + const opts = buildComposeFiles( argv ); + opts.push( 'exec', 'wordpress' ); + const cmd = argv._[ 1 ]; + + if ( cmd === 'install' ) { + opts.push( '/var/scripts/install.sh' ); + } else if ( cmd === 'sh' ) { + opts.push( 'bash' ); + } else if ( cmd === 'db' ) { + opts.push( 'mysql', '--defaults-group-suffix=docker' ); + } else if ( cmd === 'phpunit' ) { + const unitArgs = argv._.slice( 2 ); + + opts.push( + 'phpunit', + '--configuration=/var/www/html/wp-content/plugins/jetpack/phpunit.xml.dist', + ...unitArgs + ); + } else if ( cmd === 'phpunit-multisite' ) { + const unitArgs = argv._.slice( 2 ); + opts.push( + 'phpunit', + '--configuration=/var/www/html/wp-content/plugins/jetpack/tests/php.multisite.xml', + ...unitArgs + ); + } else if ( cmd === 'wp' ) { + const wpArgs = argv._.slice( 2 ); + opts.push( 'wp', '--allow-root', '--path=/var/www/html/', ...wpArgs ); + } else if ( cmd === 'tail' ) { + opts.push( '/var/scripts/tail.sh' ); + } else if ( cmd === 'uninstall' ) { + opts.push( '/var/scripts/uninstall.sh' ); + } else if ( cmd === 'multisite-convert' ) { + opts.push( '/var/scripts/multisite-convert.sh' ); + } else if ( cmd === 'update-core-unit-tests' ) { + opts.push( + 'svn', + 'up', + '/tmp/wordpress-develop/tests/phpunit/data/', + '/tmp/wordpress-develop/tests/phpunit/includes' + ); + } else if ( cmd === 'run-extras' ) { + opts.push( '/var/scripts/run-extras.sh' ); + } + + return opts; +}; + +/** + * Execution handler for `... exec wordpress` commands + * + * @param {object} argv - Yargs object + */ +const execDockerCmdHandler = argv => { + printPreCmdMsg( argv ); + + const envOpts = buildEnv( argv ); + const opts = buildExecCmd( argv ); + + composeExecutor( argv, opts, envOpts ); +}; + +/** + * Execution handler for Jurassic Tube commands + * + * @param {object} argv - Yargs object + */ +const execJtCmdHandler = argv => { + const jtConfigFile = `${ dockerFolder }/bin/jt/config.sh`; + const jtTunnelFile = `${ dockerFolder }/bin/jt/tunnel.sh`; + + if ( ! existsSync( jtConfigFile ) || ! existsSync( jtTunnelFile ) ) { + console.log( + 'Tunneling scripts are not installed. See the section "Jurassic Tube Tunneling Service" in tools/docker/README.md.' + ); + process.exit( 1 ); + } + const jtOpts = argv._.slice( 2 ); // docker jt-* [args..] + const opts = []; + const arg = argv._[ 1 ]; + let cmd; + if ( arg === 'jt-config' ) { + cmd = jtConfigFile; + } else if ( arg === 'jt-down' ) { + cmd = jtTunnelFile; + opts.push( 'break' ); + } else if ( arg === 'jt-up' ) { + cmd = jtTunnelFile; + } + + executor( argv, () => shellExecutor( argv, cmd, opts.concat( jtOpts ) ) ); }; /** @@ -34,123 +402,155 @@ const defaultDockerCmdHandler = argv => { export function dockerDefine( yargs ) { yargs.command( { command: 'docker ', - description: 'Run monorepo Docker commands', - builder: builder => { - return builder + description: 'Docker stuff', + builder: yarg => { + yarg + // Compose commands .command( { - command: 'build', - description: 'build jetpack within the docker env', - handler: defaultDockerCmdHandler, + command: 'up', + description: 'Start Docker containers', + builder: yargCmd => + defaultOpts( yargCmd ).option( 'detached', { + alias: 'd', + describe: 'Launch in detached mode', + type: 'bool', + } ), + handler: argv => defaultDockerCmdHandler( argv ), } ) .command( { - command: 'build-image', - description: 'build docker image', - handler: defaultDockerCmdHandler, + command: 'stop', + description: 'Stop the containers', + builder: yargCmd => defaultOpts( yargCmd ), + handler: argv => defaultDockerCmdHandler( argv ), } ) .command( { - command: 'clean', - description: 'remove docker images, mysql data, etc.', - handler: defaultDockerCmdHandler, + command: 'down', + description: 'Down the containers', + builder: yargCmd => defaultOpts( yargCmd ), + handler: argv => defaultDockerCmdHandler( argv ), } ) .command( { - command: 'db', - description: 'access mysql cli for the wp install', - handler: defaultDockerCmdHandler, + command: 'clean', + description: 'Remove docker volumes, MySql and WordPress data and logs.', + builder: yargCmd => defaultOpts( yargCmd ), + handler: argv => { + defaultDockerCmdHandler( argv ); + const project = getProjectName( argv ); + executor( argv, () => + shellExecutor( + argv, + 'rm', + [ + '-rf', + `${ dockerFolder }/wordpress/*`, + `${ dockerFolder }/wordpress/.htaccess`, + `${ dockerFolder }/wordpress-develop/*`, + `${ dockerFolder }/logs/${ project }/`, + `${ dockerFolder }/logs/${ project }_mysql/`, + `${ dockerFolder }/data/${ project }_mysql/*`, + ], + { shell: true } + ) + ); + }, } ) .command( { - command: 'down', - description: 'stop all docker containers', - handler: defaultDockerCmdHandler, + command: 'build-image', + description: 'Builds local docker image', + handler: argv => { + executor( argv, () => + shellExecutor( argv, 'docker', [ + 'build', + '-t', + 'automattic/jetpack-wordpress-dev', + dockerFolder, + ] ) + ); + }, } ) + // Wordpress exec commands .command( { command: 'install', - description: 'create a wp install', - handler: defaultDockerCmdHandler, + description: 'Install WP for running container', + builder: yargExec => defaultOpts( yargExec ), + handler: argv => execDockerCmdHandler( argv ), } ) .command( { - command: 'jt-config', - description: 'set jurassic tube config', - handler: defaultDockerCmdHandler, + command: 'db', + description: 'Access MySql CLI', + builder: yargExec => defaultOpts( yargExec ), + handler: argv => execDockerCmdHandler( argv ), } ) .command( { - command: 'jt-up', - description: 'start jurassic tube tunnel', - handler: defaultDockerCmdHandler, + command: 'sh', + description: 'Access shell on Wordpress container', + builder: yargExec => defaultOpts( yargExec ), + handler: argv => execDockerCmdHandler( argv ), } ) .command( { - command: 'jt-down', - description: 'stop jurassic tube tunnel', - handler: defaultDockerCmdHandler, + command: 'phpunit', + description: 'Run PHPUNIT tests inside container', + builder: yargExec => defaultOpts( yargExec ), + handler: argv => execDockerCmdHandler( argv ), } ) .command( { - command: 'multisite-convert', - description: 'convert wp install to multisite', - handler: defaultDockerCmdHandler, + command: 'wp', + description: 'Execute WP-CLI command', + builder: yargExec => defaultOpts( yargExec ), + handler: argv => execDockerCmdHandler( argv ), } ) .command( { - command: 'ngrok', - description: 'see tools/docker/README.md', - handler: defaultDockerCmdHandler, + command: 'tail', + description: 'Watch WP debug.log', + builder: yargExec => defaultOpts( yargExec ), + handler: argv => execDockerCmdHandler( argv ), } ) .command( { - command: 'ngrok-down', - description: 'stop docker with ngrok', - handler: defaultDockerCmdHandler, + command: 'uninstall', + description: 'Uninstall WP installation', + builder: yargExec => defaultOpts( yargExec ), + handler: argv => execDockerCmdHandler( argv ), } ) .command( { - command: 'ngrok-up', - description: 'start docker with ngrok', - handler: defaultDockerCmdHandler, + command: 'phpunit-multisite', + alias: 'phpunit:multisite', + description: 'Run multisite PHPUNIT tests inside container ', + builder: yargExec => defaultOpts( yargExec ), + handler: argv => execDockerCmdHandler( argv ), } ) .command( { - command: 'phpunit', - description: 'run tests', - handler: defaultDockerCmdHandler, + command: 'multisite-convert', + description: 'Convert WP into a multisite', + builder: yargExec => defaultOpts( yargExec ), + handler: argv => execDockerCmdHandler( argv ), } ) .command( { - command: 'phpunit:multisite', - description: 'runs tests for wp multisite install', - handler: defaultDockerCmdHandler, + command: 'update-core-unit-tests', + description: 'Pulls latest Core unit tests files from SVN', + builder: yargExec => defaultOpts( yargExec ), + handler: argv => execDockerCmdHandler( argv ), } ) .command( { command: 'run-extras', - description: 'see tools/docker/bin/run-extras.sh', - handler: defaultDockerCmdHandler, - } ) - .command( { - command: 'sh', - description: 'access shell for the wp install', - handler: defaultDockerCmdHandler, + description: 'Run run-extras.sh bin script', + builder: yargExec => defaultOpts( yargExec ), + handler: argv => execDockerCmdHandler( argv ), } ) + // JT commands .command( { - command: 'stop', - description: 'stop docker containers', - handler: defaultDockerCmdHandler, - } ) - .command( { - command: 'tail', - description: 'watch wp debug.log output in console', - handler: defaultDockerCmdHandler, - } ) - .command( { - command: 'uninstall', - description: 'remove current wordpress install', - handler: defaultDockerCmdHandler, - } ) - .command( { - command: 'up', - description: 'start docker containers', - handler: defaultDockerCmdHandler, + command: 'jt-up', + description: 'Start jurassic tube tunnel', + handler: argv => execJtCmdHandler( argv ), } ) .command( { - command: 'update-core-unit-tests', - description: 'updates unit test dirs', - handler: defaultDockerCmdHandler, + command: 'jt-down', + description: 'Stop jurassic tube tunnel', + handler: argv => execJtCmdHandler( argv ), } ) .command( { - command: 'wp', - description: 'pass commands to wp-cli', - handler: defaultDockerCmdHandler, + command: 'jt-config', + description: 'Set jurassic tube config', + handler: argv => execJtCmdHandler( argv ), } ); }, } ); diff --git a/tools/docker/README.md b/tools/docker/README.md index 3259f69dd3f2d..f9247a0a4f53b 100644 --- a/tools/docker/README.md +++ b/tools/docker/README.md @@ -128,7 +128,7 @@ This command will rebuild the WordPress container if you made any changes to `do For running the containers in the background, use: ```sh -jetpack docker up -- -d +jetpack docker up -d ``` ### Stop containers @@ -137,7 +137,7 @@ jetpack docker up -- -d jetpack docker stop ``` -Stops all containers. Wrapper for `docker-composer stop`. +Stops all containers. Wrapper for `docker-compose stop`. ```sh jetpack docker down @@ -156,12 +156,12 @@ jetpack docker phpunit This will run unit tests for Jetpack. You can pass arguments to `phpunit` like so: ```sh -jetpack docker phpunit --filter=Protect +jetpack docker phpunit -- --filter=Protect ``` This command runs the tests as a multi site install ```sh -jetpack docker phpunit:multisite --filter=Protect +jetpack docker phpunit:multisite -- --filter=Protect ``` To run tests for specific packages, you can run the tests locally, from within the package's directory: @@ -259,8 +259,30 @@ You can add your custom Jetpack constants (such as `JETPACK__SANDBOX_DOMAIN`) to define( 'JETPACK__SANDBOX_DOMAIN', '{your sandbox}.wordpress.com' ); ``` +## Jurassic Tube Tunneling Service +If you are an Automattician, you can use Jurassic Tube tunneling service with functionality similar to Ngrok. + +As it is developed internally, you can review the source code and participate in adding new features. + +* Start the tunnel: `jetpack docker jt-up your-username your-subdomain` +* Break the connection: `jetpack docker jt-down` + +You can also set default values: + +```shell script +jetpack docker jt-config username your-username +jetpack docker jt-config subdomain your-subdomain +``` +That will let you omit those parameters while initiating the connection: +```shell script +jetpack docker jt-up +``` + +More information: PCYsg-snO-p2. ## Using Ngrok with Jetpack +Note: While Ngrok is technically supported for everyone, Jurassic Tube should be considered as preferred tunneling solution for Automatticians. + To be able to connect Jetpack you will need a domain - you can use [Ngrok.com](https://ngrok.com/) to assign one. If you use one-off domains, you'll have to re-install WordPress and re-connect Jetpack each time you close Ngrok (thus losing your randomly assigned domain). That's perfectly fine for quick testing or lightweight development. You can use [other similar services](https://alternativeto.net/software/ngrok/) as well. @@ -283,45 +305,12 @@ tunnels: proto: http ``` -You can start your ngrok tunnel like so: +ngrok support is integrated into a jetpack cli, so to start a docker container with mapped tunnel, simply run: ```bash -./ngrok start jetpack -``` - -These two commands are all you need to run to get Docker running when you start your computer: -```bash -./ngrok start jetpack -jetpack docker up -d -``` -### Docker Ngrok - -Alternative to the above configuration file is running ngrok in the container with docker-compose file. That starts ngrok inside a container and you don't have to install it or configure as a standalone software on your machine. - -**1. Configure environment** - -Add these variables to your `tools/docker/.env` file: - -This configures `example.us.ngrok.io` reserved domain that is available on my basic plan. -Possible values for `NGROK_REGION` are: (United States, default), eu (Europe), ap (Asia/Pacific) or au (Australia). -[Read more about ngrok regions](https://ngrok.com/docs#global-locations) +jetpack docker up --ngrok ``` -NGROK_AUTH= -NGROK_SUBDOMAIN=example -NGROK_REGION=us -``` - -**2. Start docker with Ngrok** - -Start container with `jetpack docker ngrok-up -d` -Stop container with `jetpack docker ngrok-down -d` - -All the other docker-compose commands can be invoked via `jetpack docker ngrok COMMAND` - -### Configuration file - -If you need more granular control over the Ngrok tunnel, you could create a configuration file. See [default configuration file location](https://ngrok.com/docs#default-config-location) from Ngrok Docs or use `-config=your_config_file.yml` argument with `ngrok` to use your configuration file. -## Ngrok SFTP Tunnel with Jetpack +### Ngrok SFTP Tunnel with Jetpack A sample config for adding an sftp tunnel to your Ngrok setup would look like this: ``` @@ -341,7 +330,7 @@ See more configuration options from [Ngrok documentation](https://ngrok.com/docs You can now start both tunnels: ```bash -ngrok start jetpack jetpack-sftp +jetpack docker up --ngrok sftp ``` You can inspect traffic between your WordPress/Jetpack container and WordPress.com using [the inspector](https://ngrok.com/docs#inspect). @@ -357,27 +346,6 @@ You should now be able to configure [Jetpack Backup & Scan](https://jetpack.com/ - Server password: `wordpress` - WordPress installation path: `/var/www/html` -## Jurassic Tube Tunneling Service -If you are an Automattician, you can use Jurassic Tube tunneling service with functionality similar to Ngrok. - -As it is developed internally, you can review the source code and participate in adding new features. - -* Start the tunnel: `jetpack docker jt-up your-username your-subdomain` -* Break the connection: `jetpack docker jt-down` - -You can also set default values: - -```shell script -jetpack docker jt-config username your-username -jetpack docker jt-config subdomain your-subdomain -``` -That will let you omit those parameters while initiating the connection: -```shell script -jetpack docker jt-up -``` - -More information: PCYsg-snO-p2. - ## Custom plugins & themes in the container Jetpack Docker environment can be wonderful for developing your own plugins and themes, too. diff --git a/tools/docker/bin/install.sh b/tools/docker/bin/install.sh index 83530df54e080..4f406a01c8f40 100755 --- a/tools/docker/bin/install.sh +++ b/tools/docker/bin/install.sh @@ -21,21 +21,23 @@ wp --allow-root core install \ # Discourage search engines from indexing. Can be changed via UI in Settings->Reading. wp --allow-root option update blog_public 0 -# Install Query Monitor plugin -# https://wordpress.org/plugins/query-monitor/ -wp --allow-root plugin install query-monitor --activate - -# Install Core Control plugin -# https://wordpress.org/plugins/core-control/ -wp --allow-root plugin install core-control --activate - -# Install WP-Control -# https://wordpress.org/plugins/wp-crontrol/ -wp --allow-root plugin install wp-crontrol --activate - -# Install Gutenberg -# https://wordpress.org/plugins/gutenberg/ -wp --allow-root plugin install gutenberg --activate +if [ "$COMPOSE_PROJECT_NAME" == "dev" ] ; then + # Install Query Monitor plugin + # https://wordpress.org/plugins/query-monitor/ + wp --allow-root plugin install query-monitor --activate + + # Install Core Control plugin + # https://wordpress.org/plugins/core-control/ + wp --allow-root plugin install core-control --activate + + # Install WP-Control + # https://wordpress.org/plugins/wp-crontrol/ + wp --allow-root plugin install wp-crontrol --activate + + # Install Gutenberg + # https://wordpress.org/plugins/gutenberg/ + wp --allow-root plugin install gutenberg --activate +fi # Activate Jetpack wp --allow-root plugin activate jetpack diff --git a/tools/docker/bin/run.sh b/tools/docker/bin/run.sh index 233bdbce145ab..984b0ebd0a61f 100755 --- a/tools/docker/bin/run.sh +++ b/tools/docker/bin/run.sh @@ -94,8 +94,9 @@ for DIR in /usr/local/src/jetpack-monorepo/projects/plugins/*; do done # Symlink jetpack into wordpress-develop for WP >= 5.6-beta1 -if [ ! -e /tmp/wordpress-develop/tests/phpunit/data/plugins/jetpack ]; then - ln -s /var/www/html/wp-content/plugins/jetpack /tmp/wordpress-develop/tests/phpunit/data/plugins/jetpack +WP_TESTS_JP_DIR="/tmp/wordpress-develop/tests/phpunit/data/plugins/jetpack" +if [ ! -L $WP_TESTS_JP_DIR ] || [ ! -e $WP_TESTS_JP_DIR ]; then + ln -s /var/www/html/wp-content/plugins/jetpack $WP_TESTS_JP_DIR fi # Add a PsySH dependency to wp-cli diff --git a/tools/docker/data/mysql/.gitkeep b/tools/docker/data/mysql/.gitkeep deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/tools/docker/docker-compose.dev.yml b/tools/docker/docker-compose.dev.yml new file mode 100644 index 0000000000000..944f82a91c372 --- /dev/null +++ b/tools/docker/docker-compose.dev.yml @@ -0,0 +1,37 @@ +version: '3.3' + +services: + phpmyadmin: + # container_name: jetpack_phpmyadmin + image: phpmyadmin/phpmyadmin:latest + links: + - db:mysql + ports: + - 8181:80 + environment: + MYSQL_USERNAME: '${MYSQL_USER:-wordpress}' + MYSQL_ROOT_PASSWORD: '${MYSQL_ROOT_PASSWORD:-wordpress}' + + ## SMTP Server + Web Interface for viewing and testing emails during development. + ## http://maildev.github.io/maildev/ + maildev: + image: maildev/maildev + # container_name: maildev + ports: + - '${PORT_MAILDEV:-1080}:80' + - '${PORT_SMTP:-25}:25' + + ## SFTP server running at localhost:1022 + sftp: + # container_name: jetpack_sftp + image: atmoz/sftp + volumes: + ## WordPress and its plugins and themes should be defined in docker/compose-volumes.yml{.sample}, not here! + ## That avoids having to define them both here and in the "wordpress" service. + - dockerdirectory:/usr/local/src/jetpack-monorepo/tools/docker + - ./data/ssh.keys:/home/wordpress/.ssh/keys:ro + ports: + - '${PORT_SFTP:-1022}:22' + env_file: + - ./default.env + - ./.env diff --git a/tools/docker/docker-compose.yml b/tools/docker/docker-compose.yml index 44a3f018fadfe..d21822848d8ff 100644 --- a/tools/docker/docker-compose.yml +++ b/tools/docker/docker-compose.yml @@ -1,6 +1,5 @@ version: '3.3' - volumes: ## Kludge for not having the ./docker directory bound recursively dockerdirectory: @@ -10,83 +9,39 @@ services: ## We map a local directory (data/mysql) so we can have the mysql data locally ## and reuse it if we need to remove containers and images for rebuilding from scratch. db: - container_name: jetpack_mysql image: mysql:5.7 volumes: - - ./data/mysql:/var/lib/mysql - - ./logs/mysql:/var/log/mysql + - ./data/${COMPOSE_PROJECT_NAME}_mysql:/var/lib/mysql + - ./logs/${COMPOSE_PROJECT_NAME}/mysql:/var/log/mysql - ./config/mysql.conf:/etc/mysql/conf.d/docker.cnf - restart: always env_file: - default.env - .env - phpmyadmin: - container_name: jetpack_phpmyadmin - image: phpmyadmin/phpmyadmin:latest - links: - - db:mysql - ports: - - 8181:80 - environment: - MYSQL_USERNAME: "${MYSQL_USER:-wordpress}" - MYSQL_ROOT_PASSWORD: "${MYSQL_ROOT_PASSWORD:-wordpress}" - restart: always - - ## SMTP Server + Web Interface for viewing and testing emails during development. - ## http://maildev.github.io/maildev/ - maildev: - image: maildev/maildev - container_name: maildev - restart: always - ports: - - "${PORT_MAILDEV:-1080}:80" - - "${PORT_SMTP:-25}:25" - - ## SFTP server running at localhost:1022 - sftp: - container_name: jetpack_sftp - image: atmoz/sftp - volumes: - ## WordPress and its plugins and themes should be defined in docker/compose-volumes.yml{.sample}, not here! - ## That avoids having to define them both here and in the "wordpress" service. - - dockerdirectory:/usr/local/src/jetpack-monorepo/tools/docker - - ./data/ssh.keys:/home/wordpress/.ssh/keys:ro - ports: - - "${PORT_SFTP:-1022}:22" - env_file: - - ./default.env - - ./.env - ## - The container wordpress is a very basic but custom container with WordPress and all of the tools we need ## for development. ## - The container will be named jetpack_wordpress for easy reference when running docker/docker-compose commands ## ## Here we map the following: - ## - The local root directory (with Jetpack source code) into the container's directory for WordPress plugins - ## - The docker/mu-plugins directory you can put custom code that gets loaded with WordPress ## - The docker/wordpress-develop directory where we'll get WordPress source code with unit tests ## - The docker/wordpress directory so we can have Wordpress source code modifiable from the host file system ## - The docker/logs/apache2 directory so we can access Apache log files directly from the host file system ## - The docker/logs/php directory so we can access PHP log files directly from the host file system ## - The docker/bin directory for provisioning scripts wordpress: - container_name: jetpack_wordpress depends_on: - db - - maildev image: automattic/jetpack-wordpress-dev:latest volumes: ## WordPress and its plugins and themes should be defined in docker/compose-volumes.yml{.sample}, not here! ## That avoids having to define them both here and in the "sftp" service. - dockerdirectory:/usr/local/src/jetpack-monorepo/tools/docker - ./wordpress-develop:/tmp/wordpress-develop - - ./logs/apache2/:/var/log/apache2 - - ./logs/php:/var/log/php + - ./logs/${COMPOSE_PROJECT_NAME}/apache2/:/var/log/apache2 + - ./logs/${COMPOSE_PROJECT_NAME}/php:/var/log/php - ./bin:/var/scripts ports: - - "${PORT_WORDPRESS:-80}:80" - restart: always + - '${PORT_WORDPRESS:-80}:80' env_file: - default.env - .env