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 wporg-mu-plugins/.../utilities to docker environment #987

Merged

Conversation

timiwahalahti
Copy link
Collaborator

@timiwahalahti timiwahalahti commented Jul 28, 2023

Utilities were moved from the repo into wporg-mu-plugins repository, which broke for example CSV exports and meetup.com API calls.

This PR adds that repository and uses Composer post-update-cmd scripts to move the utilities from wporg-mu-plugins into the path where 2-autoloader.php expects it to be.

We cannot use [email protected] format as the repository URL, since that fails on Docker. We would need to add github.com into ~/.ssh/known_hosts so it's just easier to use HTTPS instead of SSH. See docker-library/golang#148 for more details.

I'm a bit puzzled about why the repository ends up in root wp-content (outside public_html) instead of vendor, but that seems to be the case, and we clean up a bit later so didn't bother to care too much 🤷‍♂️

In post-update-cmd let's first create the needed parent directories. The -p flag on the mkdir command does that. Then move only utilities directory, since we don't need anything else from the repo. Lastly do some cleanup and remove the wp-content directory where the repository was installed.

Fixes #769

Props @iandunn

How to test the changes in this Pull Request:

  1. Open Docker command shell
  2. cd ../ because shell opens in public_html instead of our root directory
  3. rm -r composer.lock for good measure
  4. php composer.phar install
  5. Check the logs in case of errors
  6. Verify that the utilities directory is where it should be, ls public_html/wp-content/mu-plugins-private/wporg-mu-plugins/pub-sync
  7. Open central.wordcamp.test and navigate to reports
  8. Run an CSV export on some report, for example the WordCamp Details
  9. Check that CSV file is generated (should auto download) and looks good

@timiwahalahti timiwahalahti added [Priority] 1 [Component] Tooling Build tools, automated testing, source control, linting, etc labels Jul 28, 2023
@timiwahalahti timiwahalahti marked this pull request as ready for review July 28, 2023 11:42
@timiwahalahti
Copy link
Collaborator Author

timiwahalahti commented Jul 28, 2023

I'm a bit puzzled about why the repository ends up in root wp-content (outside public_html) instead of vendor

Ahh, of course! 🤦‍♀️ It's because we have composer-installer package, which detects the wordpress-muplugin type and there's no configuration in installer-paths for that type. That makes the composer-installer build the "correct" path for MU plugins starting from the root.

To avoid future problems, let's configure the path for wordpress-muplugin on the same go.

@iandunn iandunn force-pushed the tooling/wporg-mu-plugins-composer branch from 31ffc79 to c030f1d Compare July 28, 2023 19:31
Copy link
Member

@iandunn iandunn left a comment

Choose a reason for hiding this comment

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

This worked for me 👍🏻

I'm guessing there's probably a way to have it install to the desired path to begin with, rather than using post-update-cmd, but it's probably not worth digging into since this works.

@iandunn iandunn merged commit 8b401c0 into WordPress:production Jul 28, 2023
@timiwahalahti
Copy link
Collaborator Author

Tried to look for native ways to cherry-pick folders from the repo and set path for it. Looks like composer nor composer-installer supports it. There's Composer-Dropin-Installer for example which does something similar, but only for file at the time and that's not sufficient in this case. Also thought that it's cleaner to have post-update-cmd rather than an additional repository which does the trickery.

@iandunn
Copy link
Member

iandunn commented Jul 28, 2023

🤔 I was thinking it might work to set a custom installer-path for the specific package, rather than type of package:

"installer-paths": {
    "public_html/wp-content/mu-plugins-private/wporg-mu-plugins/pub-sync": ["wporg/wporg-mu-plugins"],
}

For that to work it may require overriding the package definition for the project, but maybe not.

"repositories": [
	{
		"type": "package",
		"package": [
			{
				"name": "wporg/wporg-mu-plugins",
				"type": "vcs",
				"version": "dev-build", /* or maybe just `build` ? */
				"source": {
					"type": "vcs",
					"url": "https://github.com/WordPress/wporg-mu-plugins.git"
					"reference": "dev-build"  /* same as above ? */
				}
			}
		]
	}
]

I haven't tested any of that, though, and I wouldn't be surprised at all if it doesn't work. I've spent more hours banging my head against a wall w/ Composer than I care to admit 😆 I think it's totally fine to leave things the way they are.

@fumikito
Copy link

fumikito commented Aug 9, 2024

@iandunn
Hi, I got the error below while building local env with the installation doc:

docker compose exec wordcamp.test wp site list --field=url                                                                    
WARN[0000] /Users/me/Documents/GitHub/wordcamp.test/docker-compose.yaml: `version` is obsolete 
Warning: require_once(/usr/src/public_html/wp-content/mu-plugins-private/wporg-mu-plugins/pub-sync/loader.php): failed to open stream: No such file or directory in /usr/src/public_html/wp-content/mu-plugins/load-other-mu-plugins.php on line 21
Fatal error: require_once(): Failed opening required '/usr/src/public_html/wp-content/mu-plugins-private/wporg-mu-plugins/pub-sync/loader.php' (include_path='.:/usr/local/lib/php') in /usr/src/public_html/wp-content/mu-plugins/load-other-mu-plugins.php on line 21
Error: There has been a critical error on this website.Learn more about troubleshooting WordPress. There has been a critical error on this website.

Seems like pub-sync is missing in public_html/wp-content/mu-plugins-private/tm/wporg-mu-plugins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Component] Tooling Build tools, automated testing, source control, linting, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add wporg-mu-plugins/.../utilities to local environments
3 participants