Skip to content

Lazy-install Swoole/OpenSwoole extensions #107

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

Merged

Conversation

weierophinney
Copy link
Member

Q A
Documentation no
Bugfix yes
BC Break no
New Feature yes
RFC no
QA no

Description

This patch modifies how the Swoole and OpenSwoole extensions are installed and enabled, with the goals of:

  • Reducing container size
  • Installing only what is needed for a particular PHP version
  • Keeping or improving CI run time

For some time now, we've been downloading a package that contains pre-built Swoole and OpenSwoole extensions for all PHP versions for which we provide the extension (currently 7.3 - 8.1).
That package is large (> 140MB), and inflates the size of the container needlessly for most CI runs.

I've updated the project that builds the extensions to build and package each extension individually, per PHP version.
This patch no longer installs these extensions by default, but instead moves the installation to when a build has requested the extension(s).
At that time, it retrieves the package for the extension and PHP version, extracts it, and then enables the extension.

I've tested locally, and in doing so, uncovered an issue with how we were unpacking "before_script" and "after_script" values from a job, (both of which were causing the entrypoint.sh to fail); I've fixed the issue, and verified that the new approach works by running CI jobs against a checkout of mezzio-swoole, using the following.

docker run -v $(realpath .):/github/workspace -w=/github/workspace laminas-continuous-integration:testing '{"command":"./vendor/bin/phpunit","php":"8.1","extensions":["inotify","swoole"],"ini":[],"dependencies":"locked"}'

(Substituting in different PHP versions and each of "swoole" and "openswoole".)
These tests all ran correctly.
I also ran against other repositories that do not use the extension, and these ran normally.

Instead of shipping them in the container, this patch modifies the workflow to instead detect when swoole or openswoole have been requested within the entrypoint, and then downloads a package for the given extension specific to the current PHP version.
The package is extracted, and then `phpenmod` used to enable it.

The goal here is to (a) reduce overall container size, (b) reduce build times for this container, and (c) result in faster container startup times.

Signed-off-by: Matthew Weier O'Phinney <[email protected]>
@weierophinney weierophinney added this to the 1.22.0 milestone Jul 20, 2022
…tempting to cast to array

Bash's `readarray` will fail if a value is an empty string.
As such, we need to test that the value returned from `jq` is not empty before attempting to create an array from it.
Additionally, newlines can cause issues, so this adds logic to strip all newlines.

Signed-off-by: Matthew Weier O'Phinney <[email protected]>
@weierophinney weierophinney force-pushed the feature/lazy-install-swoole-packages branch from 092e4b9 to 4ed650d Compare July 20, 2022 17:20
DRYs up the logic, and allows keeping the original function cleaner and more easily maintained.

Signed-off-by: Matthew Weier O'Phinney <[email protected]>
Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

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

LGTM.

Note that this is a breaking change though, since we removed swoole.

May want to see which packages depend on it, and may be necessary to bump this to 2.x? (not sure about it)

@weierophinney
Copy link
Member Author

weierophinney commented Jul 20, 2022

Note that this is a breaking change though, since we removed swoole.

It's not removing it; it's just changing when the extension is installed. Even before, you had to indicate you wanted to enable it before it would be present in the runtime. With the change here, the capabilities are present when you need them, if you indicate you need the swoole extension to run a job.

Basically, it moves installation to the time that it is enabled, which is exactly the same as it is for other extensions that are installable via apt.

@weierophinney
Copy link
Member Author

May want to see which packages depend on it,

Also, note that in the description, I indicated that I've tested against mezzio/mezzio-swoole, which was the primary reason we included the extension. Works exactly as expected, and, in fact, the environment is ready to run the job faster than it had been before (I measured around 1-2 seconds faster in my runs locally).

@Ocramius
Copy link
Member

LGTM then :D 🚢 ?

@weierophinney
Copy link
Member Author

@boesing Should I cut the 1.22.0 release, or wait for the other improvements you're working on? I can also just merge now, and have you release when ready...

@Ocramius Ocramius self-assigned this Jul 21, 2022
@Ocramius Ocramius merged commit 6a78d5d into laminas:1.22.x Jul 21, 2022
@weierophinney weierophinney deleted the feature/lazy-install-swoole-packages branch July 22, 2022 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants