Skip to content
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
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ The CLI operates as a wrapper around a legacy PHP CLI:
**Commands**: `commands/`
- `root.go`: Root command that sets up the Cobra CLI and delegates to legacy CLI when needed
- Native Go commands: init, list, version, config:install, project:convert, completion, lint, and with Go auth (below): auth:browser-login (login), auth:api-token-login, auth:logout (logout), auth:token
- `lint.go`: Native config linter, `lint` (also `validate`; registered under the namespaced name `app:config-validate`). Validates Flex (`.upsun`) and Fixed (`.platform`) config in `pkg/lint`, reporting all errors at once. It looks for those names only, so it is not registered in CLIs configured with other names. `pkg/lint` and `pkg/registry` are public because other Upsun projects import them; their API is not covered by semantic versioning. The Flex JSON schema and the image registry come from meta.upsun.com (`make update-schema`, `make update-registry`): schema changes are made in the upsun/meta repository first. Fixed config is checked with the same schema, patched by `internal/schema/fixed-overlay.json` (a JSON Merge Patch adding Fixed-only keys such as `disk`)
- `lint.go`: Native config linter, `lint` (also `validate`; registered under the namespaced name `app:config-validate`). Validates Flex (`.upsun`) and Fixed (`.platform`) config in `pkg/lint`, reporting all errors at once. It looks for those names only, so it is not registered in CLIs configured with other names. `pkg/lint` and `pkg/registry` are public because other Upsun projects import them; their API is not covered by semantic versioning. The Flex JSON schema and the image registry (including composable image channels) come from meta.upsun.com (`make update-schema`, `make update-registry`): schema changes are made in the upsun/meta repository first. A version newer than the registry's (e.g. a new composable channel) is a warning, not an error, so that older CLIs accept it. Fixed config is checked with the same schema, patched by `internal/schema/fixed-overlay.json` (a JSON Merge Patch adding Fixed-only keys such as `disk`)
- Unrecognized commands are passed to the legacy PHP CLI

