diff --git a/build.go b/build.go index eb723b22..3a39f797 100644 --- a/build.go +++ b/build.go @@ -22,6 +22,7 @@ import ( const ( runComposerInstallOnCacheEnv = "BP_RUN_COMPOSER_INSTALL" + opensslExtension = "openssl" ) // DetermineComposerInstallOptions defines the interface to get options for `composer install` @@ -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) logger.Debug.Subprocess("Writing php.ini contents:\n'%s'", phpIni) return composerPhpIniPath, os.WriteFile(composerPhpIniPath, []byte(phpIni), os.ModePerm) @@ -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-") diff --git a/build_test.go b/build_test.go index 0ae9a609..1930f200 100644 --- a/build_test.go +++ b/build_test.go @@ -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 `)) }) @@ -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'")) }) }) diff --git a/integration/with_extensions_test.go b/integration/with_extensions_test.go index 4069eea4..cc744842 100644 --- a/integration/with_extensions_test.go +++ b/integration/with_extensions_test.go @@ -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"}). @@ -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"),