feat(docker): implement container management endpoints for start, stop, and restart

- Added Restart, Start, and Stop functions to manage Docker containers by ID.
- Introduced corresponding request structs (StartRequest, StopRequest) for handling input.
- Updated Swagger documentation to include new endpoints and request/response schemas.
This commit is contained in:
yusing
2025-09-04 07:30:51 +08:00
parent a1cd755597
commit 4941e9ec32
7 changed files with 642 additions and 0 deletions

View File

@@ -575,6 +575,138 @@ const docTemplate = `{
"x-id": "logs"
}
},
"/docker/restart": {
"post": {
"description": "Restart container by container id",
"produces": [
"application/json"
],
"tags": [
"docker"
],
"summary": "Restart container",
"parameters": [
{
"description": "Request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dockerapi.StopRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/SuccessResponse"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
}
},
"x-id": "restart"
}
},
"/docker/start": {
"post": {
"description": "Start container by container id",
"produces": [
"application/json"
],
"tags": [
"docker"
],
"summary": "Start container",
"parameters": [
{
"description": "Request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dockerapi.StartRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/SuccessResponse"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
}
},
"x-id": "start"
}
},
"/docker/stop": {
"post": {
"description": "Stop container by container id",
"produces": [
"application/json"
],
"tags": [
"docker"
],
"summary": "Stop container",
"parameters": [
{
"description": "Request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dockerapi.StopRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/SuccessResponse"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
}
},
"x-id": "stop"
}
},
"/favicon": {
"get": {
"description": "Get favicon",
@@ -3586,6 +3718,42 @@ const docTemplate = `{
}
}
},
"dockerapi.StartRequest": {
"type": "object",
"required": [
"id"
],
"properties": {
"checkpointDir": {
"type": "string"
},
"checkpointID": {
"type": "string"
},
"id": {
"type": "string"
}
}
},
"dockerapi.StopRequest": {
"type": "object",
"required": [
"id"
],
"properties": {
"id": {
"type": "string"
},
"signal": {
"description": "Signal (optional) is the signal to send to the container to (gracefully)\nstop it before forcibly terminating the container with SIGKILL after the\ntimeout expires. If not value is set, the default (SIGTERM) is used.",
"type": "string"
},
"timeout": {
"description": "Timeout (optional) is the timeout (in seconds) to wait for the container\nto stop gracefully before forcibly terminating it with SIGKILL.\n\n- Use nil to use the default timeout (10 seconds).\n- Use '-1' to wait indefinitely.\n- Use '0' to not wait for the container to exit gracefully, and\n immediately proceeds to forcibly terminating the container.\n- Other positive values are used as timeout (in seconds).",
"type": "integer"
}
}
},
"homepage.FetchResult": {
"type": "object",
"properties": {

View File

@@ -581,6 +581,141 @@
"operationId": "logs"
}
},
"/docker/restart": {
"post": {
"description": "Restart container by container id",
"produces": [
"application/json"
],
"tags": [
"docker"
],
"summary": "Restart container",
"parameters": [
{
"description": "Request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dockerapi.StopRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/SuccessResponse"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
}
},
"x-id": "restart",
"operationId": "restart"
}
},
"/docker/start": {
"post": {
"description": "Start container by container id",
"produces": [
"application/json"
],
"tags": [
"docker"
],
"summary": "Start container",
"parameters": [
{
"description": "Request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dockerapi.StartRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/SuccessResponse"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
}
},
"x-id": "start",
"operationId": "start"
}
},
"/docker/stop": {
"post": {
"description": "Stop container by container id",
"produces": [
"application/json"
],
"tags": [
"docker"
],
"summary": "Stop container",
"parameters": [
{
"description": "Request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dockerapi.StopRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/SuccessResponse"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
}
},
"x-id": "stop",
"operationId": "stop"
}
},
"/favicon": {
"get": {
"description": "Get favicon",
@@ -4281,6 +4416,58 @@
"x-nullable": false,
"x-omitempty": false
},
"dockerapi.StartRequest": {
"type": "object",
"required": [
"id"
],
"properties": {
"checkpointDir": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"checkpointID": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"id": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
}
},
"x-nullable": false,
"x-omitempty": false
},
"dockerapi.StopRequest": {
"type": "object",
"required": [
"id"
],
"properties": {
"id": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"signal": {
"description": "Signal (optional) is the signal to send to the container to (gracefully)\nstop it before forcibly terminating the container with SIGKILL after the\ntimeout expires. If not value is set, the default (SIGTERM) is used.",
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"timeout": {
"description": "Timeout (optional) is the timeout (in seconds) to wait for the container\nto stop gracefully before forcibly terminating it with SIGKILL.\n\n- Use nil to use the default timeout (10 seconds).\n- Use '-1' to wait indefinitely.\n- Use '0' to not wait for the container to exit gracefully, and\n immediately proceeds to forcibly terminating the container.\n- Other positive values are used as timeout (in seconds).",
"type": "integer",
"x-nullable": false,
"x-omitempty": false
}
},
"x-nullable": false,
"x-omitempty": false
},
"homepage.FetchResult": {
"type": "object",
"properties": {

View File

@@ -1097,6 +1097,41 @@ definitions:
used_percent:
type: number
type: object
dockerapi.StartRequest:
properties:
checkpointDir:
type: string
checkpointID:
type: string
id:
type: string
required:
- id
type: object
dockerapi.StopRequest:
properties:
id:
type: string
signal:
description: |-
Signal (optional) is the signal to send to the container to (gracefully)
stop it before forcibly terminating the container with SIGKILL after the
timeout expires. If not value is set, the default (SIGTERM) is used.
type: string
timeout:
description: |-
Timeout (optional) is the timeout (in seconds) to wait for the container
to stop gracefully before forcibly terminating it with SIGKILL.
- Use nil to use the default timeout (10 seconds).
- Use '-1' to wait indefinitely.
- Use '0' to not wait for the container to exit gracefully, and
immediately proceeds to forcibly terminating the container.
- Other positive values are used as timeout (in seconds).
type: integer
required:
- id
type: object
homepage.FetchResult:
properties:
errMsg:
@@ -1747,6 +1782,93 @@ paths:
- docker
- websocket
x-id: logs
/docker/restart:
post:
description: Restart container by container id
parameters:
- description: Request
in: body
name: request
required: true
schema:
$ref: '#/definitions/dockerapi.StopRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/SuccessResponse'
"403":
description: Forbidden
schema:
$ref: '#/definitions/ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/ErrorResponse'
summary: Restart container
tags:
- docker
x-id: restart
/docker/start:
post:
description: Start container by container id
parameters:
- description: Request
in: body
name: request
required: true
schema:
$ref: '#/definitions/dockerapi.StartRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/SuccessResponse'
"403":
description: Forbidden
schema:
$ref: '#/definitions/ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/ErrorResponse'
summary: Start container
tags:
- docker
x-id: start
/docker/stop:
post:
description: Stop container by container id
parameters:
- description: Request
in: body
name: request
required: true
schema:
$ref: '#/definitions/dockerapi.StopRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/SuccessResponse'
"403":
description: Forbidden
schema:
$ref: '#/definitions/ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/ErrorResponse'
summary: Stop container
tags:
- docker
x-id: stop
/favicon:
get:
consumes: