Skip to content

Commit

Permalink
fix(src,doc) use docker compose in place of docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatume committed Mar 17, 2023
1 parent 98fff64 commit b678727
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 32 deletions.
2 changes: 1 addition & 1 deletion slic-stack.site.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# docker-compose configuration file used to run cross-activation tests.
# docker compose configuration file used to run cross-activation tests.

version: "3"

Expand Down
6 changes: 3 additions & 3 deletions slic-stack.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# docker-compose configuration file used to run cross-activation tests.
# docker compose configuration file used to run cross-activation tests.

version: "3.9"

Expand Down Expand Up @@ -98,7 +98,7 @@ services:
# The `remote_host` is set to `host.docker.internal` that will resolve to the host machine IP address, from
# within the container, on macOS and Windows.
# On Linux set the host machine IP address before calling the stack:
# XDH=$(ip route | grep docker0 | awk '{print $9}') docker-compose ...
# XDH=$(ip route | grep docker0 | awk '{print $9}') docker compose ...
XDEBUG_CONFIG: "idekey=${XDK:-slic} remote_enable=${XDE:-1} remote_host=${XDH:-host.docker.internal} remote_port=${XDP:-9001} client_host=${XDH:-host.docker.internal} client_port=${XDP:-9001}"
# Whether to disable the XDebug extension in the Codeception container completely or not.
XDEBUG_DISABLE: "${XDEBUG_DISABLE:-0}"
Expand Down Expand Up @@ -156,7 +156,7 @@ services:
# The `remote_host` is set to `host.docker.internal` that will resolve to the host machine IP address, from
# within the container, on macOS and Windows.
# On Linux set the host machine IP address before calling the stack:
# XDH=$(ip route | grep docker0 | awk '{print $9}') docker-compose ...
# XDH=$(ip route | grep docker0 | awk '{print $9}') docker compose ...
XDEBUG_CONFIG: "idekey=${XDK:-slic} remote_enable=${XDE:-1} remote_host=${XDH:-host.docker.internal} remote_port=${XDP:-9001} client_host=${XDH:-host.docker.internal} client_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/${SLIC_CURRENT_PROJECT:-test}/${SLIC_CURRENT_PROJECT_SUBDIR:-}
Expand Down
6 changes: 3 additions & 3 deletions slic.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The entrypoint to anything you will need to do will be the `slic` binary, locate

## Requirements

