From 0c989b217976b2a3dde744f9946dfa93bc16fc12 Mon Sep 17 00:00:00 2001 From: Matthew Batchelder Date: Wed, 24 Jun 2020 13:27:47 -0400 Subject: [PATCH 01/17] Separate poolable commands from realtime commands The support of parallelized processes inadvertently broke the commands that should have been interactive (such as `tric shell`). This changeset brings back the approach that we had with realtime command execution and moves the new forking/proc process approach to some functions geared toward passivity. Basically, any command that gets pooled will be executed passively (with just output). All other commands will be executed in realtime. :movie_camera: http://p.tri.be/ULDtze --- src/docker.php | 31 ++++++++++++++++++++++++++++--- src/process.php | 24 +++++++++++++++++++++++- src/tric.php | 13 ++++++++++++- 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/src/docker.php b/src/docker.php index 55e60c9..e03409f 100644 --- a/src/docker.php +++ b/src/docker.php @@ -164,10 +164,11 @@ function tric_stack_array() { * Executes a docker-compose command in real time, printing the output as produced by the command. * * @param array $options A list of options to initialize the wrapper. + * @param bool $is_realtime Whether the command should be run in real time (true) or passively (false). * * @return \Closure A closure that will run the process in real time and return the process exit status. */ -function docker_compose_realtime( array $options = [] ) { +function docker_compose_process( array $options = [], $is_realtime = true ) { setup_id(); $is_ci = is_ci(); @@ -182,7 +183,7 @@ function docker_compose_realtime( array $options = [] ) { $host_ip = host_ip( 'Linux' ); } - return static function ( array $command = [], $prefix = null ) use ( $options, $host_ip, $is_ci ) { + return static function ( array $command = [], $prefix = null ) use ( $options, $host_ip, $is_ci, $is_realtime ) { $command = 'docker-compose ' . implode( ' ', $options ) . ' ' . implode( ' ', $command ); if ( ! empty( $host_ip ) ) { @@ -195,6 +196,30 @@ function docker_compose_realtime( array $options = [] ) { $command = 'XDE=0 ' . $command; } - return process_realtime( $command, $prefix ); + return $is_realtime ? process_realtime( $command ) : process_passive( $command, $prefix ); }; } + +/** + * Executes a docker-compose command in passive mode, printing the output as produced by the command. + * + * This approach is used for commands that can be run in a parallel or forked process without interactivity. + * + * @param array $options A list of options to initialize the wrapper. + * + * @return \Closure A closure that will run the process in real time and return the process exit status. + */ +function docker_compose_passive( array $options = [] ) { + return docker_compose_process( $options, false ); +} + +/** + * Executes a docker-compose command in real time, printing the output as produced by the command. + * + * @param array $options A list of options to initialize the wrapper. + * + * @return \Closure A closure that will run the process in real time and return the process exit status. + */ +function docker_compose_realtime( array $options = [] ) { + return docker_compose_process( $options, true ); +} diff --git a/src/process.php b/src/process.php index 2b719e0..b6ae7bf 100644 --- a/src/process.php +++ b/src/process.php @@ -39,7 +39,29 @@ function process( $command ) { * * @return int The process exit status, `0` means ok. */ -function process_realtime( $command, $prefix = null ) { +function process_realtime( $command ) { + debug( "Executing command: {$command}" ); + + echo PHP_EOL; + + setup_terminal(); + + $clean_command = escapeshellcmd( $command ); + + passthru( $clean_command, $status ); + + return (int) $status; +} + +/** + * Runs a process in realtime, displaying its output. + * + * @param string $command The command to run. + * @param string|null $prefix The prefix to place before all output. + * + * @return int The process exit status, `0` means ok. + */ +function process_passive( $command, $prefix = null ) { debug( "Executing command: {$command}" ); echo PHP_EOL; diff --git a/src/tric.php b/src/tric.php index f622d76..67d4637 100644 --- a/src/tric.php +++ b/src/tric.php @@ -416,6 +416,17 @@ function github_company_handle() { return ! empty( $handle ) ? trim( $handle ) : 'moderntribe'; } +/** + * Runs a process in passive mode in tric stack and returns the exit status. + * + * This approach is used when running commands that can be done in parallel or forked processes. + * + * @return \Closure The process closure to start a real-time process using tric stack. + */ +function tric_passive() { + return docker_compose_passive( tric_stack_array() ); +} + /** * Runs a process in tric stack and returns the exit status. * @@ -765,7 +776,7 @@ function build_command_pool( string $base_command, array $command, array $sub_di $prefix = "{$base_command}:" . yellow( $target ); } - $status = tric_realtime()( array_merge( [ 'run', '--rm', $base_command ], $command ), $prefix ); + $status = tric_passive()( array_merge( [ 'run', '--rm', $base_command ], $command ), $prefix ); if ( 'target' !== $target ) { tric_switch_target( $using ); From 65bb74dfca9671d4f7461aadf3442fa039e5f771 Mon Sep 17 00:00:00 2001 From: Matthew Batchelder Date: Wed, 24 Jun 2020 13:33:52 -0400 Subject: [PATCH 02/17] Fix a docblock --- src/process.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/process.php b/src/process.php index b6ae7bf..87f6c80 100644 --- a/src/process.php +++ b/src/process.php @@ -34,6 +34,8 @@ function process( $command ) { /** * Runs a process in realtime, displaying its output. * + * Realtime processes are done without forking, have no need of prefixes, and support interactivity. + * * @param string $command The command to run. * @param string|null $prefix The prefix to place before all output. * @@ -54,7 +56,9 @@ function process_realtime( $command ) { } /** - * Runs a process in realtime, displaying its output. + * Runs a process passively, displaying its output. + * + * Passive processes are ones that only need to dump their output. * * @param string $command The command to run. * @param string|null $prefix The prefix to place before all output. From 653027132b7ca82d1675eef89cb75aa26a1ed395 Mon Sep 17 00:00:00 2001 From: Matthew Batchelder Date: Wed, 24 Jun 2020 17:53:19 -0400 Subject: [PATCH 03/17] Prompt user to update if tric version mismatches current build version This adds a new non-git tracked file called `.build-version` that tracks the version of `tric` when the containers were last updated. This way, upon updating `tric`, if there is a version mismatch, the user is prompted to update their containers. The prompt is _not_ triggered if the user does not have a `.env.tric.run` file as it will assume the user is running commands for the first time. **Additionally:** I've added the output of the npm error log if one gets generated (sanse the saveTree lines). It is that change that triggered me to want to have a prompt because I was stumped for 2 minutes or so before I remembered I needed to rebuild the container stack. :movie_camera: http://p.tri.be/bYtE6L --- .gitignore | 3 +++ containers/npm/docker-entrypoint.sh | 11 ++++++++ src/scaffold.php | 1 + src/tric.php | 42 +++++++++++++++++++++++++++++ src/utils.php | 5 ++++ tric | 6 +++++ 6 files changed, 68 insertions(+) diff --git a/.gitignore b/.gitignore index 5d79395..0a2df5e 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ _plugins # Any .env.tric.* file created to override the tric cli tool configuration or to configure the runs. .env.tric.local .env.tric.run + +# Any .build-version file created by the tric cli tool. +.build-version diff --git a/containers/npm/docker-entrypoint.sh b/containers/npm/docker-entrypoint.sh index 62fb168..65949f0 100644 --- a/containers/npm/docker-entrypoint.sh +++ b/containers/npm/docker-entrypoint.sh @@ -6,3 +6,14 @@ test "${FIXUID:-1}" != "0" && eval "$( fixuid )" npm --prefix /project "$@" + +# Output error logs if present. +if compgen -G "/home/node/.npm/_logs/*.log" > /dev/null; then + echo "---------------------------------------" + echo "Error log found. Here are the contents (excluding the overly verbose saveTree lines):" + echo "---------------------------------------" + cat /home/node/.npm/_logs/*.log | grep -v "saveTree" + echo "---------------------------------------" + echo "End of error log" + echo "---------------------------------------" +fi diff --git a/src/scaffold.php b/src/scaffold.php index dcc032b..760f536 100644 --- a/src/scaffold.php +++ b/src/scaffold.php @@ -113,6 +113,7 @@ function write_tric_env_file( $plugin_path ) { $plugin_env .= "\n# We're using Docker to run the tests.\nUSING_CONTAINERS=1\n"; $file = $plugin_path . '/.env.testing.tric'; + $put = file_put_contents( $file, $plugin_env ); if ( false === $put ) { diff --git a/src/tric.php b/src/tric.php index f622d76..8950ce9 100644 --- a/src/tric.php +++ b/src/tric.php @@ -447,9 +447,17 @@ function teardown_stack() { function rebuild_stack() { echo "Building the stack images...\n\n"; tric_realtime()( [ 'build-stack' ] ); + write_build_version(); echo light_cyan( "\nStack images built.\n\n" ); } +/** + * Write the current CLI_VERSION to the build-version file + */ +function write_build_version() { + file_put_contents( TRIC_ROOT_DIR . '/.build-version', CLI_VERSION ); +} + /** * Prints information about tric tool. */ @@ -918,3 +926,37 @@ function switch_plugin_branch( $branch, $plugin = null ) { exit( 1 ); } } + +/** + * If tric stack is out of date, prompt for an execution of tric update. + */ +function maybe_prompt_for_update() { + $build_version = '0.0.1'; + $cli_version = CLI_VERSION; + + if ( file_exists( TRIC_ROOT_DIR . '/.build-version' ) ) { + $build_version = file_get_contents( TRIC_ROOT_DIR . '/.build-version' ); + } + + // If there isn't a .env.tric.run, this is likely a fresh install. Bail. + if ( ! file_exists( TRIC_ROOT_DIR . '/.env.tric.run' ) ) { + return; + } + + // If the version of the CLI is the same as the most recently built version, bail. + if ( version_compare( $build_version, $cli_version, '=' ) ) { + return; + } + + echo magenta( "\n****************************************************************\n\n" ); + echo yellow( " ____________ ____ __\n" ); + echo yellow( " | ____\ \ / / | |\n" ); + echo yellow( " | |__ \ \/ / | |\n" ); + echo yellow( " | __| \_ _/ | |\n" ); + echo yellow( " | | | | | |\n" ); + echo yellow( " |__| |__| |__|\n\n" ); + echo magenta( "Your tric containers are not up to date with the latest version.\n" ); + echo magenta( " To update, please run:\n\n" ); + echo yellow( " tric update\n\n" ); + echo magenta( "****************************************************************\n" ); +} diff --git a/src/utils.php b/src/utils.php index c5c82df..46578e1 100644 --- a/src/utils.php +++ b/src/utils.php @@ -407,6 +407,11 @@ function write_env_file( $file, array $lines = [], $update = false ) { return "{$key}={$value}"; }, array_keys( $new_lines ), $new_lines ) ); + // If this is the first time creating the .env.tric.run file, assume this is the first run and place the CLI version in `.build-version`. + if ( false !== strpos( $file, '.env.tric.run' ) && ! file_exists( $file ) ) { + write_build_version(); + } + $put = file_put_contents( $file, $data ); if ( false === $put ) { diff --git a/tric b/tric index 124688b..22f7253 100755 --- a/tric +++ b/tric @@ -14,6 +14,7 @@ use function Tribe\Test\args; use function Tribe\Test\colorize; use function Tribe\Test\root; use function Tribe\Test\light_cyan; +use function Tribe\Test\maybe_prompt_for_update; use function Tribe\Test\setup_tric_env; // Set up the argument parsing function. @@ -90,10 +91,15 @@ $subcommand = $args( 'subcommand', 'help' ); $cli_name = basename( $argv[0] ); +if ( ! in_array( $subcommand, [ 'help', 'update'] ) ) { + maybe_prompt_for_update(); +} + switch ( $subcommand ) { default: case 'help': echo $help_message; + maybe_prompt_for_update(); break; case 'airplane-mode': case 'build-prompt': From d825e873c80238dfd9f75b612906da4db73cf3c5 Mon Sep 17 00:00:00 2001 From: Matthew Batchelder Date: Wed, 24 Jun 2020 17:59:33 -0400 Subject: [PATCH 04/17] Removing stray linebreak that I had added --- src/scaffold.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/scaffold.php b/src/scaffold.php index 760f536..dcc032b 100644 --- a/src/scaffold.php +++ b/src/scaffold.php @@ -113,7 +113,6 @@ function write_tric_env_file( $plugin_path ) { $plugin_env .= "\n# We're using Docker to run the tests.\nUSING_CONTAINERS=1\n"; $file = $plugin_path . '/.env.testing.tric'; - $put = file_put_contents( $file, $plugin_env ); if ( false === $put ) { From a1a173d7c2a8e576193e2a426d4c70b9543adb8f Mon Sep 17 00:00:00 2001 From: Matthew Batchelder Date: Wed, 24 Jun 2020 18:25:56 -0400 Subject: [PATCH 05/17] Updating version to 0.3.0 --- tric | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tric b/tric index 124688b..55f3b9f 100755 --- a/tric +++ b/tric @@ -23,7 +23,7 @@ $args = args( [ ] ); $cli_name = basename( $argv[0] ); -const CLI_VERSION = '0.2.0'; +const CLI_VERSION = '0.3.0'; $cli_header = implode( ' - ', [ light_cyan( $cli_name ) . ' version ' . light_cyan( CLI_VERSION ), From edd2bfb8b28dd58c4340b0795a50042d35c5c49d Mon Sep 17 00:00:00 2001 From: Matthew Batchelder Date: Wed, 24 Jun 2020 18:33:13 -0400 Subject: [PATCH 06/17] Adding changelog.md --- changelog.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 changelog.md diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..9953608 --- /dev/null +++ b/changelog.md @@ -0,0 +1,25 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.2.0] - 2020-06-24 +### Added + +- Added phpcs and phpcbf commands. + +### Changed + +- Added parallel processing of commands. +- Changed `tric build` to `tric build-stack`. + +## [0.1.1] - 2020-05-26 +### Changed + +- Ensure `.htaccess` file is present in `_wordpress`. + +## [0.1.0] - 2020-05-25 +### Added + +- Initial version From af8fe68a551a76537b52f647e96aa514adeb5fba Mon Sep 17 00:00:00 2001 From: Matthew Batchelder Date: Wed, 24 Jun 2020 18:36:03 -0400 Subject: [PATCH 07/17] Adding changelog entry --- changelog.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/changelog.md b/changelog.md index 9953608..db853a4 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.0] - TBD +### Changed + +- Separated out poolable (passive) command functions from realtime command functions to prevent issues with interactivity. + ## [0.2.0] - 2020-06-24 ### Added From 2b76372c00490cf891670250429469b652c98e7f Mon Sep 17 00:00:00 2001 From: Matthew Batchelder Date: Wed, 24 Jun 2020 18:37:36 -0400 Subject: [PATCH 08/17] Adding version heading --- changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/changelog.md b/changelog.md index 9953608..f4235cf 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.0] - TBD + ## [0.2.0] - 2020-06-24 ### Added From bb6e9bde1cf49af4f7688d35a4b8ffe3f59da97e Mon Sep 17 00:00:00 2001 From: Matthew Batchelder Date: Wed, 24 Jun 2020 18:40:17 -0400 Subject: [PATCH 09/17] Add changelog entry --- changelog.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index f4235cf..3dc5d84 100644 --- a/changelog.md +++ b/changelog.md @@ -5,15 +5,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [0.3.0] - TBD +### Added + +- Prompt to `tric update` when container build version are out of sync from the tric version. +- Output npm error log when one is generated. ## [0.2.0] - 2020-06-24 ### Added - Added phpcs and phpcbf commands. +- Added parallel processing of commands. ### Changed -- Added parallel processing of commands. - Changed `tric build` to `tric build-stack`. ## [0.1.1] - 2020-05-26 From 3dced96232bb43972fcc2eed79d21f722ba5ee2e Mon Sep 17 00:00:00 2001 From: Matthew Batchelder Date: Wed, 24 Jun 2020 22:29:10 -0400 Subject: [PATCH 10/17] Allow npm install on subdirectory use targets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The problem with `npm install` on plugin subdirectories was that the presence of a `.git/` directory was _required_ to perform the git commands that npm was executing. Because `common/` is a submodule, it doesn't have a `.git/` directory...so when we were mounting common as `/project`, the `.git/` dir was not found, even when traversing up the tree. The solution was to—when running `tric use` against a submoduled subdirectory—set the parent directory as the volume and then `cd` into `common/` in the `docker-entrypoint.sh`. :movie_camera: http://p.tri.be/7dw7hH --- changelog.md | 3 +++ containers/npm/docker-entrypoint.sh | 15 ++++++++++++++- src/tric.php | 18 ++++++++++++++---- src/wordpress.php | 11 ++++++++++- tric-stack.yml | 7 ++++--- 5 files changed, 45 insertions(+), 9 deletions(-) diff --git a/changelog.md b/changelog.md index f4235cf..36bc3e4 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [0.3.0] - TBD +### Changed + +- Adjust pathing of subdirectories within the tric stack so that npm can find a `.git` directory when performing `npm install`. ## [0.2.0] - 2020-06-24 ### Added diff --git a/containers/npm/docker-entrypoint.sh b/containers/npm/docker-entrypoint.sh index 62fb168..972848c 100644 --- a/containers/npm/docker-entrypoint.sh +++ b/containers/npm/docker-entrypoint.sh @@ -5,4 +5,17 @@ # If the `FIXUID` env var is set to `1`, default value, then fix UIDs. test "${FIXUID:-1}" != "0" && eval "$( fixuid )" -npm --prefix /project "$@" +cd /project/${TRIC_CURRENT_PROJECT_SUBDIR} + +npm "$@" + +# Output error logs if present. +if compgen -G "/home/node/.npm/_logs/*.log" > /dev/null; then + echo "---------------------------------------" + echo "Error log found. Here are the contents (excluding the overly verbose saveTree lines):" + echo "---------------------------------------" + cat /home/node/.npm/_logs/*.log | grep -v "saveTree" + echo "---------------------------------------" + echo "End of error log" + echo "---------------------------------------" +fi diff --git a/src/tric.php b/src/tric.php index f622d76..85db9fb 100644 --- a/src/tric.php +++ b/src/tric.php @@ -178,16 +178,20 @@ function setup_tric_env( $root_dir ) { * return value will always be a non empty string. */ function tric_target( $require = true ) { - $using = getenv( 'TRIC_CURRENT_PROJECT' ); + $using = getenv( 'TRIC_CURRENT_PROJECT' ); + $using_subdir = getenv( 'TRIC_CURRENT_PROJECT_SUBDIR' ); + $using_full = $using . ( $using_subdir ? '/' . $using_subdir : '' ); + if ( $require ) { - return $using; + return $using_full; } - if ( empty( $using ) ) { + + if ( empty( $using_full ) ) { echo magenta( "Use target not set; use the 'use' sub-command to set it.\n" ); exit( 1 ); } - return trim( $using ); + return trim( $using_full ); } /** @@ -199,14 +203,20 @@ function tric_switch_target( $target ) { $root = root(); $run_settings_file = "{$root}/.env.tric.run"; $target_relative_path = ''; + $subdir = ''; if ( tric_here_is_site() ) { $target_relative_path = get_target_relative_path( $target ); } + if ( false !== strpos( $target, '/' ) ) { + list( $target, $subdir ) = explode( '/', $target ); + } + $env_values = [ 'TRIC_CURRENT_PROJECT' => $target, 'TRIC_CURRENT_PROJECT_RELATIVE_PATH' => $target_relative_path, + 'TRIC_CURRENT_PROJECT_SUBDIR' => $subdir, ]; write_env_file( $run_settings_file, $env_values, true ); diff --git a/src/wordpress.php b/src/wordpress.php index c526e3b..df7bd67 100644 --- a/src/wordpress.php +++ b/src/wordpress.php @@ -81,7 +81,7 @@ static function ( SplFileInfo $file ) { } ); - $allowed_subdirs = [ 'common' ]; + $allowed_subdirs = get_allowed_use_subdirectories(); foreach ( iterator_to_array( $dir ) as $key => $value ) { $basename = basename( $key ); $dirs[ $basename ] = $value; @@ -95,3 +95,12 @@ static function ( SplFileInfo $file ) { return $dirs; } + +/** + * Returns the list of allowed subdirectories for tric use. + * + * @return array Allowed subdirectories for use. + */ +function get_allowed_use_subdirectories() { + return [ 'common' ]; +} diff --git a/tric-stack.yml b/tric-stack.yml index 84547f7..4d16580 100644 --- a/tric-stack.yml +++ b/tric-stack.yml @@ -146,7 +146,7 @@ services: # XDH=$(ip route | grep docker0 | awk '{print $9}') docker-compose ... XDEBUG_CONFIG: "idekey=${XDK:-tric} remote_enable=${XDE:-1} remote_host=${XDH:-host.docker.internal} remote_port=${XDP:-9001}" # Move to the target directory before running the command from the plugins directory. - CODECEPTION_PROJECT_DIR: /var/www/html/wp-content/plugins/${TRIC_CURRENT_PROJECT:-test} + CODECEPTION_PROJECT_DIR: /var/www/html/wp-content/plugins/${TRIC_CURRENT_PROJECT:-test}/${TRIC_CURRENT_PROJECT_SUBDIR} # When running the container in shell mode (using the tric `shell` command), then use this CC configuration. CODECEPTION_SHELL_CONFIG: "-c codeception.tric.yml" # After the WordPress container comes online, wait a further 3s to give it some boot-up time. @@ -180,7 +180,7 @@ services: FIXUID: "${FIXUID:-1}" volumes: # Set the current plugin as project. - - ${TRIC_PLUGINS_DIR}/${TRIC_CURRENT_PROJECT:-test}:/project:cached + - ${TRIC_PLUGINS_DIR}/${TRIC_CURRENT_PROJECT:-test}/${TRIC_CURRENT_PROJECT_SUBDIR}:/project:cached # Share SSH keys with the container to pull from private repositories. - ${DOCKER_RUN_SSH_AUTH_SOCK}:/ssh-agent:ro @@ -191,6 +191,7 @@ services: user: "${DOCKER_RUN_UID:-}:${DOCKER_RUN_GID:-}" environment: FIXUID: ${FIXUID:-1} + TRIC_CURRENT_PROJECT_SUBDIR: ${TRIC_CURRENT_PROJECT_SUBDIR} volumes: # Set the current plugin as project. - ${TRIC_PLUGINS_DIR}/${TRIC_CURRENT_PROJECT:-test}:/project:cached @@ -205,7 +206,7 @@ services: working_dir: /project volumes: # Set the current plugin as project. - - ${TRIC_PLUGINS_DIR}/${TRIC_CURRENT_PROJECT:-test}:/project:cached + - ${TRIC_PLUGINS_DIR}/${TRIC_CURRENT_PROJECT:-test}/${TRIC_CURRENT_PROJECT_SUBDIR}:/project:cached # Share SSH keys with the container to pull from private repositories. - ${DOCKER_RUN_SSH_AUTH_SOCK}:/ssh-agent:ro From 98cb5746ea606151d70c00e5844fa116d427b208 Mon Sep 17 00:00:00 2001 From: Matthew Batchelder Date: Wed, 24 Jun 2020 22:35:40 -0400 Subject: [PATCH 11/17] Revert "Allow npm install on subdirectory use targets" This reverts commit 3dced96232bb43972fcc2eed79d21f722ba5ee2e. --- changelog.md | 3 --- containers/npm/docker-entrypoint.sh | 15 +-------------- src/tric.php | 18 ++++-------------- src/wordpress.php | 11 +---------- tric-stack.yml | 7 +++---- 5 files changed, 9 insertions(+), 45 deletions(-) diff --git a/changelog.md b/changelog.md index 36bc3e4..f4235cf 100644 --- a/changelog.md +++ b/changelog.md @@ -5,9 +5,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [0.3.0] - TBD -### Changed - -- Adjust pathing of subdirectories within the tric stack so that npm can find a `.git` directory when performing `npm install`. ## [0.2.0] - 2020-06-24 ### Added diff --git a/containers/npm/docker-entrypoint.sh b/containers/npm/docker-entrypoint.sh index 972848c..62fb168 100644 --- a/containers/npm/docker-entrypoint.sh +++ b/containers/npm/docker-entrypoint.sh @@ -5,17 +5,4 @@ # If the `FIXUID` env var is set to `1`, default value, then fix UIDs. test "${FIXUID:-1}" != "0" && eval "$( fixuid )" -cd /project/${TRIC_CURRENT_PROJECT_SUBDIR} - -npm "$@" - -# Output error logs if present. -if compgen -G "/home/node/.npm/_logs/*.log" > /dev/null; then - echo "---------------------------------------" - echo "Error log found. Here are the contents (excluding the overly verbose saveTree lines):" - echo "---------------------------------------" - cat /home/node/.npm/_logs/*.log | grep -v "saveTree" - echo "---------------------------------------" - echo "End of error log" - echo "---------------------------------------" -fi +npm --prefix /project "$@" diff --git a/src/tric.php b/src/tric.php index 85db9fb..f622d76 100644 --- a/src/tric.php +++ b/src/tric.php @@ -178,20 +178,16 @@ function setup_tric_env( $root_dir ) { * return value will always be a non empty string. */ function tric_target( $require = true ) { - $using = getenv( 'TRIC_CURRENT_PROJECT' ); - $using_subdir = getenv( 'TRIC_CURRENT_PROJECT_SUBDIR' ); - $using_full = $using . ( $using_subdir ? '/' . $using_subdir : '' ); - + $using = getenv( 'TRIC_CURRENT_PROJECT' ); if ( $require ) { - return $using_full; + return $using; } - - if ( empty( $using_full ) ) { + if ( empty( $using ) ) { echo magenta( "Use target not set; use the 'use' sub-command to set it.\n" ); exit( 1 ); } - return trim( $using_full ); + return trim( $using ); } /** @@ -203,20 +199,14 @@ function tric_switch_target( $target ) { $root = root(); $run_settings_file = "{$root}/.env.tric.run"; $target_relative_path = ''; - $subdir = ''; if ( tric_here_is_site() ) { $target_relative_path = get_target_relative_path( $target ); } - if ( false !== strpos( $target, '/' ) ) { - list( $target, $subdir ) = explode( '/', $target ); - } - $env_values = [ 'TRIC_CURRENT_PROJECT' => $target, 'TRIC_CURRENT_PROJECT_RELATIVE_PATH' => $target_relative_path, - 'TRIC_CURRENT_PROJECT_SUBDIR' => $subdir, ]; write_env_file( $run_settings_file, $env_values, true ); diff --git a/src/wordpress.php b/src/wordpress.php index df7bd67..c526e3b 100644 --- a/src/wordpress.php +++ b/src/wordpress.php @@ -81,7 +81,7 @@ static function ( SplFileInfo $file ) { } ); - $allowed_subdirs = get_allowed_use_subdirectories(); + $allowed_subdirs = [ 'common' ]; foreach ( iterator_to_array( $dir ) as $key => $value ) { $basename = basename( $key ); $dirs[ $basename ] = $value; @@ -95,12 +95,3 @@ static function ( SplFileInfo $file ) { return $dirs; } - -/** - * Returns the list of allowed subdirectories for tric use. - * - * @return array Allowed subdirectories for use. - */ -function get_allowed_use_subdirectories() { - return [ 'common' ]; -} diff --git a/tric-stack.yml b/tric-stack.yml index 4d16580..84547f7 100644 --- a/tric-stack.yml +++ b/tric-stack.yml @@ -146,7 +146,7 @@ services: # XDH=$(ip route | grep docker0 | awk '{print $9}') docker-compose ... XDEBUG_CONFIG: "idekey=${XDK:-tric} remote_enable=${XDE:-1} remote_host=${XDH:-host.docker.internal} remote_port=${XDP:-9001}" # Move to the target directory before running the command from the plugins directory. - CODECEPTION_PROJECT_DIR: /var/www/html/wp-content/plugins/${TRIC_CURRENT_PROJECT:-test}/${TRIC_CURRENT_PROJECT_SUBDIR} + CODECEPTION_PROJECT_DIR: /var/www/html/wp-content/plugins/${TRIC_CURRENT_PROJECT:-test} # When running the container in shell mode (using the tric `shell` command), then use this CC configuration. CODECEPTION_SHELL_CONFIG: "-c codeception.tric.yml" # After the WordPress container comes online, wait a further 3s to give it some boot-up time. @@ -180,7 +180,7 @@ services: FIXUID: "${FIXUID:-1}" volumes: # Set the current plugin as project. - - ${TRIC_PLUGINS_DIR}/${TRIC_CURRENT_PROJECT:-test}/${TRIC_CURRENT_PROJECT_SUBDIR}:/project:cached + - ${TRIC_PLUGINS_DIR}/${TRIC_CURRENT_PROJECT:-test}:/project:cached # Share SSH keys with the container to pull from private repositories. - ${DOCKER_RUN_SSH_AUTH_SOCK}:/ssh-agent:ro @@ -191,7 +191,6 @@ services: user: "${DOCKER_RUN_UID:-}:${DOCKER_RUN_GID:-}" environment: FIXUID: ${FIXUID:-1} - TRIC_CURRENT_PROJECT_SUBDIR: ${TRIC_CURRENT_PROJECT_SUBDIR} volumes: # Set the current plugin as project. - ${TRIC_PLUGINS_DIR}/${TRIC_CURRENT_PROJECT:-test}:/project:cached @@ -206,7 +205,7 @@ services: working_dir: /project volumes: # Set the current plugin as project. - - ${TRIC_PLUGINS_DIR}/${TRIC_CURRENT_PROJECT:-test}/${TRIC_CURRENT_PROJECT_SUBDIR}:/project:cached + - ${TRIC_PLUGINS_DIR}/${TRIC_CURRENT_PROJECT:-test}:/project:cached # Share SSH keys with the container to pull from private repositories. - ${DOCKER_RUN_SSH_AUTH_SOCK}:/ssh-agent:ro From 484463e9ce5ee485519348969025d35a564da22c Mon Sep 17 00:00:00 2001 From: Matthew Batchelder Date: Wed, 24 Jun 2020 22:36:13 -0400 Subject: [PATCH 12/17] Revert "Revert "Allow npm install on subdirectory use targets"" This reverts commit 98cb5746ea606151d70c00e5844fa116d427b208. --- changelog.md | 3 +++ containers/npm/docker-entrypoint.sh | 15 ++++++++++++++- src/tric.php | 18 ++++++++++++++---- src/wordpress.php | 11 ++++++++++- tric-stack.yml | 7 ++++--- 5 files changed, 45 insertions(+), 9 deletions(-) diff --git a/changelog.md b/changelog.md index f4235cf..36bc3e4 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [0.3.0] - TBD +### Changed + +- Adjust pathing of subdirectories within the tric stack so that npm can find a `.git` directory when performing `npm install`. ## [0.2.0] - 2020-06-24 ### Added diff --git a/containers/npm/docker-entrypoint.sh b/containers/npm/docker-entrypoint.sh index 62fb168..972848c 100644 --- a/containers/npm/docker-entrypoint.sh +++ b/containers/npm/docker-entrypoint.sh @@ -5,4 +5,17 @@ # If the `FIXUID` env var is set to `1`, default value, then fix UIDs. test "${FIXUID:-1}" != "0" && eval "$( fixuid )" -npm --prefix /project "$@" +cd /project/${TRIC_CURRENT_PROJECT_SUBDIR} + +npm "$@" + +# Output error logs if present. +if compgen -G "/home/node/.npm/_logs/*.log" > /dev/null; then + echo "---------------------------------------" + echo "Error log found. Here are the contents (excluding the overly verbose saveTree lines):" + echo "---------------------------------------" + cat /home/node/.npm/_logs/*.log | grep -v "saveTree" + echo "---------------------------------------" + echo "End of error log" + echo "---------------------------------------" +fi diff --git a/src/tric.php b/src/tric.php index f622d76..85db9fb 100644 --- a/src/tric.php +++ b/src/tric.php @@ -178,16 +178,20 @@ function setup_tric_env( $root_dir ) { * return value will always be a non empty string. */ function tric_target( $require = true ) { - $using = getenv( 'TRIC_CURRENT_PROJECT' ); + $using = getenv( 'TRIC_CURRENT_PROJECT' ); + $using_subdir = getenv( 'TRIC_CURRENT_PROJECT_SUBDIR' ); + $using_full = $using . ( $using_subdir ? '/' . $using_subdir : '' ); + if ( $require ) { - return $using; + return $using_full; } - if ( empty( $using ) ) { + + if ( empty( $using_full ) ) { echo magenta( "Use target not set; use the 'use' sub-command to set it.\n" ); exit( 1 ); } - return trim( $using ); + return trim( $using_full ); } /** @@ -199,14 +203,20 @@ function tric_switch_target( $target ) { $root = root(); $run_settings_file = "{$root}/.env.tric.run"; $target_relative_path = ''; + $subdir = ''; if ( tric_here_is_site() ) { $target_relative_path = get_target_relative_path( $target ); } + if ( false !== strpos( $target, '/' ) ) { + list( $target, $subdir ) = explode( '/', $target ); + } + $env_values = [ 'TRIC_CURRENT_PROJECT' => $target, 'TRIC_CURRENT_PROJECT_RELATIVE_PATH' => $target_relative_path, + 'TRIC_CURRENT_PROJECT_SUBDIR' => $subdir, ]; write_env_file( $run_settings_file, $env_values, true ); diff --git a/src/wordpress.php b/src/wordpress.php index c526e3b..df7bd67 100644 --- a/src/wordpress.php +++ b/src/wordpress.php @@ -81,7 +81,7 @@ static function ( SplFileInfo $file ) { } ); - $allowed_subdirs = [ 'common' ]; + $allowed_subdirs = get_allowed_use_subdirectories(); foreach ( iterator_to_array( $dir ) as $key => $value ) { $basename = basename( $key ); $dirs[ $basename ] = $value; @@ -95,3 +95,12 @@ static function ( SplFileInfo $file ) { return $dirs; } + +/** + * Returns the list of allowed subdirectories for tric use. + * + * @return array Allowed subdirectories for use. + */ +function get_allowed_use_subdirectories() { + return [ 'common' ]; +} diff --git a/tric-stack.yml b/tric-stack.yml index 84547f7..4d16580 100644 --- a/tric-stack.yml +++ b/tric-stack.yml @@ -146,7 +146,7 @@ services: # XDH=$(ip route | grep docker0 | awk '{print $9}') docker-compose ... XDEBUG_CONFIG: "idekey=${XDK:-tric} remote_enable=${XDE:-1} remote_host=${XDH:-host.docker.internal} remote_port=${XDP:-9001}" # Move to the target directory before running the command from the plugins directory. - CODECEPTION_PROJECT_DIR: /var/www/html/wp-content/plugins/${TRIC_CURRENT_PROJECT:-test} + CODECEPTION_PROJECT_DIR: /var/www/html/wp-content/plugins/${TRIC_CURRENT_PROJECT:-test}/${TRIC_CURRENT_PROJECT_SUBDIR} # When running the container in shell mode (using the tric `shell` command), then use this CC configuration. CODECEPTION_SHELL_CONFIG: "-c codeception.tric.yml" # After the WordPress container comes online, wait a further 3s to give it some boot-up time. @@ -180,7 +180,7 @@ services: FIXUID: "${FIXUID:-1}" volumes: # Set the current plugin as project. - - ${TRIC_PLUGINS_DIR}/${TRIC_CURRENT_PROJECT:-test}:/project:cached + - ${TRIC_PLUGINS_DIR}/${TRIC_CURRENT_PROJECT:-test}/${TRIC_CURRENT_PROJECT_SUBDIR}:/project:cached # Share SSH keys with the container to pull from private repositories. - ${DOCKER_RUN_SSH_AUTH_SOCK}:/ssh-agent:ro @@ -191,6 +191,7 @@ services: user: "${DOCKER_RUN_UID:-}:${DOCKER_RUN_GID:-}" environment: FIXUID: ${FIXUID:-1} + TRIC_CURRENT_PROJECT_SUBDIR: ${TRIC_CURRENT_PROJECT_SUBDIR} volumes: # Set the current plugin as project. - ${TRIC_PLUGINS_DIR}/${TRIC_CURRENT_PROJECT:-test}:/project:cached @@ -205,7 +206,7 @@ services: working_dir: /project volumes: # Set the current plugin as project. - - ${TRIC_PLUGINS_DIR}/${TRIC_CURRENT_PROJECT:-test}:/project:cached + - ${TRIC_PLUGINS_DIR}/${TRIC_CURRENT_PROJECT:-test}/${TRIC_CURRENT_PROJECT_SUBDIR}:/project:cached # Share SSH keys with the container to pull from private repositories. - ${DOCKER_RUN_SSH_AUTH_SOCK}:/ssh-agent:ro From fbc2b93c76974dbe90af6c5b60d387e06e248095 Mon Sep 17 00:00:00 2001 From: Matthew Batchelder Date: Wed, 24 Jun 2020 22:39:22 -0400 Subject: [PATCH 13/17] Add headings for changelog --- changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/changelog.md b/changelog.md index f4235cf..a71ecf9 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [0.3.0] - TBD +### Added + +### Changed ## [0.2.0] - 2020-06-24 ### Added From 49e9feea5679ff4510dde03217887f3facabf033 Mon Sep 17 00:00:00 2001 From: Matthew Batchelder Date: Wed, 24 Jun 2020 22:53:55 -0400 Subject: [PATCH 14/17] Fix bug where tric update was failing to run `build` on the containers --- src/tric.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tric.php b/src/tric.php index 8950ce9..ffa6f63 100644 --- a/src/tric.php +++ b/src/tric.php @@ -446,7 +446,7 @@ function teardown_stack() { */ function rebuild_stack() { echo "Building the stack images...\n\n"; - tric_realtime()( [ 'build-stack' ] ); + tric_realtime()( [ 'build' ] ); write_build_version(); echo light_cyan( "\nStack images built.\n\n" ); } From f3958d768879c32d8c180d1ee8393d74d88c936e Mon Sep 17 00:00:00 2001 From: Matthew Batchelder Date: Wed, 24 Jun 2020 22:55:47 -0400 Subject: [PATCH 15/17] Add subdirectory env var reference --- .env.tric | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.env.tric b/.env.tric index b1e605a..b4ec16f 100644 --- a/.env.tric +++ b/.env.tric @@ -19,6 +19,8 @@ CLI_VERBOSITY=0 # TRIC_CURRENT_PROJECT=the-events-calendar # When you `here` at the site level, all selected targets via `use` will have a relative path set. # TRIC_CURRENT_PROJECT_RELATIVE_PATH= +# When you `use` on a supported subdirectory of a plugin, this stores the subdirectory name. +#TRIC_CURRENT_PROJECT_SUBDIR= # The GitHub handle of the company to clone plugins from. TRIC_GITHUB_COMPANY_HANDLE=moderntribe From 703ce3ba88c6600c1da2631069f752aea4204d22 Mon Sep 17 00:00:00 2001 From: Matthew Batchelder Date: Wed, 24 Jun 2020 23:21:23 -0400 Subject: [PATCH 16/17] Suppress the fixuid output because it is annoying --- containers/npm/docker-entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/containers/npm/docker-entrypoint.sh b/containers/npm/docker-entrypoint.sh index 972848c..3e4da13 100644 --- a/containers/npm/docker-entrypoint.sh +++ b/containers/npm/docker-entrypoint.sh @@ -3,7 +3,7 @@ # This file is just a proxy to call the `npm` binary that will, but, take care of fixing file mode issues before. # If the `FIXUID` env var is set to `1`, default value, then fix UIDs. -test "${FIXUID:-1}" != "0" && eval "$( fixuid )" +test "${FIXUID:-1}" != "0" && eval "$( fixuid > /dev/null 2>&1 )" cd /project/${TRIC_CURRENT_PROJECT_SUBDIR} From a227b8488b3df9075fc763dde3328f8b0a9dab25 Mon Sep 17 00:00:00 2001 From: Matthew Batchelder Date: Wed, 24 Jun 2020 23:22:39 -0400 Subject: [PATCH 17/17] Suppress fixuid output --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 123bd9c..3a24f70 100644 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Adjust pathing of subdirectories within the tric stack so that npm can find a `.git` directory when performing `npm install`. +- Suppress the `fixuid` command output in the npm `docker-entrypoint.sh`. ## [0.2.0] - 2020-06-24 ### Added