Skip to content

Commit

Permalink
Merge branch 'main' of github.com:drew-harris/dockercraft
Browse files Browse the repository at this point in the history
  • Loading branch information
drew-harris committed Aug 11, 2023
2 parents f0d418b + 997abd7 commit 4efc78a
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 19 deletions.
11 changes: 8 additions & 3 deletions engine/dockerengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (e *DockerEngine) EnsureSetup(log types.Logger) error {

if notBuilt {
execId, err := e.client.ContainerExecCreate(context.TODO(), containerId, dtypes.ExecConfig{
Cmd: []string{"./build_all.sh"},
Cmd: []string{"./build.sh"},
AttachStderr: true,
AttachStdout: true,
Tty: true,
Expand Down Expand Up @@ -185,9 +185,14 @@ func (e *DockerEngine) Shutdown() error {
return err
}

func (e *DockerEngine) RebuildAllPlugins(log types.Logger) error {
func (e *DockerEngine) RebuildAllPlugins(log types.Logger, disableCache bool) error {
var arg []string
if disableCache {
arg = append(arg, "nocache")
}
result, err := docker.RunContainerCommand(e.client, e.containerId, log, commands.Command{
Name: "./build_all.sh",
Name: "./build.sh",
Args: arg,
})

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Engine interface {
EnsureSetup(log types.Logger) error
StartServer(log types.Logger) error
// TODO: boolean for cache
RebuildAllPlugins(log types.Logger) error
RebuildAllPlugins(log types.Logger, disableCache bool) error
Shutdown() error
// SendCommandToSpigot(cmd string) error
CanAttach() bool
Expand Down
4 changes: 2 additions & 2 deletions engine/hostengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ func (h *HostEngine) EnsureSetup(log types.Logger) error {
}

// Rebuild all plugins
err = h.RebuildAllPlugins(log)
err = h.RebuildAllPlugins(log, false)
if err != nil {
return err
}

return nil
}

func (h *HostEngine) RebuildAllPlugins(log types.Logger) error {
func (h *HostEngine) RebuildAllPlugins(log types.Logger, disableCache bool) error {
log("Building all plugins...")
err := commands.RunExternalCommand(log, commands.Command{
Name: "mvn",
Expand Down
4 changes: 2 additions & 2 deletions model/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func (m *MainModel) Shutdown() tea.Cmd {
}
}

func (m *MainModel) rebuildAllPlugins() tea.Cmd {
func (m *MainModel) rebuildAllPlugins(disableCache bool) tea.Cmd {
return func() tea.Msg {
err := m.engine.RebuildAllPlugins(m.loggers.build)
err := m.engine.RebuildAllPlugins(m.loggers.build, disableCache)
if err != nil {
return types.ErrorBuilding
}
Expand Down
11 changes: 8 additions & 3 deletions model/keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ type KeyMap struct {
Help key.Binding
Quit key.Binding

Attach key.Binding
ToggleBuildLogs key.Binding
RebuildAll key.Binding
Attach key.Binding
ToggleBuildLogs key.Binding
RebuildAll key.Binding
RebuildAllNoCache key.Binding
}

var DefaultKeyMap = KeyMap{
Expand Down Expand Up @@ -53,4 +54,8 @@ var DefaultKeyMap = KeyMap{
RebuildAll: key.NewBinding(
key.WithKeys("r"),
),

RebuildAllNoCache: key.NewBinding(
key.WithKeys("R"),
),
}
19 changes: 14 additions & 5 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package model
import (
"strings"

"github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
Expand Down Expand Up @@ -41,6 +42,8 @@ type MainModel struct {

engine engine.Engine
config config.Config
keys KeyMap
help help.Model

outputChan chan types.OutputMsg
errorMessages []string
Expand All @@ -64,21 +67,25 @@ func (m MainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch {
case key.Matches(msg, DefaultKeyMap.Quit):
case key.Matches(msg, m.keys.Quit):
m.isShuttingDown = true
return m, m.Shutdown()

case key.Matches(msg, DefaultKeyMap.ToggleBuildLogs):
case key.Matches(msg, m.keys.ToggleBuildLogs):
m.isViewingBuildLogs = !m.isViewingBuildLogs
return m, nil

case key.Matches(msg, DefaultKeyMap.Attach):
case key.Matches(msg, m.keys.Attach):
// Print info in non alt screen
// return m, tea.ExecProcess(exec.Command("docker", "attach", m.ConatainerId), func(err error) tea.Msg { return nil })
case key.Matches(msg, DefaultKeyMap.RebuildAll):
case key.Matches(msg, m.keys.RebuildAll):
// Print info in non alt screen
m.isBuilding = true
return m, tea.Sequence(m.rebuildAllPlugins(), func() tea.Msg { return types.DoneBuilding })
return m, tea.Sequence(m.rebuildAllPlugins(false), func() tea.Msg { return types.DoneBuilding })
case key.Matches(msg, m.keys.RebuildAllNoCache):
// Print info in non alt screen
m.isBuilding = true
return m, tea.Sequence(m.rebuildAllPlugins(true), func() tea.Msg { return types.DoneBuilding })
}

case tea.WindowSizeMsg: // RESIZE
Expand Down Expand Up @@ -149,6 +156,8 @@ func InitialModel(engine engine.Engine, config config.Config) MainModel {
isLoading: true,
engine: engine,
outputChan: outputChan,
keys: DefaultKeyMap,
help: help.New(),
config: config,
loadingModel: LoadingModel{
spinner: s,
Expand Down
6 changes: 3 additions & 3 deletions model/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ func (m MainModel) View() string {
statusStyle := lipgloss.NewStyle().Width(m.width).Background(lipgloss.Color("#555"))
var statusBar string
if m.isBuilding {
statusBar = statusStyle.Copy().Background(lipgloss.Color("#ab009d")).Render(m.loadingModel.spinner.View() + " BUILDING... ")
statusBar = statusStyle.Copy().Background(lipgloss.Color("#ab009d")).Render(" " + m.loadingModel.spinner.View() + " BUILDING... ")
} else {
statusBar = statusStyle.Render("IDLE")
statusBar = statusStyle.Render(" IDLE")
}

leftMenuContainer := lipgloss.NewStyle().Padding(1).BorderStyle(lipgloss.NormalBorder()).BorderForeground(lipgloss.Color("#fff")).Height(9)
leftMenuContainer := lipgloss.NewStyle().Padding(1).BorderStyle(lipgloss.NormalBorder()).BorderForeground(lipgloss.Color("#fff")).Height(m.height - 3)
menu := leftMenuContainer.Render("Shulker Menu\n* Rebuild\n* Restart")

logContainer := lipgloss.NewStyle().Padding(2).Width(m.width - lipgloss.Width(menu) - 2).AlignVertical(lipgloss.Top)
Expand Down

0 comments on commit 4efc78a

Please sign in to comment.