Skip to content

Commit

Permalink
feat: default runtime version
Browse files Browse the repository at this point in the history
  • Loading branch information
mlhiter committed Nov 7, 2024
1 parent c67bf20 commit f93f754
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 28 deletions.
69 changes: 41 additions & 28 deletions frontend/providers/devbox/app/api/platform/getRuntime/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,19 @@ export async function GET(req: NextRequest) {
languageList.forEach((item: any) => {
const language = item.metadata.name
const versions = runtimes.filter((runtime: any) => runtime.spec.classRef === language)
languageVersionMap[language] = []
versions.forEach((version: any) => {
runtimeNamespaceMap[version.metadata.name] = item.metadata.namespace
languageVersionMap[language].push({
id: version.metadata.name,
label: version.spec.version,
defaultPorts: version.spec.config.appPorts.map((item: any) => item.port)
})
})
const defaultVersion = versions.find(
(v: any) => v.metadata.annotations?.['devbox.sealos.io/defaultVersion'] === 'true'
)
const otherVersions = versions.filter(
(v: any) => v.metadata.annotations?.['devbox.sealos.io/defaultVersion'] !== 'true'
)
const sortedVersions = defaultVersion ? [defaultVersion, ...otherVersions] : versions

languageVersionMap[language] = sortedVersions.map((version: any) => ({
id: version.metadata.name,
label: version.spec.version,
defaultPorts: version.spec.config.appPorts.map((item: any) => item.port)
}))
if (languageVersionMap[language].length === 0) {
delete languageVersionMap[language]
const index = languageTypeList.findIndex((item) => item.id === language)
Expand All @@ -98,15 +102,19 @@ export async function GET(req: NextRequest) {
frameworkList.forEach((item: any) => {
const framework = item.metadata.name
const versions = runtimes.filter((runtime: any) => runtime.spec.classRef === framework)
frameworkVersionMap[framework] = []
versions.forEach((version: any) => {
runtimeNamespaceMap[version.metadata.name] = item.metadata.namespace
frameworkVersionMap[framework].push({
id: version.metadata.name,
label: version.spec.version,
defaultPorts: version.spec.config.appPorts.map((item: any) => item.port)
})
})
const defaultVersion = versions.find(
(v: any) => v.metadata.annotations?.['devbox.sealos.io/defaultVersion'] === 'true'
)
const otherVersions = versions.filter(
(v: any) => v.metadata.annotations?.['devbox.sealos.io/defaultVersion'] !== 'true'
)
const sortedVersions = defaultVersion ? [defaultVersion, ...otherVersions] : versions

frameworkVersionMap[framework] = sortedVersions.map((version: any) => ({
id: version.metadata.name,
label: version.spec.version,
defaultPorts: version.spec.config.appPorts.map((item: any) => item.port)
}))
if (frameworkVersionMap[framework].length === 0) {
delete frameworkVersionMap[framework]
const index = frameworkTypeList.findIndex((item) => item.id === framework)
Expand All @@ -115,23 +123,28 @@ export async function GET(req: NextRequest) {
}
}
})

osList.forEach((item: any) => {
const os = item.metadata.name
const versions = runtimes.filter((runtime: any) => runtime.spec.classRef === os)
osVersionMap[os] = []
versions.forEach((version: any) => {
runtimeNamespaceMap[version.metadata.name] = item.metadata.namespace
osVersionMap[os].push({
id: version.metadata.name,
label: version.spec.version,
defaultPorts: version.spec.config.appPorts.map((item: any) => item.port)
})
})
const defaultVersion = versions.find(
(v: any) => v.metadata.annotations?.['devbox.sealos.io/defaultVersion'] === 'true'
)
const otherVersions = versions.filter(
(v: any) => v.metadata.annotations?.['devbox.sealos.io/defaultVersion'] !== 'true'
)
const sortedVersions = defaultVersion ? [defaultVersion, ...otherVersions] : versions

osVersionMap[os] = sortedVersions.map((version: any) => ({
id: version.metadata.name,
label: version.spec.version,
defaultPorts: version.spec.config.appPorts.map((item: any) => item.port)
}))
if (osVersionMap[os].length === 0) {
delete osVersionMap[os]
const index = osTypeList.findIndex((item) => item.id === os)
if (index !== -1) {
frameworkTypeList.splice(index, 1)
osTypeList.splice(index, 1)
}
}
})
Expand Down
3 changes: 3 additions & 0 deletions frontend/providers/devbox/types/k8s.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ export type KBRuntimeType = {
namespace: string
uid: string
creationTimestamp: string
annotations: {
'devbox.sealos.io/defaultVersion': boolean
}
}
spec: {
classRef: string
Expand Down

0 comments on commit f93f754

Please sign in to comment.