latest cdbcd03

push.go RawHistoryFolder

1package cmd
2
3import (
4	"fmt"
5	"os"
6
7	"github.com/bnema/gordon/internal/cli"
8	"github.com/bnema/gordon/internal/cli/handler"
9	"github.com/bnema/gordon/internal/common"
10	"github.com/bnema/gordon/pkg/docker"
11	"github.com/spf13/cobra"
12)
13
14// the push command is used to push a container image to gordon's endpoint
15
16// Pseudo code of the steps for the push command
17
18// 1. Extract the container image as .tar and store it in a temporary directory
19
20// 2. Prepare a payload with the .tar as a byte array, the image name and tag (if any)
21
22// 3. append the payload to the request body with the type "push" and the token
23
24// 4. Send the request to the backend
25
26// 5. If the response is 200, print the success message
27
28func NewPushCommand(a *cli.App) *cobra.Command {
29	var port string
30	var targetDomain string
31
32	// handler.FieldCheck(a)
33
34	pushCmd := &cobra.Command{
35		Use:   "push [image:tag]",
36		Short: "Push an image to the server, if no tag is specified, latest is used",
37		Args:  cobra.ExactArgs(1),
38		PreRun: func(cmd *cobra.Command, args []string) {
39			if err := handler.FieldCheck(a); err != nil {
40				fmt.Println("Field check failed:", err)
41				os.Exit(1)
42			}
43		},
44		Run: func(cmd *cobra.Command, args []string) {
45			imageName := args[0]
46			fmt.Println("Exporting image:", imageName)
47			// Export the image using Docker client
48			data, err := docker.ExportImageFromEngine(imageName)
49			if err != nil {
50				fmt.Println("Error exporting image:", err)
51				return
52			}
53			fmt.Println("Image exported successfully")
54			// Create a RequestPayload and populate it
55			reqPayload := common.RequestPayload{ // <- TODO : Load RequestPayLoad from cli.App
56				Type: "push",
57				Payload: common.PushPayload{ // <- Same
58					Ports:        port,
59					TargetDomain: targetDomain,
60					ImageName:    imageName,
61					Data:         data,
62				},
63			}
64			fmt.Println("Sending image to backend")
65			// Send the request to the backend
66			resp, err := handler.SendHTTPRequest(a, &reqPayload, "POST", "/push")
67			if err != nil {
68				fmt.Println("Error sending HTTP request:", err)
69				return
70			}
71
72			fmt.Print(string(resp.Body))
73		},
74	}
75
76	// Add flags
77	pushCmd.Flags().StringVarP(&port, "port", "p", "", "Port mapping for the container")
78	pushCmd.Flags().StringVarP(&targetDomain, "target", "t", "", "Target domain for Traefik")
79
80	return pushCmd
81}

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