The stack runs based on [Docker](https://www.docker.com/) and [docker-compose](https://docs.docker.com/compose/): you will need both installed and available to be able to use the local testing environment.
The stack runs based on [Docker](https://www.docker.com/) and [docker compose](https://docs.docker.com/compose/): you will need both installed and available to be able to use the local testing environment.
If your Docker installation requires root access, please follow [this guide](https://docs.docker.com/install/linux/linux-postinstall/) to make sure root access is not required to run `docker` commands.

You should be able to run the following command without issues and without requiring root access:
Expand All @@ -16,7 +16,7 @@ You should be able to run the following command without issues and without requi
docker run hello-world
```

If this is not the case, please take the time to read Docker and docker-compose documentation and fix the issues you encounter.
If this is not the case, please take the time to read Docker and docker compose documentation and fix the issues you encounter.

## Where to get help

Expand Down Expand Up @@ -178,7 +178,7 @@ slic cli db export /plugins/the-events/calendar/tests/_data/dump.sql
## How the stack works, an overview

The stack services are defined by the `slic-stack.yml` file.
This is a YAML format docker-compose configuration file the `slic` binary will use to run the `docker-compose` command.
This is a YAML format docker compose configuration file the `slic` binary will use to run the `docker compose` command.
The main services defined there are:

* `wordpress` - this uses the `wordpress:latest` image, the official Docker image for WordPress. When running the container will fill the `_wordpress` directory with the contents of the WordPress installation that is currently serving the container. Furthermore the WordPress container is configured to look for plugins in the `/plugins` directory, that directory is a shared volume that you can find in the `dev/test/plugins` directory.
Expand Down
2 changes: 1 addition & 1 deletion src/commands/site-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
array_unshift( $command, 'wp', '--allow-root' );

/*
* Due to how docker-compose works, the default `CMD` for the `wordpress:cli` image will be overridden as a
* Due to how docker compose works, the default `CMD` for the `wordpress:cli` image will be overridden as a
* consequence of overriding the `entrypoint` configuration parameter of the service.
* We cannot, thus, pass the user command directly, we use an env var, `SLIC_SITE_CLI_COMMAND`, to embed the
* command we're running into the entrypoint call arguments.
Expand Down
43 changes: 26 additions & 17 deletions src/docker.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* docker-compose wrapper functions.
* docker compose wrapper functions.
*/

namespace StellarWP\Slic;
Expand Down Expand Up @@ -28,11 +28,11 @@ function os() {
}

/**
* Curried docker-compose wrapper.
* Curried docker compose wrapper.
*
* @param array<string> $options A list of options to initialize the wrapper.
*
* @return \Closure A closure to actually call docker-compose with more arguments.
* @return \Closure A closure to actually call docker compose with more arguments.
*/
function docker_compose( array $options = [] ) {
setup_id();
Expand All @@ -49,13 +49,7 @@ function docker_compose( array $options = [] ) {
$host_ip = host_ip( 'Linux' );
}

/*
* Newer versions of Docker include the `docker compose` command instead of a separate `docker-compose`.
* Most CIs have the newer version of Docker that includes the `docker compose` command, but will also include the
* outdated `docker-compose` command for back-compatibility.
* Unless the `SLIC_DOCKER_COMPOSE_BIN` environment variable is set, we'll use the newer `docker compose` command.
*/
$dc_bin = getenv( 'SLIC_DOCKER_COMPOSE_BIN' ) ?: 'docker compose';
$dc_bin = docker_compose_bin();

return static function ( array $command = [] ) use ( $dc_bin, $options, $host_ip, $is_ci ) {
$command = $dc_bin . ' ' . implode( ' ', $options ) . ' ' . implode( ' ', $command );
Expand Down Expand Up @@ -130,7 +124,7 @@ function wordpress_url() {
* @param string $postfix A postfix to use for the stack file, it will be inserted between the file base name and
* the `.yml` file extension.
*
* @return string The path to the docker-compose stack file to run, depending on the run context.
* @return string The path to the docker compose stack file to run, depending on the run context.
*/
function stack( $postfix = '' ) {
$root_dir = dirname( __DIR__ );
Expand All @@ -151,13 +145,13 @@ function stack( $postfix = '' ) {
}

/**
* Builds a collection of docker-compose yaml files for spinning up a stack.
* Builds a collection of docker compose yaml files for spinning up a stack.
*
* Typically, this would be slic-stack.yml for plugin-only setups, but if running in site mode, it adds slic-stack.site.yml.
*
* @param bool $filenames_only Return only the files part of the stack, without including option flags.
*
* @return string[] Array of docker-compose arguments indicating the files that should be used to initialize the stack.
* @return string[] Array of docker compose arguments indicating the files that should be used to initialize the stack.
*/
function slic_stack_array( $filenames_only = false ) {
$file_prefix = $filenames_only ? '' : '-f';
Expand All @@ -174,7 +168,7 @@ function slic_stack_array( $filenames_only = false ) {
}

/**
* Executes a docker-compose command in real time, printing the output as produced by the command.
* Executes a docker compose command in real time, printing the output as produced by the command.
*
* @param array<string> $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).
Expand Down Expand Up @@ -212,7 +206,7 @@ function docker_compose_process( array $options = [], $is_realtime = true ) {
$command = array_unique( array_merge( [ $subcommand ], $var, $command ) );
}

$command = 'docker-compose ' . implode( ' ', $options ) . ' ' . implode( ' ', $command );
$command = docker_compose_bin() . ' ' . implode( ' ', $options ) . ' ' . implode( ' ', $command );

if ( ! empty( $host_ip ) ) {
// Set the host IP address on Linux machines.
Expand All @@ -230,7 +224,7 @@ function docker_compose_process( array $options = [], $is_realtime = true ) {
}

/**
* Executes a docker-compose command in passive mode, printing the output as produced by the command.
* 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.
*
Expand All @@ -243,7 +237,7 @@ function docker_compose_passive( array $options = [] ) {
}

/**
* Executes a docker-compose command in real time, printing the output as produced by the command.
* Executes a docker compose command in real time, printing the output as produced by the command.
*
* @param array<string> $options A list of options to initialize the wrapper.
*
Expand All @@ -252,3 +246,18 @@ function docker_compose_passive( array $options = [] ) {
function docker_compose_realtime( array $options = [] ) {
return docker_compose_process( $options, true );
}

/**
* Returns the path to the docker compose binary.
*
* Newer versions of Docker include the `docker compose` command instead of a separate `docker-compose`.
* Most CIs have the newer version of Docker that includes the `docker compose` command, but will also include the
* outdated `docker-compose` command for back-compatibility.
* Unless the `SLIC_DOCKER_COMPOSE_BIN` environment variable is set, we'll use the newer `docker compose` command.
*
* @return string
*/
function docker_compose_bin(): string {
return (string) getenv( 'SLIC_DOCKER_COMPOSE_BIN' ) ?: 'docker compose';
}

8 changes: 4 additions & 4 deletions src/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
use Exception;

/**
* Returns the `docker-compose` schema parsed from the `slic` files loaded in the current
* Returns the `docker compose` schema parsed from the `slic` files loaded in the current
* request.
*
* @return array<string,array> The loaded `docker-compose` format files, merged in array format.
* @return array<string,array> The loaded `docker compose` format files, merged in array format.
*/
function stack_schema() {
static $schema;
Expand Down Expand Up @@ -45,10 +45,10 @@ function stack_schema() {
}

/**
* Returns the `service` section of the `docker-compose` format stack files loaded in the request
* Returns the `service` section of the `docker compose` format stack files loaded in the request
* for `slic`.
*
* @return array<string,array> The `services` section of the loaded `docker-compose` format files.
* @return array<string,array> The `services` section of the loaded `docker compose` format files.
*/
function services_schema() {
$stack_schema = stack_schema();
Expand Down
4 changes: 2 additions & 2 deletions src/slic.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ function php_services() {
/**
* Restart the stack PHP services.
*
* @param bool $hard Whether to restart the PHP services using the `docker-compose restart` command or by using a
* @param bool $hard Whether to restart the PHP services using the `docker compose restart` command or by using a
* tear-down and up again cycle.
*/
function restart_php_services( $hard = false ) {
Expand All @@ -379,7 +379,7 @@ function restart_php_services( $hard = false ) {
*
* @param string $service The name of the service to restart, e.g. `wordpress`.
* @param string|null $pretty_name The pretty name to use for the service, or `null` to use the service name.
* @param bool $hard Whether to restart the service using the `docker-compose restart` command or to use full tear-down
* @param bool $hard Whether to restart the service using the `docker compose restart` command or to use full tear-down
* and up again cycle.
*/
function restart_service( $service, $pretty_name = null, $hard = false ) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function gid() {
*
* On OSes that will handle user ID and group ID mapping at the Docker daemon level, macOS and Windows, the
* `SLIC_UID` and `SLIC_GID` env variables will be set to empty strings.
* This, in turn, will fill the `user` parameter of the stack services to `user: ":"` that will prompt docker-compose
* This, in turn, will fill the `user` parameter of the stack services to `user: ":"` that will prompt docker compose
* to not set the user at all, the wanted behavior on such OSes.
*
* @param bool $reset Whether to re-fetch and reset the user id and group or not.
Expand Down

0 comments on commit b678727

Please sign in to comment.