Skip to content

Commit

Permalink
feat: enable flag guard
Browse files Browse the repository at this point in the history
  • Loading branch information
CorrectRoadH committed Jan 24, 2024
1 parent 2a91016 commit aca5db9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
After=casaos-message-bus.service
After=docker.service
Description=CasaOS App Management Service

[Service]
ExecStartPre=/usr/bin/casaos-app-management -v
ExecStart=/usr/bin/casaos-app-management -c /etc/casaos/app-management.conf -r true
PIDFile=/var/run/casaos/app-management.pid
Restart=always
Type=notify

[Install]
WantedBy=multi-user.target
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func main() {
{
configFlag := flag.String("c", "", "config file path")
versionFlag := flag.Bool("v", false, "version")
removeRuntimeWithoutNvidiaGPUFlag := flag.Bool("r", false, "remove runtime with nvidia gpu")

flag.Parse()

Expand All @@ -65,6 +66,8 @@ func main() {
logger.LogInit(config.AppInfo.LogPath, config.AppInfo.LogSaveName, config.AppInfo.LogFileExt)

service.MyService = service.NewService(config.CommonInfo.RuntimePath)

config.RemoveRuntimeWithoutNvidiaGPUFlag = *removeRuntimeWithoutNvidiaGPUFlag
}

// setup cron
Expand Down
5 changes: 3 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

var (
AppManagementConfigFilePath = filepath.Join(constants.DefaultConfigPath, "app-management.conf")
AppManagementGlobalEnvFilePath = filepath.Join(constants.DefaultConfigPath, "env")
AppManagementConfigFilePath = filepath.Join(constants.DefaultConfigPath, "app-management.conf")
AppManagementGlobalEnvFilePath = filepath.Join(constants.DefaultConfigPath, "env")
RemoveRuntimeWithoutNvidiaGPUFlag = false
)
20 changes: 12 additions & 8 deletions service/compose_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1036,15 +1036,19 @@ func NewComposeAppFromYAML(yaml []byte, skipInterpolation, skipValidation bool)
composeApp.SetTitle(composeApp.Name, common.DefaultLanguage)
}

value, err := cache.Get("gpus")
if err != nil {
value, err = external.GPUInfoList()
cache.Set("gpus", value)
}
if config.RemoveRuntimeWithoutNvidiaGPUFlag {
value, err := cache.Get("gpus")
if err != nil {
value, err = external.GPUInfoList()
cache.Set("gpus", value)
} else {
cache.Set("gpus", []external.GPUInfo{})
}

Check warning on line 1046 in service/compose_app.go

View check run for this annotation

Codecov / codecov/patch

service/compose_app.go#L1040-L1046

Added lines #L1040 - L1046 were not covered by tests

// without nvidia-smi // no gpu
if err != nil || len(value.([]external.GPUInfo)) == 0 {
removeRuntime(composeApp)
// without nvidia-smi // no gpu
if err != nil || len(value.([]external.GPUInfo)) == 0 {
removeRuntime(composeApp)
}

Check warning on line 1051 in service/compose_app.go

View check run for this annotation

Codecov / codecov/patch

service/compose_app.go#L1049-L1051

Added lines #L1049 - L1051 were not covered by tests
}

// pass icon information to v1 label for backward compatibility, because we are
Expand Down

0 comments on commit aca5db9

Please sign in to comment.