Skip to content

Commit

Permalink
dockercompose: move helper functions around
Browse files Browse the repository at this point in the history
  • Loading branch information
nicks committed May 10, 2022
1 parent e5ee33c commit 55b873e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (r *Reconciler) recordSpecAndDisableStatus(
if !apicmp.DeepEqual(result.Spec, spec) {
delete(r.resultsByServiceName, result.Spec.Service)
result.Spec = spec
result.ProjectHash = mustHashProject(spec.Project)
result.ProjectHash = dockercomposeservices.MustHashProject(spec.Project)
r.resultsByServiceName[result.Spec.Service] = result
}

Expand Down
10 changes: 3 additions & 7 deletions internal/engine/runtimelog/docker_compose_log_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ package runtimelog
import (
"bytes"
"context"
"fmt"
"io"
"time"
"unicode"

"github.com/tilt-dev/tilt/internal/dockercompose"
"github.com/tilt-dev/tilt/internal/store"
"github.com/tilt-dev/tilt/internal/store/dockercomposeservices"
"github.com/tilt-dev/tilt/pkg/logger"
"github.com/tilt-dev/tilt/pkg/model"
"github.com/tilt-dev/tilt/pkg/model/logstore"
)

// Collects logs from running docker-compose services.
Expand Down Expand Up @@ -204,7 +203,8 @@ func (w *DockerComposeLogActionWriter) Write(p []byte) (n int, err error) {

newText := bytes.Join(linesToWrite, newlineAsBytes)

w.store.Dispatch(store.NewLogAction(w.manifestName, SpanIDForDCService(w.manifestName), logger.InfoLvl, nil, newText))
w.store.Dispatch(store.NewLogAction(w.manifestName,
dockercomposeservices.SpanIDForDCService(w.manifestName), logger.InfoLvl, nil, newText))
return len(p), nil
}

Expand All @@ -219,10 +219,6 @@ func (w *DockerComposeLogActionWriter) LastLogTime() time.Time {

var _ store.Subscriber = &DockerComposeLogManager{}

func SpanIDForDCService(mn model.ManifestName) logstore.SpanID {
return logstore.SpanID(fmt.Sprintf("dc:%s", mn))
}

// splitDockerComposeLogLineTimestamp attempts to extract a timestamp from a Docker Compose log line.
//
// Tilt invokes `docker-compose logs` with `--timestamps`, which will output timestamps in the RFC3339Nano format
Expand Down
4 changes: 2 additions & 2 deletions internal/store/buildcontrols/reducers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (

"github.com/tilt-dev/tilt/internal/container"
"github.com/tilt-dev/tilt/internal/dockercompose"
"github.com/tilt-dev/tilt/internal/engine/runtimelog"
"github.com/tilt-dev/tilt/internal/k8s"
"github.com/tilt-dev/tilt/internal/store"
"github.com/tilt-dev/tilt/internal/store/dockercomposeservices"
"github.com/tilt-dev/tilt/internal/timecmp"
"github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1"
"github.com/tilt-dev/tilt/pkg/logger"
Expand Down Expand Up @@ -59,7 +59,7 @@ func HandleBuildStarted(ctx context.Context, state *store.EngineState, action Bu
} else if manifest.IsDC() {
// Attach the SpanID and initialize the runtime state if we haven't yet.
state, _ := ms.RuntimeState.(dockercompose.State)
state = state.WithSpanID(runtimelog.SpanIDForDCService(mn))
state = state.WithSpanID(dockercomposeservices.SpanIDForDCService(mn))
ms.RuntimeState = state
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dockercomposeservice
package dockercomposeservices

import (
"crypto"
Expand All @@ -24,7 +24,7 @@ func createDefaultJSONIterator() jsoniter.API {
}

// Compute the hash of a dockercompose project.
func mustHashProject(p v1alpha1.DockerComposeProject) string {
func MustHashProject(p v1alpha1.DockerComposeProject) string {
w := newHashWriter()
err := w.append(p)
if err != nil {
Expand Down
10 changes: 8 additions & 2 deletions internal/store/dockercomposeservices/reducers.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package dockercomposeservices

import (
"fmt"

"github.com/tilt-dev/tilt/internal/container"
"github.com/tilt-dev/tilt/internal/dockercompose"
"github.com/tilt-dev/tilt/internal/engine/runtimelog"
"github.com/tilt-dev/tilt/internal/store"
"github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1"
"github.com/tilt-dev/tilt/pkg/model"
"github.com/tilt-dev/tilt/pkg/model/logstore"
)

func SpanIDForDCService(mn model.ManifestName) logstore.SpanID {
return logstore.SpanID(fmt.Sprintf("dc:%s", mn))
}

func HandleDockerComposeServiceUpsertAction(state *store.EngineState, action DockerComposeServiceUpsertAction) {
obj := action.DockerComposeService
n := obj.Name
Expand All @@ -25,7 +31,7 @@ func HandleDockerComposeServiceUpsertAction(state *store.EngineState, action Doc
dcs = dockercompose.State{}
}

dcs = dcs.WithSpanID(runtimelog.SpanIDForDCService(mn))
dcs = dcs.WithSpanID(SpanIDForDCService(mn))

cid := obj.Status.ContainerID
if cid != "" {
Expand Down

0 comments on commit 55b873e

Please sign in to comment.