Skip to content

Commit b5f5ad1

Browse files
committed
Fix hardcoded deps index in PHP-FPM fpm.d include directive
The processPhpFpmConf function was using a hardcoded '/0/' in the fpm.d include path, which breaks multi-buildpack support when PHP buildpack is not at index 0. Changed to use dynamic deps index from Stager.DepsIdx() to properly support multi-buildpack chains where PHP buildpack may be positioned at any index. Added unit tests to verify: - Dynamic index is used in include directive when fpm.d configs exist - Include directive is properly removed when no fpm.d configs exist - Test helper ProcessPhpFpmConfForTesting() to expose private method
1 parent dda37c2 commit b5f5ad1

2 files changed

Lines changed: 77 additions & 2 deletions

File tree

src/php/supply/supply.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,9 @@ func (s *Supplier) processPhpFpmConf(phpFpmConfPath, phpEtcDir string) error {
595595
// Set the include directive based on whether user has fpm.d configs
596596
var includeDirective string
597597
if hasFpmDConfigs {
598-
// Use DEPS_DIR which will be replaced by rewrite tool at runtime
599-
includeDirective = "include=@{DEPS_DIR}/0/php/etc/fpm.d/*.conf"
598+
// Use DEPS_DIR with dynamic index which will be replaced by rewrite tool at runtime
599+
depsIdx := s.Stager.DepsIdx()
600+
includeDirective = fmt.Sprintf("include=@{DEPS_DIR}/%s/php/etc/fpm.d/*.conf", depsIdx)
600601
s.Log.Info("Enabling fpm.d config includes")
601602
} else {
602603
includeDirective = ""
@@ -834,3 +835,8 @@ func (s *Supplier) copyFile(src, dest string) error {
834835
}
835836
return os.Chmod(dest, sourceInfo.Mode())
836837
}
838+
839+
// ProcessPhpFpmConfForTesting exposes processPhpFpmConf for testing purposes
840+
func (s *Supplier) ProcessPhpFpmConfForTesting(phpFpmConfPath, phpEtcDir string) error {
841+
return s.processPhpFpmConf(phpFpmConfPath, phpEtcDir)
842+
}

src/php/supply/supply_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,75 @@ var _ = Describe("Supply", func() {
314314
Expect(installer.installed).To(HaveKey("php"))
315315
})
316316
})
317+
318+
})
319+
320+
Describe("PHP-FPM configuration with dynamic deps index", func() {
321+
It("uses dynamic deps index in fpm.d include directive when user configs exist", func() {
322+
stager := &testStager{
323+
buildDir: buildDir,
324+
depsDir: depsDir,
325+
depsIdx: "13",
326+
}
327+
328+
supplier = &supply.Supplier{
329+
Stager: stager,
330+
Log: logger,
331+
}
332+
333+
phpInstallDir := filepath.Join(stager.DepDir(), "php")
334+
phpEtcDir := filepath.Join(phpInstallDir, "etc")
335+
Expect(os.MkdirAll(phpEtcDir, 0755)).To(Succeed())
336+
337+
fpmDDir := filepath.Join(phpEtcDir, "fpm.d")
338+
Expect(os.MkdirAll(fpmDDir, 0755)).To(Succeed())
339+
testConfPath := filepath.Join(fpmDDir, "test-pool.conf")
340+
Expect(os.WriteFile(testConfPath, []byte("[test]\nlisten = 9001\n"), 0644)).To(Succeed())
341+
342+
phpFpmConfPath := filepath.Join(phpEtcDir, "php-fpm.conf")
343+
phpFpmConfContent := "[global]\npid = /tmp/php-fpm.pid\n\n#{PHP_FPM_CONF_INCLUDE}\n\n[www]\nlisten = 9000\n"
344+
Expect(os.WriteFile(phpFpmConfPath, []byte(phpFpmConfContent), 0644)).To(Succeed())
345+
346+
err = supplier.ProcessPhpFpmConfForTesting(phpFpmConfPath, phpEtcDir)
347+
Expect(err).To(BeNil())
348+
349+
content, err := os.ReadFile(phpFpmConfPath)
350+
Expect(err).To(BeNil())
351+
352+
Expect(string(content)).To(ContainSubstring("include=@{DEPS_DIR}/13/php/etc/fpm.d/*.conf"))
353+
Expect(string(content)).NotTo(ContainSubstring("@{DEPS_DIR}/0/"))
354+
Expect(string(content)).NotTo(ContainSubstring("#{PHP_FPM_CONF_INCLUDE}"))
355+
})
356+
357+
It("removes include directive when no user fpm.d configs exist", func() {
358+
stager := &testStager{
359+
buildDir: buildDir,
360+
depsDir: depsDir,
361+
depsIdx: "07",
362+
}
363+
364+
supplier = &supply.Supplier{
365+
Stager: stager,
366+
Log: logger,
367+
}
368+
369+
phpInstallDir := filepath.Join(stager.DepDir(), "php")
370+
phpEtcDir := filepath.Join(phpInstallDir, "etc")
371+
Expect(os.MkdirAll(phpEtcDir, 0755)).To(Succeed())
372+
373+
phpFpmConfPath := filepath.Join(phpEtcDir, "php-fpm.conf")
374+
phpFpmConfContent := "[global]\npid = /tmp/php-fpm.pid\n\n#{PHP_FPM_CONF_INCLUDE}\n\n[www]\nlisten = 9000\n"
375+
Expect(os.WriteFile(phpFpmConfPath, []byte(phpFpmConfContent), 0644)).To(Succeed())
376+
377+
err = supplier.ProcessPhpFpmConfForTesting(phpFpmConfPath, phpEtcDir)
378+
Expect(err).To(BeNil())
379+
380+
content, err := os.ReadFile(phpFpmConfPath)
381+
Expect(err).To(BeNil())
382+
383+
Expect(string(content)).NotTo(ContainSubstring("include="))
384+
Expect(string(content)).NotTo(ContainSubstring("#{PHP_FPM_CONF_INCLUDE}"))
385+
})
317386
})
318387

319388
Describe("InstallWebServer", func() {

0 commit comments

Comments
 (0)