mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-10 18:05:48 +02:00
feat(self-check): add Docker socket existence check
This commit is contained in:
parent
3944be2369
commit
7dfb6e86e6
8 changed files with 48 additions and 2 deletions
|
@ -29,6 +29,8 @@ services:
|
||||||
nginx-ui-3:
|
nginx-ui-3:
|
||||||
image: nginx-ui-dev
|
image: nginx-ui-dev
|
||||||
container_name: nginx-ui-3
|
container_name: nginx-ui-3
|
||||||
|
environment:
|
||||||
|
- NGINX_UI_OFFICIAL_DOCKER=true
|
||||||
volumes:
|
volumes:
|
||||||
- ../..:/workspaces:cached
|
- ../..:/workspaces:cached
|
||||||
- ./data/nginx-ui-3/nginx:/etc/nginx
|
- ./data/nginx-ui-3/nginx:/etc/nginx
|
||||||
|
|
|
@ -70,7 +70,7 @@ func PerformCoreUpgrade(c *gin.Context) {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if helper.InNginxUIOfficialDocker() {
|
if helper.InNginxUIOfficialDocker() && helper.DockerSocketExists() {
|
||||||
upgrader.DockerUpgrade(ws, &control)
|
upgrader.DockerUpgrade(ws, &control)
|
||||||
} else {
|
} else {
|
||||||
upgrader.BinaryUpgrade(ws, &control)
|
upgrader.BinaryUpgrade(ws, &control)
|
||||||
|
|
|
@ -32,7 +32,7 @@ export function handleApiError(err: CosyError, dedupe: MessageDedupe) {
|
||||||
if (!errors[err.scope]) {
|
if (!errors[err.scope]) {
|
||||||
try {
|
try {
|
||||||
// Dynamic import error files
|
// Dynamic import error files
|
||||||
import(`@/constants/errors/${err.scope}.ts`)
|
import(/* @vite-ignore */ `@/constants/errors/${err.scope}.ts`)
|
||||||
.then(error => {
|
.then(error => {
|
||||||
registerError(err.scope!, error.default)
|
registerError(err.scope!, error.default)
|
||||||
displayErrorMessage(err, dedupe)
|
displayErrorMessage(err, dedupe)
|
||||||
|
|
|
@ -26,6 +26,14 @@ const backendTasks: Record<string, BackendTask> = {
|
||||||
description: () => $gettext('Check if the nginx.conf includes the conf.d directory.'),
|
description: () => $gettext('Check if the nginx.conf includes the conf.d directory.'),
|
||||||
type: 'backend',
|
type: 'backend',
|
||||||
},
|
},
|
||||||
|
'Docker-Socket': {
|
||||||
|
name: () => $gettext('Docker Socket'),
|
||||||
|
description: () => $gettext('Check if /var/run/docker.sock exists. '
|
||||||
|
+ 'If you are using Nginx UI Official Docker Image, '
|
||||||
|
+ 'please make sure the docker socket is mounted like this: '
|
||||||
|
+ '`-v /var/run/docker.sock:/var/run/docker.sock`.'),
|
||||||
|
type: 'backend',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
export default backendTasks
|
export default backendTasks
|
||||||
|
|
|
@ -9,3 +9,14 @@ import (
|
||||||
func InNginxUIOfficialDocker() bool {
|
func InNginxUIOfficialDocker() bool {
|
||||||
return cast.ToBool(os.Getenv("NGINX_UI_OFFICIAL_DOCKER"))
|
return cast.ToBool(os.Getenv("NGINX_UI_OFFICIAL_DOCKER"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DockerSocketExists() bool {
|
||||||
|
if !InNginxUIOfficialDocker() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
_, err := os.Stat("/var/run/docker.sock")
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
17
internal/self_check/docker.go
Normal file
17
internal/self_check/docker.go
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package self_check
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CheckDockerSocket() error {
|
||||||
|
if !helper.InNginxUIOfficialDocker() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if !helper.DockerSocketExists() {
|
||||||
|
return ErrDockerSocketNotExist
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -17,4 +17,5 @@ var (
|
||||||
ErrStreamAvailableNotExist = e.New(4048, "Streams-available directory not exist")
|
ErrStreamAvailableNotExist = e.New(4048, "Streams-available directory not exist")
|
||||||
ErrStreamEnabledNotExist = e.New(4049, "Streams-enabled directory not exist")
|
ErrStreamEnabledNotExist = e.New(4049, "Streams-enabled directory not exist")
|
||||||
ErrNginxConfNotIncludeConfD = e.New(4050, "Nginx conf not include conf.d directory")
|
ErrNginxConfNotIncludeConfD = e.New(4050, "Nginx conf not include conf.d directory")
|
||||||
|
ErrDockerSocketNotExist = e.New(4051, "Docker socket not exist")
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,6 +3,7 @@ package self_check
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
|
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||||
"github.com/uozi-tech/cosy"
|
"github.com/uozi-tech/cosy"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -53,6 +54,12 @@ func init() {
|
||||||
for _, task := range selfCheckTasks {
|
for _, task := range selfCheckTasks {
|
||||||
selfCheckTaskMap[task.Name] = task
|
selfCheckTaskMap[task.Name] = task
|
||||||
}
|
}
|
||||||
|
if helper.InNginxUIOfficialDocker() {
|
||||||
|
selfCheckTasks = append(selfCheckTasks, &Task{
|
||||||
|
Name: "Docker-Socket",
|
||||||
|
CheckFunc: CheckDockerSocket,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Run() (reports Reports) {
|
func Run() (reports Reports) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue