docker

package
v0.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DockerCmd = &cobra.Command{
	Use:   "docker",
	Short: "Generate a Dockerfile for the given application",
	Long:  `Generate a Dockerfile for the given application.`,
	Run: func(cmd *cobra.Command, args []string) {
		printer = cprint.NewCPrinter(flags.VerboseFlag)

		config, err := config.RestoreConfig()
		if err != nil {
			printer.Error(cmd, err)
			return
		}

		orgId, err := flags.GetOrganizationID()
		if err != nil {
			printer.Error(cmd, err)
			return
		}

		if config.IsMonorepoProject() {
			printer.Error(cmd, fmt.Errorf("docker generation for monorepos is not supported yet"))
			return
		}

		service := run.NewService()

		targetBranch := "main"
		targetBranch, _ = gitutil.GetCurrentBranch()
		hyphenRun, err := service.CreateDockerFileRun(orgId, *config.AppId, targetBranch)
		if err != nil {
			printer.Error(cmd, err)
			return
		}

		modelThing := GenerateDockerRunModel{
			Run: hyphenRun,
		}

		statusDisplay := tea.NewProgram(modelThing)

		go func() {
			client := httputil.NewHyphenHTTPClient()
			url := fmt.Sprintf("%s/api/websockets/eventStream", apiconf.GetBaseWebsocketUrl())
			conn, err := client.GetWebsocketConnection(url)
			if err != nil {
				printer.Error(cmd, fmt.Errorf("failed to connect to WebSocket: %w", err))
				return
			}
			defer conn.Close()
			conn.WriteJSON(
				map[string]interface{}{
					"eventStreamTopic": "run",
					"organizationId":   orgId,
				},
			)
		messageListener:
			for {
				_, message, err := conn.ReadMessage()
				if err != nil {
					printer.Error(cmd, fmt.Errorf("error reading WebSocket message: %w", err))
					break
				}

				var wsMessage WebSocketMessage
				err = json.Unmarshal(message, &wsMessage)
				if err != nil {
					continue
				}

				var typeCheck map[string]interface{}
				err = json.Unmarshal(wsMessage.Data, &typeCheck)
				if err != nil {
					printer.Error(cmd, fmt.Errorf("error unmarshalling Data for type check: %w", err))
					continue
				}

				var data RunData

				err = json.Unmarshal(wsMessage.Data, &data)
				if err != nil {
					continue
				}

				if data.RunId != hyphenRun.ID {
					continue
				}

				statusDisplay.Send(data)

				if data.Action == "update" && data.Run.Status == "succeeded" {
					var codeChanges run.CodeChangeRunData
					err := json.Unmarshal(data.Run.Data, &codeChanges)
					if err != nil {
						printer.Error(cmd, fmt.Errorf("error unmarshaling to CodeChangeRunData: %w", err))
						break messageListener
					}

					applyDiffs(codeChanges.Changes)
					statusDisplay.Send(tea.KeyMsg{Type: tea.KeyEsc})
					break messageListener
				}

			}
		}()
		statusDisplay.Run()
	},
}

Functions

This section is empty.

Types

type GenerateDockerRunModel

type GenerateDockerRunModel struct {
	RunID string
	Run   *run.Run
}

func (GenerateDockerRunModel) Init

func (m GenerateDockerRunModel) Init() tea.Cmd

func (GenerateDockerRunModel) Update

func (m GenerateDockerRunModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (GenerateDockerRunModel) View

func (m GenerateDockerRunModel) View() string

type RunData

type RunData struct {
	Action string  `json:"action"`
	RunId  string  `json:"runId"`
	Run    run.Run `json:"run"`
}

type WebSocketMessage

type WebSocketMessage struct {
	EventStreamTopic string          `json:"eventStreamTopic"`
	OrganizationId   string          `json:"organizationId"`
	Data             json.RawMessage `json:"data"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL