-
-
Notifications
You must be signed in to change notification settings - Fork 27
fix: warn and fallback for unsupported PHP versions #348
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
Open
AaronFeledy
wants to merge
3
commits into
main
Choose a base branch
from
fix/unsupported-php-version-warning
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| name: pantheon-php-warning | ||
| recipe: pantheon | ||
| config: | ||
| framework: drupal | ||
| site: fake-site | ||
| id: fake-id | ||
|
|
||
| # do not remove this | ||
| plugins: | ||
| "@lando/pantheon": ../.. | ||
| "@lando/mariadb": ../../node_modules/@lando/mariadb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # Pantheon PHP Version Warning Example | ||
|
|
||
| This example exists primarily to test the unsupported-PHP-version warning | ||
| introduced in [#347](https://github.com/lando/pantheon/pull/347). | ||
|
|
||
| The bundled `pantheon.yml` sets `php_version: "6.0"` — a PHP version that | ||
| does not exist (the PHP 6 project was abandoned in 2010, and Pantheon has | ||
| never published a `6.0` appserver image). The Lando Pantheon plugin should | ||
| warn the user clearly during `lando start` instead of leaving them to | ||
| decode the cryptic Docker `manifest unknown` error that follows. | ||
|
|
||
| `lando start` is *expected to fail* in this test — the appserver image | ||
| genuinely does not exist. We capture the start output to verify the | ||
| warning was emitted before that failure. | ||
|
|
||
| ## Start up tests | ||
|
|
||
| Run the following commands to get up and running with this example. | ||
|
|
||
| ```bash | ||
| # Should poweroff | ||
| lando poweroff | ||
|
|
||
| # Should attempt to start and emit a warning to the terminal. The actual | ||
| # `lando start` is expected to fail because devwithlando/pantheon-appserver:6.0-* | ||
| # does not exist, so we tolerate the non-zero exit code with `|| true` and | ||
| # rely on the verification step below to assert the warning fired first. | ||
| lando start 2>&1 | tee /tmp/pantheon-php-warning-start.log || true | ||
| ``` | ||
|
|
||
| ## Verification commands | ||
|
|
||
| Run the following commands to validate things are rolling as they should. | ||
|
|
||
| ```bash | ||
| # Should warn that no Docker images are available for PHP 6.0 | ||
| grep "WARNING: No Docker images are available for PHP 6.0" /tmp/pantheon-php-warning-start.log | ||
|
|
||
| # Should explain that the appserver will fail to start | ||
| grep "appserver will fail to start" /tmp/pantheon-php-warning-start.log | ||
|
|
||
| # Should advise updating php_version in the user's pantheon.yml | ||
| grep "Update php_version in your pantheon.yml" /tmp/pantheon-php-warning-start.log | ||
|
|
||
| # Should recommend a Pantheon-supported PHP version | ||
| grep "Pantheon-recommended version" /tmp/pantheon-php-warning-start.log | ||
|
|
||
| # Should NOT have a running appserver container (the 6.0 image doesn't exist) | ||
| docker ps --filter label=com.docker.compose.project=pantheonphpwarning --format '{{.Image}}' | grep "pantheon-appserver" || echo $? | grep 1 | ||
| ``` | ||
|
|
||
| ## Destroy tests | ||
|
|
||
| Run the following commands to trash this app like nothing ever happened. | ||
|
|
||
| ```bash | ||
| # Should be destroyed cleanly even though start failed | ||
| lando destroy -y || true | ||
| lando poweroff | ||
|
|
||
| # Should clean up the start log | ||
| rm -f /tmp/pantheon-php-warning-start.log | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| PHP FALLBACK |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <?php phpinfo(); ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # This pantheon.yml exists to test the unsupported-PHP-version warning | ||
| # behavior introduced in https://github.com/lando/pantheon/pull/347. | ||
| # | ||
| # php_version: 6.0 is intentionally a PHP version that does not exist | ||
| # (PHP famously skipped 6.0; the project was abandoned in 2010) so this | ||
| # test stays valid even as Pantheon publishes new images. With no | ||
| # devwithlando/pantheon-appserver:6.0-* image available, the Lando | ||
| # Pantheon plugin should emit a clear, user-facing warning instead of | ||
| # leaving the user to decode a cryptic Docker "manifest unknown" error. | ||
| api_version: 1 | ||
| php_version: "6.0" | ||
| database: | ||
| version: 10.6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| 'use strict'; | ||
|
|
||
| const chai = require('chai'); | ||
| const pantheonPhp = require('../builders/pantheon-php'); | ||
|
|
||
| chai.should(); | ||
|
|
||
| describe('pantheon-php', () => { | ||
| it('should silently fall back to an available image generation', () => { | ||
| class Parent { | ||
| constructor(id, options) { | ||
| this.options = options; | ||
| } | ||
| } | ||
|
|
||
| class PantheonNginx { | ||
| constructor() { | ||
| this.data = [{version: '3'}]; | ||
| this.info = {}; | ||
| } | ||
| } | ||
|
|
||
| const app = { | ||
| add: () => {}, | ||
| config: {services: {}}, | ||
| env: {LANDO_HOST_IP: '127.0.0.1'}, | ||
| info: [], | ||
| _lando: {log: {debug: () => {}}}, | ||
| }; | ||
| const factory = { | ||
| get: () => PantheonNginx, | ||
| }; | ||
| const PantheonPhp = pantheonPhp.builder(Parent, pantheonPhp.defaults); | ||
| const service = new PantheonPhp('appserver', { | ||
| _app: app, | ||
| app: 'pantheon', | ||
| confDest: '/tmp/lando/config', | ||
| framework: 'drupal', | ||
| generation: '4', | ||
| id: 'site-id', | ||
| name: 'appserver', | ||
| php: '8.4', | ||
| project: 'pantheon', | ||
| root: '/app', | ||
| site: 'site-name', | ||
| solrTag: 'latest', | ||
| userConfRoot: '/app/.lando', | ||
| volumes: [], | ||
| }, factory); | ||
|
|
||
| service.options.image.should.equal('devwithlando/pantheon-appserver:8.4-5'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| 'use strict'; | ||
|
|
||
| const chai = require('chai'); | ||
| const fs = require('fs'); | ||
| const os = require('os'); | ||
| const path = require('path'); | ||
| const utils = require('../lib/utils'); | ||
|
|
||
| chai.should(); | ||
|
|
||
| describe('utils', () => { | ||
| describe('#resolveGeneration', () => { | ||
| it('should fall back to the highest available generation', () => { | ||
| utils.resolveGeneration('8.4', '4').should.equal('5'); | ||
| }); | ||
|
|
||
| it('should return null when no PHP generation images exist', () => { | ||
| chai.expect(utils.resolveGeneration('9.9', '5')).to.equal(null); | ||
| }); | ||
| }); | ||
|
|
||
| describe('#getPantheonConfig', () => { | ||
| let tempDir; | ||
| let originalWarn; | ||
| let warnings; | ||
|
|
||
| const writePantheonConfig = content => { | ||
| const file = path.join(tempDir, 'pantheon.yml'); | ||
| fs.writeFileSync(file, content); | ||
| return file; | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'lando-pantheon-')); | ||
| warnings = []; | ||
| originalWarn = console.warn; | ||
| console.warn = warning => warnings.push(warning); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| console.warn = originalWarn; | ||
| fs.rmSync(tempDir, {recursive: true, force: true}); | ||
| }); | ||
|
|
||
| it('should normalize unquoted x.0 PHP versions before resolving the generation', () => { | ||
| const file = writePantheonConfig([ | ||
| 'php_version: 8.0', | ||
| 'php_runtime_generation: 1', | ||
| ].join('\n')); | ||
|
|
||
| const config = utils.getPantheonConfig([file]); | ||
|
|
||
| config.php.should.equal('8.0'); | ||
| config.generation.should.equal('4'); | ||
| }); | ||
|
|
||
| it('should warn and fall back when the requested PHP generation has no image', () => { | ||
| const file = writePantheonConfig([ | ||
| 'php_version: 8.4', | ||
| 'php_runtime_generation: 1', | ||
| ].join('\n')); | ||
|
|
||
| const config = utils.getPantheonConfig([file]); | ||
|
|
||
| config.generation.should.equal('5'); | ||
| warnings.should.have.length(1); | ||
| warnings[0].should.include('No Docker image exists for PHP 8.4 generation 4'); | ||
| warnings[0].should.include('devwithlando/pantheon-appserver:8.4-5'); | ||
| }); | ||
|
|
||
| it('should warn and keep the requested generation when no PHP images exist', () => { | ||
| const file = writePantheonConfig([ | ||
| 'php_version: 9.9', | ||
| 'php_runtime_generation: 2', | ||
| ].join('\n')); | ||
|
|
||
| const config = utils.getPantheonConfig([file]); | ||
|
|
||
| config.generation.should.equal('5'); | ||
| warnings.should.have.length(1); | ||
| warnings[0].should.include('No Docker images are available for PHP 9.9'); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.