Skip to content

Commit

Permalink
feat: add uncontrolled field to difference application (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
CorrectRoadH committed Mar 18, 2024
1 parent c9ed263 commit d495fbd
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 20 deletions.
35 changes: 34 additions & 1 deletion api/app_management/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ paths:
parameters:
- $ref: "#/components/parameters/DryRun"
- $ref: "#/components/parameters/CheckPortConflict"
- $ref: "#/components/parameters/Uncontrolled"
requestBody:
$ref: "#/components/requestBodies/RequestComposeApp"
responses:
Expand Down Expand Up @@ -783,6 +784,18 @@ components:
type: boolean
default: true

Uncontrolled:
name: uncontrolled
description: |
Install the app without any control. the control mean version control, if the app is stable and latest. it is controlled, It will auto update. otherwise it is uncontrolled.
- `true` - uncontrolled install
- `false` - normal install
in: query
schema:
type: boolean
example: false

requestBodies:
RequestComposeApp:
description: Compose app YAML content
Expand Down Expand Up @@ -1319,7 +1332,15 @@ components:
- "arm64"
x-oapi-codegen-extra-tags:
yaml: ",omitempty"

is_uncontrolled: # uncontrolled == not stable and latest
title: is the app uncontrolled.
description: |
the mean the image tag is custom. not stable or latest
type: boolean
example: false
x-oapi-codegen-extra-tags:
yaml: ",omitempty"

ComposeApp:
type: object
description: |-
Expand Down Expand Up @@ -1350,6 +1371,15 @@ components:
example: true
x-oapi-codegen-extra-tags:
yaml: ",omitempty"
is_uncontrolled:
readOnly: true
title: is the app uncontrolled.
description: |
the mean the image tag is custom. not stable or latest
type: boolean
example: false
x-oapi-codegen-extra-tags:
yaml: ",omitempty"

ComposeAppValidationErrors:
description: |-
Expand Down Expand Up @@ -1621,3 +1651,6 @@ components:
image:
type: string
example: gitea/gitea:1
is_uncontrolled:
type: boolean
example: false
7 changes: 4 additions & 3 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ const (

ComposeAppAuthorCasaOSTeam = "CasaOS Team"

ComposeExtensionNameXCasaOS = "x-casaos"
ComposeExtensionPropertyNameStoreAppID = "store_app_id"
ComposeExtensionPropertyNameTitle = "title"
ComposeExtensionNameXCasaOS = "x-casaos"
ComposeExtensionPropertyNameStoreAppID = "store_app_id"
ComposeExtensionPropertyNameTitle = "title"
ComposeExtensionPropertyNameIsUncontrolled = "is_uncontrolled"

ComposeYAMLFileName = "docker-compose.yml"

Expand Down
33 changes: 17 additions & 16 deletions model/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,23 @@ type ServerAppList struct {
}

type MyAppList struct {
ID string `json:"id"`
Name string `json:"name"`
Icon string `json:"icon"`
State string `json:"state"`
CustomID string `gorm:"column:custom_id;primary_key" json:"custom_id"`
Index string `json:"index"`
Port string `json:"port"`
Slogan string `json:"slogan"`
Type string `json:"type"`
Image string `json:"image"`
Volumes string `json:"volumes"`
Latest bool `json:"latest"`
Host string `json:"host"`
Protocol string `json:"protocol"`
Created int64 `json:"created"`
AppStoreID uint `json:"appstore_id"`
ID string `json:"id"`
Name string `json:"name"`
Icon string `json:"icon"`
State string `json:"state"`
CustomID string `gorm:"column:custom_id;primary_key" json:"custom_id"`
Index string `json:"index"`
Port string `json:"port"`
Slogan string `json:"slogan"`
Type string `json:"type"`
Image string `json:"image"`
Volumes string `json:"volumes"`
Latest bool `json:"latest"`
Host string `json:"host"`
Protocol string `json:"protocol"`
Created int64 `json:"created"`
AppStoreID uint `json:"appstore_id"`
IsUncontrolled bool `json:"is_uncontrolled"`
}

type Ports struct {
Expand Down
17 changes: 17 additions & 0 deletions route/v2/compose_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,17 @@ func (a *AppManagement) InstallComposeApp(ctx echo.Context, params codegen.Insta
})
}

if params.Uncontrolled != nil && *params.Uncontrolled {
xcasaos := composeApp.Extensions[common.ComposeExtensionNameXCasaOS]
xcasaosMap, ok := xcasaos.(map[string]interface{})
if !ok {
logger.Error("failed to get map compose app extensions", zap.String("composeAppID", composeApp.Name))
} else {
xcasaosMap[common.ComposeExtensionPropertyNameIsUncontrolled] = true
composeApp.Extensions[common.ComposeExtensionNameXCasaOS] = xcasaosMap
}
}

if service.MyService.Compose().IsInstalling(composeApp.Name) {
message := fmt.Sprintf("compose app `%s` is already being installed", composeApp.Name)
return ctx.JSON(http.StatusConflict, codegen.ComposeAppBadRequest{Message: &message})
Expand Down Expand Up @@ -578,6 +589,7 @@ func composeAppsWithStoreInfo(ctx context.Context) (map[string]codegen.ComposeAp
StoreInfo: nil,
Status: utils.Ptr("unknown"),
UpdateAvailable: utils.Ptr(false),
IsUncontrolled: utils.Ptr(false),
}

storeInfo, err := composeApp.StoreInfo(true)
Expand Down Expand Up @@ -611,6 +623,11 @@ func composeAppsWithStoreInfo(ctx context.Context) (map[string]codegen.ComposeAp
return composeAppWithStoreInfo
}

isUncontrolled, ok := composeApp.Extensions[common.ComposeExtensionNameXCasaOS].(map[string]interface{})[common.ComposeExtensionPropertyNameIsUncontrolled].(bool)
if ok {
composeAppWithStoreInfo.IsUncontrolled = &isUncontrolled
}

// Because of a stupid design by @tigerinus, the `composeApp.Containers(...)` func above was returning a map
// of docker compose `service` to a single container:
//
Expand Down
5 changes: 5 additions & 0 deletions route/v2/internal_web.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func WebAppGridItemAdapterV2(composeAppWithStoreInfo *codegen.ComposeAppWithStor
Title: lo.ToPtr(map[string]string{
common.DefaultLanguage: composeApp.Name,
}),
IsUncontrolled: composeAppWithStoreInfo.StoreInfo.IsUncontrolled,
}

composeAppStoreInfo := composeAppWithStoreInfo.StoreInfo
Expand All @@ -144,6 +145,7 @@ func WebAppGridItemAdapterV2(composeAppWithStoreInfo *codegen.ComposeAppWithStor
item.Status = composeAppWithStoreInfo.Status
item.StoreAppID = composeAppStoreInfo.StoreAppID
item.Title = &composeAppStoreInfo.Title
item.IsUncontrolled = composeAppStoreInfo.IsUncontrolled

var mainApp *types.ServiceConfig
for i, service := range composeApp.Services {
Expand All @@ -158,6 +160,7 @@ func WebAppGridItemAdapterV2(composeAppWithStoreInfo *codegen.ComposeAppWithStor
// item type
itemAuthorType := composeApp.AuthorType()
item.AuthorType = &itemAuthorType
item.IsUncontrolled = composeAppWithStoreInfo.IsUncontrolled

return item, nil
}
Expand All @@ -180,6 +183,7 @@ func WebAppGridItemAdapterV1(app *model.MyAppList) (*codegen.WebAppGridItem, err
Title: &map[string]string{
common.DefaultLanguage: app.Name,
},
IsUncontrolled: &app.IsUncontrolled,
}

return item, nil
Expand All @@ -198,6 +202,7 @@ func WebAppGridItemAdapterContainer(container *model.MyAppList) (*codegen.WebApp
Title: &map[string]string{
common.DefaultLanguage: container.Name,
},
IsUncontrolled: &container.IsUncontrolled,
}

return item, nil
Expand Down

0 comments on commit d495fbd

Please sign in to comment.