Add create container URL to push response
- Update PushResponse struct to include CreateContainerURL - Generate and include create container URL in CLI push endpoint - Add new HTMX route for create-container with short ID - Display create container URL in CLI after successful push - Implement short ID mapping for image IDs
- commit
- 3cc9340a9643478107255ab57e38bf44cce80a56
- author
- Brice · · 2024-09-16 14:17 UTC
- parent
- e9b201c
- signature
- unsigned
4 files · +25 -5
M internal/cli/cmd/push.go +5 -0
| @@ -79,5 +79,10 @@ func pushImage(a *cli.App, imageName string) error { | |||
| 79 | 79 | } | |
| 80 | 80 | ||
| 81 | 81 | log.Info("Image pushed successfully", "image", imageName) | |
| 82 | + | ||
| 83 | + | if pushResponse.CreateContainerURL != "" { | |
| 84 | + | log.Info("You can create a container for this image at:", "url", pushResponse.CreateContainerURL) | |
| 85 | + | } | |
| 86 | + | ||
| 82 | 87 | return nil | |
| 83 | 88 | } | |
| @@ -79,5 +79,10 @@ func pushImage(a *cli.App, imageName string) error { | |||||
| 79 | } | 79 | } | ||
| 80 | 80 | ||||
| 81 | log.Info("Image pushed successfully", "image", imageName) | 81 | log.Info("Image pushed successfully", "image", imageName) | ||
| 82 | + | ||||
| 83 | + | if pushResponse.CreateContainerURL != "" { | |||
| 84 | + | log.Info("You can create a container for this image at:", "url", pushResponse.CreateContainerURL) | |||
| 85 | + | } | |||
| 86 | + | ||||
| 82 | return nil | 87 | return nil | ||
| 83 | } | 88 | } | ||
M internal/common/payload.go +3 -2
| @@ -23,8 +23,9 @@ type DeployResponse struct { | |||
| 23 | 23 | } | |
| 24 | 24 | ||
| 25 | 25 | type PushResponse struct { | |
| 26 | - | Success bool `json:"success"` | |
| 27 | - | Message string `json:"message"` | |
| 26 | + | Success bool `json:"success"` | |
| 27 | + | Message string `json:"message"` | |
| 28 | + | CreateContainerURL string `json:"create_container_url,omitempty"` | |
| 28 | 29 | } | |
| 29 | 30 | ||
| 30 | 31 | type DeploymentError struct { | |
| @@ -23,8 +23,9 @@ type DeployResponse struct { | |||||
| 23 | } | 23 | } | ||
| 24 | 24 | ||||
| 25 | type PushResponse struct { | 25 | type PushResponse struct { | ||
| 26 | - | Success bool `json:"success"` | 26 | + | Success bool `json:"success"` |
| 27 | - | Message string `json:"message"` | 27 | + | Message string `json:"message"` |
| 28 | + | CreateContainerURL string `json:"create_container_url,omitempty"` | |||
| 28 | } | 29 | } | ||
| 29 | 30 | ||||
| 30 | type DeploymentError struct { | 31 | type DeploymentError struct { | ||
M internal/httpserve/handler/cli-endpoints.go +13 -3
| @@ -120,10 +120,20 @@ func PostPush(c echo.Context, a *server.App) error { | |||
| 120 | 120 | // Update the payload with the image ID | |
| 121 | 121 | payload.ImageID = imageID | |
| 122 | 122 | ||
| 123 | - | // If we arrive here, send back a success response with the target domain | |
| 123 | + | // Generate shortened ID (first 12 characters) | |
| 124 | + | shortID := imageID[:12] | |
| 125 | + | ||
| 126 | + | // Store the mapping | |
| 127 | + | safelyInteractWithIDMap(Update, shortID, imageID) | |
| 128 | + | ||
| 129 | + | // Generate the URL for create container view | |
| 130 | + | createContainerURL := fmt.Sprintf("%s/htmx/create-container/%s", a.Config.Server.URL, shortID) | |
| 131 | + | ||
| 132 | + | // Return success response with the URL | |
| 124 | 133 | return sendJSONResponse(c, http.StatusOK, common.PushResponse{ | |
| 125 | - | Success: true, | |
| 126 | - | Message: "Deployment successful", | |
| 134 | + | Success: true, | |
| 135 | + | Message: "Image pushed successfully", | |
| 136 | + | CreateContainerURL: createContainerURL, | |
| 127 | 137 | }) | |
| 128 | 138 | } | |
| 129 | 139 | ||
| @@ -120,10 +120,20 @@ func PostPush(c echo.Context, a *server.App) error { | |||||
| 120 | // Update the payload with the image ID | 120 | // Update the payload with the image ID | ||
| 121 | payload.ImageID = imageID | 121 | payload.ImageID = imageID | ||
| 122 | 122 | ||||
| 123 | - | // If we arrive here, send back a success response with the target domain | 123 | + | // Generate shortened ID (first 12 characters) |
| 124 | + | shortID := imageID[:12] | |||
| 125 | + | ||||
| 126 | + | // Store the mapping | |||
| 127 | + | safelyInteractWithIDMap(Update, shortID, imageID) | |||
| 128 | + | ||||
| 129 | + | // Generate the URL for create container view | |||
| 130 | + | createContainerURL := fmt.Sprintf("%s/htmx/create-container/%s", a.Config.Server.URL, shortID) | |||
| 131 | + | ||||
| 132 | + | // Return success response with the URL | |||
| 124 | return sendJSONResponse(c, http.StatusOK, common.PushResponse{ | 133 | return sendJSONResponse(c, http.StatusOK, common.PushResponse{ | ||
| 125 | - | Success: true, | 134 | + | Success: true, |
| 126 | - | Message: "Deployment successful", | 135 | + | Message: "Image pushed successfully", |
| 136 | + | CreateContainerURL: createContainerURL, | |||
| 127 | }) | 137 | }) | ||
| 128 | } | 138 | } | ||
| 129 | 139 | ||||
M internal/httpserve/router.go +4 -0
| @@ -162,6 +162,10 @@ func bindHTMXEndpoints(e *echo.Echo, a *server.App) { | |||
| 162 | 162 | htmxGroup.GET("/create-container/:ID", func(c echo.Context) error { | |
| 163 | 163 | return handler.CreateContainerGET(c, a) | |
| 164 | 164 | }) | |
| 165 | + | // Display create-container component | |
| 166 | + | htmxGroup.GET("/create-container/:ShortID", func(c echo.Context) error { | |
| 167 | + | return handler.CreateContainerGET(c, a) | |
| 168 | + | }) | |
| 165 | 169 | // Create container | |
| 166 | 170 | htmxGroup.POST("/create-container/:ID", func(c echo.Context) error { | |
| 167 | 171 | return handler.CreateContainerPOST(c, a) | |
| @@ -162,6 +162,10 @@ func bindHTMXEndpoints(e *echo.Echo, a *server.App) { | |||||
| 162 | htmxGroup.GET("/create-container/:ID", func(c echo.Context) error { | 162 | htmxGroup.GET("/create-container/:ID", func(c echo.Context) error { | ||
| 163 | return handler.CreateContainerGET(c, a) | 163 | return handler.CreateContainerGET(c, a) | ||
| 164 | }) | 164 | }) | ||
| 165 | + | // Display create-container component | |||
| 166 | + | htmxGroup.GET("/create-container/:ShortID", func(c echo.Context) error { | |||
| 167 | + | return handler.CreateContainerGET(c, a) | |||
| 168 | + | }) | |||
| 165 | // Create container | 169 | // Create container | ||
| 166 | htmxGroup.POST("/create-container/:ID", func(c echo.Context) error { | 170 | htmxGroup.POST("/create-container/:ID", func(c echo.Context) error { | ||
| 167 | return handler.CreateContainerPOST(c, a) | 171 | return handler.CreateContainerPOST(c, a) | ||