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

always load the openssl extension #3

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

const (
runComposerInstallOnCacheEnv = "BP_RUN_COMPOSER_INSTALL"
opensslExtension = "openssl"
)

// DetermineComposerInstallOptions defines the interface to get options for `composer install`
Expand Down Expand Up @@ -448,7 +449,7 @@ func writeComposerPhpIni(logger scribe.Emitter, context packit.BuildContext) (co

phpIni := fmt.Sprintf(`[PHP]
extension_dir = "%s"
extension = openssl.so`, os.Getenv(PhpExtensionDir))
extension = %s.so`, os.Getenv(PhpExtensionDir), opensslExtension)
Copy link

Choose a reason for hiding this comment

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

You know why openssl is in here in the first place?

Copy link
Author

@thirdeyenick thirdeyenick Dec 1, 2023

Choose a reason for hiding this comment

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

Don't know exactly. composer install installs modules from somewhere. So a HTTPS connection might be needed. The composer installer also seems to check for the extension.

Copy link

Choose a reason for hiding this comment

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

ok, that makes sense

logger.Debug.Subprocess("Writing php.ini contents:\n'%s'", phpIni)

return composerPhpIniPath, os.WriteFile(composerPhpIniPath, []byte(phpIni), os.ModePerm)
Expand Down Expand Up @@ -493,7 +494,12 @@ func runCheckPlatformReqs(logger scribe.Emitter, checkPlatformReqsExec Executabl
}
}

var extensions []string
// we always include the openssl extension as it will not be found
// otherwise. The reason for this is that `writeComposerPhpIni` gets
// executed first and already includes the openssl extension. `composer
// check-platform-reqs` will therefore not output a missing openssl
// extension (as it was already loaded).
var extensions = []string{opensslExtension}
for _, line := range strings.Split(buffer.String(), "\n") {
chunks := strings.Split(strings.TrimSpace(line), " ")
extensionName := strings.TrimPrefix(strings.TrimSpace(chunks[0]), "ext-")
Expand Down
5 changes: 3 additions & 2 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,8 @@ composer-lock-sha = "sha-from-composer-lock"
contents, err := os.ReadFile(filepath.Join(workingDir, ".php.ini.d", "composer-extensions.ini"))
Expect(err).NotTo(HaveOccurred())

Expect(string(contents)).To(Equal(`extension = hello.so
Expect(string(contents)).To(Equal(`extension = openssl.so
extension = hello.so
extension = bar.so
`))
})
Expand Down Expand Up @@ -610,7 +611,7 @@ extension = bar.so
Expect(output).To(ContainSubstring(fmt.Sprintf("Listing files in %s:", filepath.Join(layersDir, composer.ComposerPackagesLayerName, "vendor"))))
Expect(output).To(ContainSubstring(" Generating SBOM"))
Expect(output).To(ContainSubstring("Running 'composer check-platform-reqs'"))
Expect(output).To(ContainSubstring("Found extensions 'hello, bar'"))
Expect(output).To(ContainSubstring("Found extensions 'openssl, hello, bar'"))
})
})

Expand Down
3 changes: 2 additions & 1 deletion integration/with_extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func testWithExtensions(t *testing.T, context spec.G, it spec.S) {
Expect(err).ToNot(HaveOccurred(), logs.String)

Expect(logs).To(ContainSubstring("Running 'composer check-platform-reqs'"))
Expect(logs).To(ContainSubstring("Found extensions 'fileinfo, gd, mysqli, zip'"))
Expect(logs).To(ContainSubstring("Found extensions 'openssl, fileinfo, gd, mysqli, zip'"))

container, err = docker.Container.Run.
WithEnv(map[string]string{"PORT": "8765"}).
Expand All @@ -78,6 +78,7 @@ func testWithExtensions(t *testing.T, context spec.G, it spec.S) {
// Note that `mbstring` is not included, since it is not available in `php-dist` for unknown reasons
extensionsMatcher := And(
ContainSubstring("zip"),
ContainSubstring("openssl"),
ContainSubstring("gd"),
ContainSubstring("fileinfo"),
ContainSubstring("mysqli"),
Expand Down