Skip to content

Commit

Permalink
Added pre-composer command to replace composer if there is a vendor v…
Browse files Browse the repository at this point in the history
…ersion
  • Loading branch information
juanjol committed Oct 9, 2024
1 parent 8b964c1 commit 942b89a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions config.aljibe.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Custom config to alter composer executable in case Drupal is defining a custom version.
# See https://github.com/ddev/ddev/issues/6602 for more details.
hooks:
post-start:
- exec: test -f /var/www/html/vendor/bin/composer && rm -f /usr/local/bin/composer && ln -s /var/www/html/vendor/bin/composer /usr/local/bin/composer
pre-composer:
- exec: |
if [ -f /var/www/html/vendor/bin/composer ] && \
[ "$(readlink /usr/local/bin/composer)" != "/var/www/html/vendor/bin/composer" ]; then \
rm -f /usr/local/bin/composer && \
ln -s /var/www/html/vendor/bin/composer /usr/local/bin/composer; \
fi

2 comments on commit 942b89a

@rfay
Copy link

@rfay rfay commented on 942b89a Oct 9, 2024

Choose a reason for hiding this comment

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

Thanks for exploring this territory!

You'll probably be more satisfied with ln -sf /var/www/html/vendor/bin/composer /usr/local/bin/composer than remove-and-link.

I see readlink returns empty string when it's not a link, so the strategy should be OK.

I assume that you never use an alternate composer_root, which would change this logic.

@juanjol
Copy link
Collaborator Author

@juanjol juanjol commented on 942b89a Oct 9, 2024

Choose a reason for hiding this comment

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

Hi @rfay!

As for removing the link, you're absolutely right! I hadn't thought of it that way. I think I'll replace those two lines with what you recommend.

I've been testing the option of using composer_version but for CI I was having problems keeping it in sync with the composer.json version.

This is a workaround while we see if the issue we raised this morning goes through. I think it's quite hacky, but at least it works and in the controlled environments of aljibe I think it can work well. What I'm going to have to investigate is if the vendors can be installed somewhere else... or some way to make this ‘configurable’. But to solve the inconsistency problems that the different versions of composer are generating in CI is enough.

Please sign in to comment.