**Configuration**: `internal/config/`
Expand Down
8 changes: 4 additions & 4 deletions pkg/lint/fixed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ web:
name: "container features",
files: map[string]string{
".platform.app.yaml": `name: myapp
type: "composable:25.11"
type: "composable:26.05"
container_profile: HIGH_CPU
stack:
runtimes: ["php@8.4"]
Expand Down Expand Up @@ -194,7 +194,7 @@ authorizations:
name: "composable image with type and stack",
files: map[string]string{
".platform.app.yaml": `name: myapp
type: "composable:25.11"
type: "composable:26.05"
stack: {runtimes: ["php@8.3"]}`,
},
wantNoErr: true,
Expand All @@ -203,7 +203,7 @@ stack: {runtimes: ["php@8.3"]}`,
name: "composable image with an empty stack",
files: map[string]string{
".platform.app.yaml": `name: myapp
type: "composable:25.11"
type: "composable:26.05"
stack: []`,
},
wantNoErr: true,
Expand All @@ -212,7 +212,7 @@ stack: []`,
name: "composable image with a stack list",
files: map[string]string{
".platform.app.yaml": `name: myapp
type: "composable:25.11"
type: "composable:26.05"
stack: ["php@8.3"]`,
},
wantErrors: []string{"applications.myapp.stack: Array must have at most 0 items"},
Expand Down
16 changes: 8 additions & 8 deletions pkg/lint/linter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ tasks:
- type: env
action: view
composed:
type: composable:25.11
type: composable:26.05
stack: {runtimes: ["python@3.14"]}
run:
command: python run.py
Expand Down Expand Up @@ -313,12 +313,12 @@ tasks:
content: `
applications:
listed:
type: composable:25.11
type: composable:26.05
stack:
runtimes: ["php@8.4", {"nodejs@24": {}}]
packages: [yarn, {package: jq, channel: unstable}]
scalar:
type: composable:25.11
type: composable:26.05
stack:
runtimes: php@8.4
packages: yarn
Expand All @@ -333,13 +333,13 @@ routes:
content: `
applications:
empty_list:
type: composable:25.11
type: composable:26.05
stack: []
empty_map:
type: composable:25.11
type: composable:26.05
stack: {}
empty_runtimes:
type: composable:25.11
type: composable:26.05
stack: {runtimes: [], packages: []}
classic:
type: php:8.4
Expand Down Expand Up @@ -380,7 +380,7 @@ routes:
content: `
applications:
app:
type: composable:25.11
type: composable:26.05
stack: {runtimes: ["php@8.4"]}
egress:
runtime:
Expand All @@ -402,7 +402,7 @@ applications:
content: `
applications:
app:
type: composable:25.11
type: composable:26.05
stack: ["php@8.4"]
`,
wantErrors: `Linter errors:
Expand Down
125 changes: 69 additions & 56 deletions pkg/lint/testdata/registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@
]
}
},
"composable": {
"name": "Composable image",
"type": "composable",
"runtime": true,
"versions": {
"supported": [
"26.05"
],
"retired": [
"25.11"
]
}
},
"dotnet": {
"description": "ASP.NET 5 application container.",
"repo_name": "dotnet",
Expand Down Expand Up @@ -490,62 +503,6 @@
]
}
},
"mysql": {
"description": "A manufacture-based container for MariaDB",
"repo_name": "mariadb",
"disk": true,
"docs": {
"relationship_name": "mysql",
"service_name": "mysql",
"url": "/add-services/mysql.html"
},
"endpoint": "mysql",
"min_disk_size": 256,
"name": "MariaDB/MySQL",
"runtime": false,
"type": "mysql",
"versions": {
"deprecated": [
"10.2",
"10.1",
"10.0",
"5.5"
],
"supported": [
"11.0",
"10.11",
"10.6",
"10.5",
"10.4",
"10.3"
]
},
"versions-dedicated-gen-2": {
"supported": [
"10.5 Galera",
"10.4 Galera",
"10.3 Galera"
],
"deprecated": [
"10.2 Galera",
"10.1 Galera",
"10.0 Galera"
]
},
"versions-dedicated-gen-3": {
"supported": [
"10.11 Galera",
"10.6 Galera",
"10.5 Galera",
"10.4 Galera",
"10.3 Galera"
],
"deprecated": [
"10.2 Galera",
"10.1 Galera"
]
}
},
"memcached": {
"description": "Memcached service.",
"repo_name": "memcached",
Expand Down Expand Up @@ -638,6 +595,62 @@
]
}
},
"mysql": {
"description": "A manufacture-based container for MariaDB",
"repo_name": "mariadb",
"disk": true,
"docs": {
"relationship_name": "mysql",
"service_name": "mysql",
"url": "/add-services/mysql.html"
},
"endpoint": "mysql",
"min_disk_size": 256,
"name": "MariaDB/MySQL",
"runtime": false,
"type": "mysql",
"versions": {
"deprecated": [
"10.2",
"10.1",
"10.0",
"5.5"
],
"supported": [
"11.0",
"10.11",
"10.6",
"10.5",
"10.4",
"10.3"
]
},
"versions-dedicated-gen-2": {
"supported": [
"10.5 Galera",
"10.4 Galera",
"10.3 Galera"
],
"deprecated": [
"10.2 Galera",
"10.1 Galera",
"10.0 Galera"
]
},
"versions-dedicated-gen-3": {
"supported": [
"10.11 Galera",
"10.6 Galera",
"10.5 Galera",
"10.4 Galera",
"10.3 Galera"
],
"deprecated": [
"10.2 Galera",
"10.1 Galera"
]
}
},
"network-storage": {
"description": "",
"repo_name": "network-storage",
Expand Down
58 changes: 56 additions & 2 deletions pkg/lint/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lint
import (
"fmt"
"slices"
"strconv"
"strings"

"github.com/upsun/cli/pkg/registry"
Expand All @@ -12,7 +13,7 @@ import (
func checkTypes(cfg *config, reg registry.Registry) *Result {
result := &Result{}

// check reports an error, or a warning for a retired version, at path.
// check reports an error, or a warning for a retired or newer version, at path.
check := func(path, t string, runtime bool) {
warning, err := checkType(t, reg, runtime)
if err != nil {
Expand Down Expand Up @@ -76,7 +77,8 @@ func checkTypes(cfg *config, reg registry.Registry) *Result {
}

// checkType validates an image type and version. It returns a warning for a
// retired version, or an error if the type or version is not allowed.
// retired version or an unknown one that could be newer, or an error if the
// type or version is not allowed.
func checkType(t string, reg registry.Registry, runtime bool) (string, error) {
if t == "" {
return "", fmt.Errorf("type cannot be empty")
Expand Down Expand Up @@ -114,6 +116,13 @@ func checkType(t string, reg registry.Registry, runtime bool) (string, error) {
return "", fmt.Errorf("version '%s' is not precise enough for type '%s'%s",
version, imageType, mustBeOneOf)
}
// A version newer than all known ones may have been released since the registry was generated.
if len(img.Versions.Supported) > 0 {
if newest := slices.MaxFunc(allVersions, registry.CompareVersions); isNextVersion(version, newest) {
return fmt.Sprintf("unknown version '%s' of type '%s' (the newest known is %s)",
version, imageType, newest), nil
}
}
return "", fmt.Errorf("version '%s' is not supported for type '%s'%s",
version, imageType, mustBeOneOf)
}
Expand All @@ -133,3 +142,48 @@ func hasMajorVersion(l []string, v string) bool {
}
return false
}

// isNextVersion reports whether v could be a version released after newest. It
// must have as many numeric parts, and zero-padded parts as wide as newest's
// (e.g. 26.05).
// At the first part that differs, it must be at most one higher for the major
// part, and at most 12 higher for others (e.g. month-numbered versions, from
// 26.05 to 26.11). This leaves typos such as "84", "8.44" or "8.06" for "8.4"
// as errors.
func isNextVersion(v, newest string) bool {
vParts, newestParts := strings.Split(v, "."), strings.Split(newest, ".")
if len(vParts) != len(newestParts) {
return false
}
for i, p := range vParts {
if p == "" || strings.Trim(p, "0123456789") != "" {
return false
}
if n := newestParts[i]; (isZeroPadded(p) || isZeroPadded(n)) && len(p) != len(n) {
Comment thread
pjcdawkins marked this conversation as resolved.
Resolved
return false
}
}
for i, p := range vParts {
if p == newestParts[i] {
continue
}
vn, err := strconv.Atoi(p)
if err != nil {
return false
}
newestN, err := strconv.Atoi(newestParts[i])
if err != nil {
return false
}
maxStep := 12
if i == 0 {
maxStep = 1
}
return vn > newestN && vn-newestN <= maxStep
Comment thread
pjcdawkins marked this conversation as resolved.
Resolved
}
return false
}

func isZeroPadded(p string) bool {
return len(p) > 1 && p[0] == '0'
}
Loading
Loading