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

Fix cache rebuild #169

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,30 @@ func runComposerInstall(
logger.Debug.Subprocess(fmt.Sprintf("- %s", f.Name()))
}
}
if os.Getenv("BP_RUN_COMPOSER_INSTALL") == "1" {
Copy link
Member

Choose a reason for hiding this comment

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

If we do end up going with the environment variable, we usually use booleans for this type of environment variable, so I'd want to see this changed to true/false. I'd also want to see this env. var documented in the README with the rest of the configurations.

Let's not make these changes until we (you and @paketo-buildpacks/php-maintainers) are in agreement about how to do this

installArgs := append([]string{"install"}, composerInstallOptions.Determine()...)
logger.Process("Running 'composer %s' from cached files", strings.Join(installArgs, " "))

// install packages into /workspace/vendor because composer cannot handle symlinks easily
execution := pexec.Execution{
Args: installArgs,
Dir: context.WorkingDir,
Env: append(os.Environ(),
"COMPOSER_NO_INTERACTION=1", // https://getcomposer.org/doc/03-cli.md#composer-no-interaction
fmt.Sprintf("COMPOSER=%s", composerJsonPath),
fmt.Sprintf("COMPOSER_HOME=%s", filepath.Join(composerPackagesLayer.Path, ".composer")),
fmt.Sprintf("COMPOSER_VENDOR_DIR=%s", workspaceVendorDir),
fmt.Sprintf("PHPRC=%s", composerPhpIniPath),
fmt.Sprintf("PATH=%s", path),
),
Stdout: logger.ActionWriter,
Stderr: logger.ActionWriter,
}
err = composerInstallExec.Execute(execution)
if err != nil {
return packit.Layer{}, err
}
}

if exists, err := fs.Exists(workspaceVendorDir); err != nil {
return packit.Layer{}, err
Expand Down
48 changes: 48 additions & 0 deletions integration/framework_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,53 @@ func testFrameworkApps(t *testing.T, context spec.G, it spec.S) {
})
})

context("building a drupal app", func() {
var (
err error
logs fmt.Stringer
secondImage occam.Image
)

it.Before(func() {
source, err = occam.Source(filepath.Join("testdata", "drupal_app"))
Expect(err).NotTo(HaveOccurred())
})

it("reruns composer install when reusing cached layer", func() {
image, logs, err = pack.Build.
WithPullPolicy("never").
WithBuildpacks(buildpacksArray...).
WithEnv(map[string]string{
"BP_PHP_SERVER": "nginx",
"BP_PHP_WEB_DIR": "web",
"BP_LOG_LEVEL": "DEBUG",
}).
Execute(name, source)

Expect(err).ToNot(HaveOccurred(), logs.String)

secondImage, logs, err = pack.Build.
WithPullPolicy("never").
WithBuildpacks(buildpacksArray...).
WithEnv(map[string]string{
"BP_PHP_SERVER": "nginx",
"BP_PHP_WEB_DIR": "web",
"BP_LOG_LEVEL": "DEBUG",
"BP_RUN_COMPOSER_INSTALL": "1",
}).
Execute(name, source)

Expect(err).ToNot(HaveOccurred(), logs.String)
Expect(logs.String()).To(ContainSubstring("Running 'composer install --no-progress --no-dev' from cached files"))

container, err = docker.Container.Run.
WithEnv(map[string]string{"PORT": "8080"}).
WithPublish("8080").
Execute(secondImage.ID)
Expect(err).NotTo(HaveOccurred())

Eventually(container).Should(Serve(ContainSubstring("<title>Choose language | Drupal</title>")).OnPort(8080))
})
})
})
}
21 changes: 21 additions & 0 deletions integration/testdata/drupal_app/.php.ini.d/drupal.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
opcache.enable = 1
opcache.enable_cli = 1
opcache.memory_consumption = 128
opcache.interned_strings_buffer = 16
opcache.max_accelerated_files = 10000
opcache.revalidate_freq = 240
opcache.fast_shutdown = 1

extension=mysqli
extension=gd
extension=mbstring
extension=openssl
extension=pdo
extension=pdo_mysql
extension=zip
extension=curl
extension=exif
extension=opcache


date.timezone = UTC
95 changes: 95 additions & 0 deletions integration/testdata/drupal_app/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"name": "drupal/recommended-project",
"description": "Project template for Drupal projects with a relocated document root",
"type": "project",
"license": "GPL-2.0-or-later",
"homepage": "https://www.drupal.org/project/drupal",
"support": {
"docs": "https://www.drupal.org/docs/user_guide/en/index.html",
"chat": "https://www.drupal.org/node/314178"
},
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
}
],
"require": {
"composer/installers": "^2.0",
"drupal/core-composer-scaffold": "^10.1",
"drupal/core-project-message": "^10.1",
"drupal/core-recommended": "^10.1"
},
"conflict": {
"drupal/drupal": "*"
},
"minimum-stability": "stable",
"prefer-stable": true,
"config": {
"allow-plugins": {
"composer/installers": true,
"drupal/core-composer-scaffold": true,
"drupal/core-project-message": true,
"phpstan/extension-installer": true,
"dealerdirect/phpcodesniffer-composer-installer": true
},
"sort-packages": true
},
"extra": {
"drupal-scaffold": {
"locations": {
"web-root": "web/"
}
},
"installer-paths": {
"web/core": [
"type:drupal-core"
],
"web/libraries/{$name}": [
"type:drupal-library"
],
"web/modules/contrib/{$name}": [
"type:drupal-module"
],
"web/profiles/contrib/{$name}": [
"type:drupal-profile"
],
"web/themes/contrib/{$name}": [
"type:drupal-theme"
],
"drush/Commands/contrib/{$name}": [
"type:drupal-drush"
],
"web/modules/custom/{$name}": [
"type:drupal-custom-module"
],
"web/profiles/custom/{$name}": [
"type:drupal-custom-profile"
],
"web/themes/custom/{$name}": [
"type:drupal-custom-theme"
]
},
"drupal-core-project-message": {
"include-keys": [
"homepage",
"support"
],
"post-create-project-cmd-message": [
"<bg=blue;fg=white> </>",
"<bg=blue;fg=white> Congratulations, you’ve installed the Drupal codebase </>",
"<bg=blue;fg=white> from the drupal/recommended-project template! </>",
"<bg=blue;fg=white> </>",
"",
"<bg=yellow;fg=black>Next steps</>:",
" * Install the site: https://www.drupal.org/docs/installing-drupal",
" * Read the user guide: https://www.drupal.org/docs/user_guide/en/index.html",
" * Get support: https://www.drupal.org/support",
" * Get involved with the Drupal community:",
" https://www.drupal.org/getting-involved",
" * Remove the plugin that prints this message:",
" composer remove drupal/core-project-message"
]
}
}
}
Loading