detached 3cc9340

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 {
7979 }
8080
8181 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+
8287 return nil
8388 }
@@ -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 nil87 return nil
83 }88 }
M internal/common/payload.go +3 -2
@@ -23,8 +23,9 @@ type DeployResponse struct {
2323 }
2424
2525 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"`
2829 }
2930
3031 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 {
120120 // Update the payload with the image ID
121121 payload.ImageID = imageID
122122
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
124133 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,
127137 })
128138 }
129139
@@ -120,10 +120,20 @@ func PostPush(c echo.Context, a *server.App) error {
120 // Update the payload with the image ID120 // Update the payload with the image ID
121 payload.ImageID = imageID121 payload.ImageID = imageID
122 122
123- // If we arrive here, send back a success response with the target domain123+ // 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) {
162162 htmxGroup.GET("/create-container/:ID", func(c echo.Context) error {
163163 return handler.CreateContainerGET(c, a)
164164 })
165+ // Display create-container component
166+ htmxGroup.GET("/create-container/:ShortID", func(c echo.Context) error {
167+ return handler.CreateContainerGET(c, a)
168+ })
165169 // Create container
166170 htmxGroup.POST("/create-container/:ID", func(c echo.Context) error {
167171 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 container169 // 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)

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close