Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to modify docker-compose configuration #722

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rmccue
Copy link
Member

@rmccue rmccue commented Aug 20, 2024

Adds the ability for any Composer package (including the root/project itself) to modify the docker-compose configuration, making it possible for modules to add containers or alter the existing configuration.

This can be used for better modularity and conditional behaviour, such as for optional features like Elasticsearch or Node.js. It also provides the ability for users to customise Docker behaviour fairly directly in their project.

My plan is to transition the ES + Kibana containers to the Enhanced Search package, and then eventually someday remove it from the default bundle, allowing a clearer opt-in for customers who have actually bought it. PR for that incoming soon.

This adds the ability for modules to extend the docker-compose.yml
configuration with sidecar containers (or override existing
configuration).
}

public function filter_compose( array $config ) : array {
$config['services']'foo'] = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$config['services']'foo'] = [
$config['services']['foo'] = [

Copy link
Contributor

@mikelittle mikelittle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of suggestions.
Also, the lint issues will need fixes (mostly missing docs).


## How Local Server works

Local Server internally uses Docker Compose to create and manage containers for the Altis environment. When a user runs the `composer server start` command, Local Server dynamically provisions a `docker-compose.yml` file based on the user's preferences. (This file is only regenerated when starting Local Server to avoid conflicts or surprising behaviour for users.)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Local Server internally uses Docker Compose to create and manage containers for the Altis environment. When a user runs the `composer server start` command, Local Server dynamically provisions a `docker-compose.yml` file based on the user's preferences. (This file is only regenerated when starting Local Server to avoid conflicts or surprising behaviour for users.)
Local Server internally uses Docker Compose to create and manages containers for the Altis environment. When a user runs the `composer server start` command, Local Server dynamically provisions a `docker-compose.yml` file based on the user's preferences. (This file is only regenerated when starting Local Server to avoid conflicts or surprising behaviour for users.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also wrap lines at 132 chars please? As per our MD linting standards.

$config = [];
foreach ( $packages as $name => $package ) {
$extra = $package->getExtra();
if ( ! isset( $extra['altis'] ) || ! isset( $extra['altis']['local-server'] ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be clearer as a positive test:

Suggested change
if ( ! isset( $extra['altis'] ) || ! isset( $extra['altis']['local-server'] ) ) {
if ( isset( $extra['altis'] ) && isset( $extra['altis']['local-server'] ) ) {
$config[ $name ] = $extra['altis']['local-server'];
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd agree if it were a straight if/else, but this is more of a return-early pattern. Not strongly opinionated so if you feel it's much more readable that way I'll update

@mikelittle
Copy link
Contributor

I like the idea of this.
It might be an opportunity to stop using the implicit dependency and networking configuration of links. Instead, we should use explicit depends_on and networks attributes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants