Documentation
¶
Index ¶
- type Controller
- func (ctrl *Controller) Changes(c *gin.Context)
- func (ctrl *Controller) Create(c *gin.Context)
- func (ctrl *Controller) Exec(c *gin.Context)
- func (ctrl *Controller) GetContainer(c *gin.Context)
- func (ctrl *Controller) GetFiles(c *gin.Context)
- func (ctrl *Controller) ListContainers(c *gin.Context)
- func (ctrl *Controller) Logs(c *gin.Context)
- func (ctrl *Controller) Pause(c *gin.Context)
- func (ctrl *Controller) PutFiles(c *gin.Context)
- func (ctrl *Controller) RegisterRoutes(router *gin.RouterGroup, authMW *middleware.AuthMiddleware)
- func (ctrl *Controller) Remove(c *gin.Context)
- func (ctrl *Controller) Rename(c *gin.Context)
- func (ctrl *Controller) Restart(c *gin.Context)
- func (ctrl *Controller) Start(c *gin.Context)
- func (ctrl *Controller) Stats(c *gin.Context)
- func (ctrl *Controller) Stop(c *gin.Context)
- func (ctrl *Controller) Top(c *gin.Context)
- func (ctrl *Controller) Unpause(c *gin.Context)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller handles container-related API requests
func NewController ¶
func NewController( containerService container.Service, dockerManager docker.Manager, logger *logrus.Logger, ) *Controller
NewController creates a new container controller
func (*Controller) Changes ¶
func (ctrl *Controller) Changes(c *gin.Context)
Changes godoc @Summary Inspect changes on a container's filesystem @Description Shows changes to files or directories on a container's filesystem since it was created. @Tags Containers @Produce json @Security BearerAuth @Param id path string true "Container ID or Name" example(my-nginx-container) @Success 200 {object} models.SuccessResponse{data=[]models.ChangeItemResponse} "Successfully retrieved filesystem changes" @Failure 400 {object} models.ErrorResponse "Invalid container ID" @Failure 401 {object} models.ErrorResponse "Authentication required" @Failure 403 {object} models.ErrorResponse "Permission denied" @Failure 404 {object} models.ErrorResponse "Container not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /containers/{id}/changes [get]
func (*Controller) Create ¶
func (ctrl *Controller) Create(c *gin.Context)
Create godoc @Summary Create a new container @Description Creates a new Docker container based on the provided configuration. @Tags Containers @Accept json @Produce json @Security BearerAuth @Param container body models.ContainerCreateRequest true "Container Configuration" @Success 201 {object} models.SuccessResponse{data=models.Container} "Successfully created container" @Failure 400 {object} models.ErrorResponse "Invalid input or configuration" @Failure 401 {object} models.ErrorResponse "Authentication required" @Failure 403 {object} models.ErrorResponse "Permission denied (e.g., creating privileged container as non-admin)" @Failure 404 {object} models.ErrorResponse "Image not found (if pull fails)" @Failure 409 {object} models.ErrorResponse "Container name already in use" @Failure 500 {object} models.ErrorResponse "Internal server error (e.g., Docker daemon error)" @Router /containers [post]
func (*Controller) Exec ¶
func (ctrl *Controller) Exec(c *gin.Context)
Exec handles POST /containers/:id/exec @Summary Execute Command in Container @Description Creates and starts an exec instance in a running container. @Description Supports both non-interactive execution (HTTP POST) and interactive sessions (WebSocket upgrade). @Description For interactive sessions, upgrade the connection to WebSocket. @Tags Containers @Accept json @Produce json @Security BearerAuth @Param id path string true "Container ID" example(my-running-container) @Param exec body models.ContainerExecCreateRequest true "Exec configuration" @Success 200 {object} models.ContainerExecResponse "Success (non-interactive)" @Success 101 {string} string "Switching Protocols (interactive WebSocket)" @Failure 400 {object} models.ErrorResponse "Bad Request (e.g., missing command, invalid ID)" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 403 {object} models.ErrorResponse "Forbidden (user lacks permission)" @Failure 404 {object} models.ErrorResponse "Container Not Found" @Failure 500 {object} models.ErrorResponse "Internal Server Error" @Router /api/v1/containers/{id}/exec [post]
func (*Controller) GetContainer ¶
func (ctrl *Controller) GetContainer(c *gin.Context)
GetContainer godoc @Summary Get container details @Description Get detailed information about a specific container. @Tags Containers @Produce json @Security BearerAuth @Param id path string true "Container ID or Name" example(my-nginx-container) @Success 200 {object} models.SuccessResponse{data=models.ContainerResponse} "Successfully retrieved container details" @Failure 400 {object} models.ErrorResponse "Invalid container ID" @Failure 401 {object} models.ErrorResponse "Authentication required" @Failure 403 {object} models.ErrorResponse "Permission denied" @Failure 404 {object} models.ErrorResponse "Container not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /containers/{id} [get]
func (*Controller) GetFiles ¶
func (ctrl *Controller) GetFiles(c *gin.Context)
GetFiles godoc @Summary Download file or directory from container @Description Retrieves a file or directory from a container as a TAR archive. @Tags Containers @Produce application/x-tar @Security BearerAuth @Param id path string true "Container ID or Name" example(my-nginx-container) @Param path query string true "Absolute path to the file or directory inside the container" example(/etc/nginx/nginx.conf) @Success 200 {file} binary "TAR archive of the requested path" @Failure 400 {object} models.ErrorResponse "Invalid container ID or missing path parameter" @Failure 401 {object} models.ErrorResponse "Authentication required" @Failure 403 {object} models.ErrorResponse "Permission denied" @Failure 404 {object} models.ErrorResponse "Container or path not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /containers/{id}/files [get]
func (*Controller) ListContainers ¶
func (ctrl *Controller) ListContainers(c *gin.Context)
ListContainers godoc @Summary List containers @Description Get a list of containers based on optional filters. @Tags Containers @Produce json @Security BearerAuth @Param all query bool false "Show all containers (default shows just running)" default(false) @Param limit query int false "Maximum number of containers to return" default(-1) @Param size query bool false "Return container sizes" default(false) @Param filters query string false "Filters to apply (JSON map format, e.g., {\"status\":[\"running\"]})" @Success 200 {object} models.SuccessResponse{data=models.ContainerListResponse} "Successfully retrieved container list" @Failure 400 {object} models.ErrorResponse "Invalid filter format" @Failure 401 {object} models.ErrorResponse "Authentication required" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /containers [get]
func (*Controller) Logs ¶
func (ctrl *Controller) Logs(c *gin.Context)
Logs godoc @Summary Get container logs @Description Retrieves logs from a container. Can optionally stream logs. @Tags Containers @Produce plain @Security BearerAuth @Param id path string true "Container ID or Name" example(my-nginx-container) @Param follow query bool false "Stream logs" default(false) example(true) @Param stdout query bool false "Include stdout" default(true) example(true) @Param stderr query bool false "Include stderr" default(true) example(true) @Param since query string false "Show logs since timestamp (e.g., 2013-01-02T13:23:37Z) or relative (e.g., 42m for 42 minutes)" example(1h) @Param until query string false "Show logs before timestamp (e.g., 2013-01-02T13:23:37Z) or relative (e.g., 42m for 42 minutes)" example(2023-10-27T11:00:00Z) @Param timestamps query bool false "Show timestamps" default(false) example(true) @Param tail query string false "Number of lines to show from the end of the logs (e.g., 100 or all)" default("all") example(50) @Success 200 {string} string "Container logs stream" @Failure 400 {object} models.ErrorResponse "Invalid container ID or query parameters" @Failure 401 {object} models.ErrorResponse "Authentication required" @Failure 403 {object} models.ErrorResponse "Permission denied" @Failure 404 {object} models.ErrorResponse "Container not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /containers/{id}/logs [get]
func (*Controller) Pause ¶
func (ctrl *Controller) Pause(c *gin.Context)
Pause godoc @Summary Pause a container @Description Pauses a running container. @Tags Containers @Produce json @Security BearerAuth @Param id path string true "Container ID or Name" example(my-nginx-container) @Success 204 "Container paused successfully" @Failure 400 {object} models.ErrorResponse "Invalid container ID" @Failure 401 {object} models.ErrorResponse "Authentication required" @Failure 403 {object} models.ErrorResponse "Permission denied" @Failure 404 {object} models.ErrorResponse "Container not found or not running" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /containers/{id}/pause [post]
func (*Controller) PutFiles ¶
func (ctrl *Controller) PutFiles(c *gin.Context)
PutFiles godoc @Summary Upload file or directory to container @Description Uploads a TAR archive to a specified path within a container. The request body must be the TAR archive. @Tags Containers @Accept application/x-tar @Produce json @Security BearerAuth @Param id path string true "Container ID or Name" example(my-nginx-container) @Param path query string true "Absolute destination path inside the container" example(/usr/share/nginx/html) @Param archive body []byte true "TAR archive content" @Success 200 {object} models.SuccessResponse{message=string} "Archive successfully uploaded" @Failure 400 {object} models.ErrorResponse "Invalid container ID, missing path parameter, or empty/invalid request body (e.g., malformed tar)" @Failure 401 {object} models.ErrorResponse "Authentication required" @Failure 403 {object} models.ErrorResponse "Permission denied" @Failure 404 {object} models.ErrorResponse "Container not found" @Failure 500 {object} models.ErrorResponse "Internal server error (e.g., failed to write archive)" @Router /containers/{id}/files [post]
func (*Controller) RegisterRoutes ¶
func (ctrl *Controller) RegisterRoutes(router *gin.RouterGroup, authMW *middleware.AuthMiddleware)
RegisterRoutes registers the container API routes
func (*Controller) Remove ¶
func (ctrl *Controller) Remove(c *gin.Context)
Remove godoc @Summary Remove a container @Description Removes a container. @Tags Containers @Produce json @Security BearerAuth @Param id path string true "Container ID or Name" example(my-nginx-container) @Param force query bool false "Force removal of a running container" default(false) example(true) @Param volumes query bool false "Remove anonymous volumes associated with the container" default(false) example(true) @Success 204 "Container removed successfully" @Failure 400 {object} models.ErrorResponse "Invalid container ID" @Failure 401 {object} models.ErrorResponse "Authentication required" @Failure 403 {object} models.ErrorResponse "Permission denied" @Failure 404 {object} models.ErrorResponse "Container not found" @Failure 409 {object} models.ErrorResponse "Conflict (e.g., container is running and force=false)" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /containers/{id} [delete]
func (*Controller) Rename ¶
func (ctrl *Controller) Rename(c *gin.Context)
Rename godoc @Summary Rename a container @Description Renames an existing container. @Tags Containers @Accept json @Produce json @Security BearerAuth @Param id path string true "Container ID or Name" example(my-nginx-container) @Param name body models.ContainerRenameRequest true "New Container Name" @Success 200 {object} models.SuccessResponse{data=models.ContainerResponse} "Successfully renamed container" @Failure 400 {object} models.ErrorResponse "Invalid container ID or new name" @Failure 401 {object} models.ErrorResponse "Authentication required" @Failure 403 {object} models.ErrorResponse "Permission denied" @Failure 404 {object} models.ErrorResponse "Container not found" @Failure 409 {object} models.ErrorResponse "New name already in use" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /containers/{id}/rename [post]
func (*Controller) Restart ¶
func (ctrl *Controller) Restart(c *gin.Context)
Restart godoc @Summary Restart a container @Description Restarts a container. @Tags Containers @Produce json @Security BearerAuth @Param id path string true "Container ID or Name" example(my-nginx-container) @Param timeout query int false "Timeout in seconds to wait for container to stop before starting it" default(10) example(5) @Success 204 "Container restarted successfully" @Failure 400 {object} models.ErrorResponse "Invalid container ID or timeout" @Failure 401 {object} models.ErrorResponse "Authentication required" @Failure 403 {object} models.ErrorResponse "Permission denied" @Failure 404 {object} models.ErrorResponse "Container not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /containers/{id}/restart [post]
func (*Controller) Start ¶
func (ctrl *Controller) Start(c *gin.Context)
Start godoc @Summary Start a container @Description Starts a stopped or created container. @Tags Containers @Produce json @Security BearerAuth @Param id path string true "Container ID or Name" example(my-nginx-container) @Success 204 "Container started successfully" @Failure 400 {object} models.ErrorResponse "Invalid container ID" @Failure 401 {object} models.ErrorResponse "Authentication required" @Failure 403 {object} models.ErrorResponse "Permission denied" @Failure 404 {object} models.ErrorResponse "Container not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /containers/{id}/start [post]
func (*Controller) Stats ¶
func (ctrl *Controller) Stats(c *gin.Context)
Stats godoc @Summary Get container resource usage statistics @Description Retrieves a live stream or a single snapshot of resource usage statistics for a container. @Tags Containers @Produce json @Security BearerAuth @Param id path string true "Container ID or Name" example(my-nginx-container) @Param stream query bool false "Stream stats (true) or get a single snapshot (false)" default(false) example(true) @Success 200 {object} models.SuccessResponse{data=models.ContainerStats} "Container statistics (if stream=false)" @Success 200 {string} string "Container statistics stream (if stream=true, Content-Type: text/event-stream)" @Failure 400 {object} models.ErrorResponse "Invalid container ID" @Failure 401 {object} models.ErrorResponse "Authentication required" @Failure 403 {object} models.ErrorResponse "Permission denied" @Failure 404 {object} models.ErrorResponse "Container not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /containers/{id}/stats [get]
func (*Controller) Stop ¶
func (ctrl *Controller) Stop(c *gin.Context)
Stop godoc @Summary Stop a container @Description Stops a running container. @Tags Containers @Produce json @Security BearerAuth @Param id path string true "Container ID or Name" example(my-nginx-container) @Param timeout query int false "Timeout in seconds to wait for container to stop before killing it" default(10) example(5) @Success 204 "Container stopped successfully" @Failure 400 {object} models.ErrorResponse "Invalid container ID or timeout" @Failure 401 {object} models.ErrorResponse "Authentication required" @Failure 403 {object} models.ErrorResponse "Permission denied" @Failure 404 {object} models.ErrorResponse "Container not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /containers/{id}/stop [post]
func (*Controller) Top ¶
func (ctrl *Controller) Top(c *gin.Context)
Top godoc @Summary List processes running inside a container @Description Shows the processes running inside a container, similar to the 'top' command. @Tags Containers @Produce json @Security BearerAuth @Param id path string true "Container ID or Name" @Param ps_args query string false "Arguments to pass to 'ps' command (e.g., -ef)" default("") @Success 200 {object} models.SuccessResponse{data=models.TopResponse} "Successfully retrieved process list" @Failure 400 {object} models.ErrorResponse "Invalid container ID" @Failure 401 {object} models.ErrorResponse "Authentication required" @Failure 403 {object} models.ErrorResponse "Permission denied" @Failure 404 {object} models.ErrorResponse "Container not found or not running" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /containers/{id}/top [get]
func (*Controller) Unpause ¶
func (ctrl *Controller) Unpause(c *gin.Context)
Unpause godoc @Summary Unpause a container @Description Unpauses a paused container. @Tags Containers @Produce json @Security BearerAuth @Param id path string true "Container ID or Name" example(my-nginx-container) @Success 204 "Container unpaused successfully" @Failure 400 {object} models.ErrorResponse "Invalid container ID" @Failure 401 {object} models.ErrorResponse "Authentication required" @Failure 403 {object} models.ErrorResponse "Permission denied" @Failure 404 {object} models.ErrorResponse "Container not found or not paused" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /containers/{id}/unpause [post]