Skip to content

Commit 34255f3

Browse files
fix(config): replace composer_version 1 option with 2.2 (LTS), fixes #8084 (#8126)
Co-authored-by: Stanislav Zhuk <[email protected]>
1 parent 2a7d95b commit 34255f3

File tree

8 files changed

+32
-11
lines changed

8 files changed

+32
-11
lines changed

cmd/ddev/cmd/autocompletion_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func TestAutocompletionForConfigCmd(t *testing.T) {
245245
"--project-tld": {nodeps.DdevDefaultTLD},
246246
"--use-dns-when-possible": {"true", "false"},
247247
"--disable-settings-management": {"true", "false"},
248-
"--composer-version": {"2", "2.2", "1", "stable", "preview", "snapshot"},
248+
"--composer-version": {"2", "2.2", "stable", "preview", "snapshot"},
249249
"--bind-all-interfaces": {"true", "false"},
250250
"--database": nodeps.GetValidDatabaseVersions(),
251251
"--nodejs-version": {nodeps.NodeJSDefault, "auto", "engine"},

cmd/ddev/cmd/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ func init() {
300300
ConfigCommand.Flags().Bool("disable-settings-management", false, "Prevent DDEV from creating or updating CMS settings files")
301301
_ = ConfigCommand.RegisterFlagCompletionFunc("disable-settings-management", configCompletionFunc([]string{"true", "false"}))
302302

303-
ConfigCommand.Flags().String("composer-version", nodeps.ComposerDefault, `Specify override for Composer version in web container. This may be "", "1", "2", "2.2", "stable", "preview", "snapshot" or a specific version`)
304-
_ = ConfigCommand.RegisterFlagCompletionFunc("composer-version", configCompletionFunc([]string{"2", "2.2", "1", "stable", "preview", "snapshot"}))
303+
ConfigCommand.Flags().String("composer-version", nodeps.ComposerDefault, `Specify override for Composer version in web container. This may be "", "2", "2.2", "stable", "preview", "snapshot" or a specific version`)
304+
_ = ConfigCommand.RegisterFlagCompletionFunc("composer-version", configCompletionFunc([]string{"2", "2.2", "stable", "preview", "snapshot"}))
305305

306306
ConfigCommand.Flags().Bool("auto", false, `Automatically run config without prompting`)
307307
ConfigCommand.Flags().Bool("bind-all-interfaces", false, `Bind host ports on all interfaces, not only on the localhost network interface`)

docs/content/users/configuration/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Composer version for the web container and the [`ddev composer`](../usage/comman
9292

9393
| Type | Default | Usage
9494
| -- | -- | --
95-
| :octicons-file-directory-16: project | `2` | Can be `2`, `1`, or empty (`""`) for latest major version at container build time.<br><br>Can also be the LTS version `2.2` (there's no other `2.x` LTS), an explicit version like `2.9.3`, or a keyword like `stable`, `preview` or `snapshot`. See [Composer documentation](https://getcomposer.org/doc/03-cli.md#self-update-selfupdate).
95+
| :octicons-file-directory-16: project | `2` | Can be `2` or empty (`""`) for latest major version at container build time.<br><br>Can also be the LTS version `2.2` (there's no other `2.x` LTS), an explicit version like `2.9.3`, or a keyword like `stable`, `preview` or `snapshot`. See [Composer documentation](https://getcomposer.org/doc/03-cli.md#self-update-selfupdate).
9696

9797
!!!warning "Composer version is cached at container build time"
9898
DDEV installs Composer at container build time and caches it. If you use a non-specific version like `2`, `2.2`, `""` (empty), or `stable`, DDEV installs the latest available version in that range at build time.

docs/content/users/usage/commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ Flags:
372372
* `--bind-all-interfaces`: Bind host ports on all interfaces, not only on the localhost network interface.
373373
* `--composer-root`: The relative path, from the project root, to the directory containing `composer.json`. (This is where all Composer-related commands are executed.)
374374
* `--composer-root-default`: Unset a `web` service Composer root directory override, the same as `--composer-root=""`.
375-
* `--composer-version`: Specify override for Composer version in the web container. This may be `""`, `"1"`, `"2"`, `"2.2"`, `"stable"`, `"preview"`, `"snapshot"`, or a specific version.
375+
* `--composer-version`: Specify override for Composer version in the web container. This may be `""`, `"2"`, `"2.2"`, `"stable"`, `"preview"`, `"snapshot"`, or a specific version.
376376
* `--corepack-enable`: Whether to run `corepack enable` on Node.js configuration.
377377
* `--database`: Specify the database `type:version` to use (see [default](../configuration/config.md#database)).
378378
* `--db-working-dir`: Override the default working directory for the `db` service.

pkg/ddevapp/composer_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,22 @@ func TestComposerVersion(t *testing.T) {
126126
assert.NoError(err)
127127
assert.True(strings.HasPrefix(stdout, "Composer 2") || strings.HasPrefix(stdout, "Composer version 2"), "Composer version not the expected Composer 2: %v", stdout)
128128

129-
// Make sure it does the right thing with 1.x
129+
// With version "1" we should get Composer v2.2 LTS
130+
// See https://blog.packagist.com/shutting-down-packagist-org-support-for-composer-1-x/
130131
app.ComposerVersion = "1"
131132
err = app.Restart()
132133
require.NoError(t, err)
133134
stdout, _, err = app.Exec(&ddevapp.ExecOpts{Cmd: "composer --version"})
134135
assert.NoError(err)
135-
assert.Contains(stdout, "Composer version 1")
136+
assert.Contains(stdout, "Composer version 2.2")
137+
138+
// With version "1.10.25" we should also get Composer v2.2 LTS.
139+
app.ComposerVersion = "1.10.25"
140+
err = app.Restart()
141+
require.NoError(t, err)
142+
stdout, _, err = app.Exec(&ddevapp.ExecOpts{Cmd: "composer --version"})
143+
assert.NoError(err)
144+
assert.Contains(stdout, "Composer version 2.2")
136145

137146
// With version "2" we should be back to latest v2
138147
app.ComposerVersion = "2"

pkg/ddevapp/config.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ import (
2929
// Regexp pattern to determine if a hostname is valid per RFC 1123.
3030
var hostRegex = regexp.MustCompile(`^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$`)
3131

32+
// Regexp pattern to match Composer v1 versions: "1" or "1.x.y"
33+
var composerV1Regex = regexp.MustCompile(`^1(\.\d+\.\d+)?$`)
34+
3235
// RunValidateConfig controls whether to run ValidateConfig() function.
3336
// In some cases we don't actually need to check the config, e.g. when deleting the project.
3437
// It is enabled by default.
@@ -262,6 +265,11 @@ func (app *DdevApp) WriteConfig() error {
262265
appcopy.Type = nodeps.AppTypePHP
263266
}
264267

268+
if composerV1Regex.MatchString(appcopy.ComposerVersion) {
269+
appcopy.ComposerVersion = "2.2"
270+
util.WarningOnce(`Project '%s' now uses Composer v2.2 LTS. Composer v1 is no longer supported by Packagist, see https://blog.packagist.com/shutting-down-packagist-org-support-for-composer-1-x/`, app.Name)
271+
}
272+
265273
// We now want to reserve the port we're writing for HostDBPort and HostWebserverPort and so they don't
266274
// accidentally get used for other projects.
267275
err := app.UpdateGlobalProjectList()
@@ -854,7 +862,11 @@ func (app *DdevApp) CheckCustomConfig() {
854862

855863
// CheckDeprecations warns the user if anything in use is deprecated.
856864
func (app *DdevApp) CheckDeprecations() {
857-
865+
if composerV1Regex.MatchString(app.ComposerVersion) {
866+
app.ComposerVersion = "2.2"
867+
util.WarningOnce(`Project '%s' now uses Composer v2.2 LTS. Composer v1 is no longer supported by Packagist, see https://blog.packagist.com/shutting-down-packagist-org-support-for-composer-1-x/
868+
Run 'ddev config --auto' to remove this Composer warning.`, app.Name)
869+
}
858870
}
859871

860872
// FixObsolete removes files that may be obsolete, etc.
@@ -1456,7 +1468,7 @@ RUN (timeout %d apt-get update || true) && DEBIAN_FRONTEND=noninteractive apt-ge
14561468
}
14571469

14581470
// Major and minor versions have to be provided as option so add '--' prefix.
1459-
// E.g. a major version can be 1 or 2, a minor version 2.2 or 2.1 etc.
1471+
// E.g. a major version can be 2, a minor version 2.2 or 2.1 etc.
14601472
if strings.Count(composerVersion, ".") < 2 {
14611473
composerSelfUpdateArg = "--" + composerSelfUpdateArg
14621474
}

pkg/ddevapp/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ func TestComposerVersionConfig(t *testing.T) {
13271327
assert.NoError(err)
13281328
})
13291329

1330-
for _, testVersion := range []string{"2", "2.2", "2.5.5", "1", "stable", "preview", "snapshot"} {
1330+
for _, testVersion := range []string{"2", "2.2", "2.5.5", "stable", "preview", "snapshot"} {
13311331
app.ComposerVersion = testVersion
13321332
err = app.Start()
13331333
assert.NoError(err)

pkg/ddevapp/templates.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const ConfigInstructions = `
6969
# commands are executed.
7070
7171
# composer_version: "2"
72-
# You can set it to "" or "2" (default) for Composer v2 or "1" for Composer v1
72+
# You can set it to "" or "2" (default) for Composer v2
7373
# to use the latest major version available at the time your container is built.
7474
# It is also possible to use each other Composer version channel. This includes:
7575
# - 2.2 (latest Composer LTS version)

0 commit comments

Comments
 (0)