Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ linters:
- exhaustruct
- fatcontext
- forbidigo
- forcetypeassert
- funcorder
- funlen
- gochecknoglobals
Expand Down
12 changes: 10 additions & 2 deletions ast/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,20 @@ func (l *lexer) debugToken(token antlr.Token, modeBefore int) {
}

func (l *lexer) pos() (line, column, index int) {
atn := l.Interpreter.(*antlr.LexerATNSimulator)
atn, ok := l.Interpreter.(*antlr.LexerATNSimulator)
if !ok {
return 0, 0, 0
}

return atn.Line, atn.CharPositionInLine, l.GetInputStream().Index()
}

func (l *lexer) seek(line, column, index int) {
atn := l.Interpreter.(*antlr.LexerATNSimulator)
atn, ok := l.Interpreter.(*antlr.LexerATNSimulator)
if !ok {
return
}

atn.Line = line
atn.CharPositionInLine = column

Expand Down
10 changes: 8 additions & 2 deletions buildcontext/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ func (gr *gitResolver) resolveEarthProject(
return nil, err
}

localBuildFile := localBuildFileValue.(*buildFile)
localBuildFile, ok := localBuildFileValue.(*buildFile)
if !ok {
return nil, fmt.Errorf("want *buildFile, got %T", localBuildFileValue)
}

// TODO: Apply excludes / .earthignore.
return &Data{
Expand Down Expand Up @@ -569,7 +572,10 @@ func (gr *gitResolver) resolveGitProject(
return nil, "", "", err
}

rgp = rgpValue.(*resolvedGitProject)
rgp, ok := rgpValue.(*resolvedGitProject)
if !ok {
return nil, "", "", fmt.Errorf("want *resolvedGitProject, got %T", rgpValue)
}

return rgp, gitURL, subDir, nil
}
Expand Down
12 changes: 10 additions & 2 deletions buildcontext/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package buildcontext

import (
"context"
"fmt"
"path/filepath"
"strings"

Expand Down Expand Up @@ -62,7 +63,10 @@ func (lr *localResolver) resolveLocal(
return nil, err
}

metadata := metadataValue.(*gitutil.GitMetadata)
metadata, ok := metadataValue.(*gitutil.GitMetadata)
if !ok {
return nil, fmt.Errorf("want *gitutil.GitMetadata, got %T", metadataValue)
}

localPath := filepath.FromSlash(ref.GetLocalPath())
key := localPath
Expand Down Expand Up @@ -100,7 +104,11 @@ func (lr *localResolver) resolveLocal(
return nil, err
}

bf := buildFileValue.(*buildFile)
bf, ok := buildFileValue.(*buildFile)
if !ok {
return nil, fmt.Errorf("want *buildFile, got %T", buildFileValue)
}

data := &Data{
BuildFilePath: bf.path,
GitMetadata: metadata,
Expand Down
18 changes: 15 additions & 3 deletions buildcontext/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package buildcontext

import (
"context"
"fmt"
"path/filepath"
"strings"

Expand Down Expand Up @@ -111,7 +112,10 @@ func (r *Resolver) ExpandWildcard(
return nil, errors.Wrap(err, "failed to join references")
}

target = ref.(domain.Target)
target, ok := ref.(domain.Target)
if !ok {
return nil, fmt.Errorf("want domain.Target, got %T", ref)
}

matches, err := fileutil.GlobDirs(target.GetLocalPath())
if err != nil {
Expand Down Expand Up @@ -185,13 +189,21 @@ func (r *Resolver) parseEarthfile(ctx context.Context, path string) (spec.Earthf
path = filepath.Clean(path)

efValue, err := r.parseCache.Do(ctx, path, func(ctx context.Context, k any) (any, error) {
return ast.Parse(k.(string), true)
filePath, ok := k.(string)
if !ok {
return nil, fmt.Errorf("want string, got %T", k)
}

return ast.Parse(filePath, true)
})
if err != nil {
return spec.Earthfile{}, err
}

ef := efValue.(spec.Earthfile)
ef, ok := efValue.(spec.Earthfile)
if !ok {
return spec.Earthfile{}, errors.Errorf("want spec.Earthfile, got %T", efValue)
}

return ef, nil
}
10 changes: 5 additions & 5 deletions cmd/earthly/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ func (app *EarthlyApp) handleError(ctx context.Context, err error, args []string
}

grpcErr, grpcErrOK := grpcerrors.AsGRPCStatus(err)
hintErr, hintErrOK := getHintErr(err, grpcErr)
hintErr := getHintErr(err, grpcErr)

var (
paramsErr *params.Error
autoSkipErr *inputgraph.Error
)

switch {
case hintErrOK:
case hintErr != nil:
app.BaseCLI.Logbus().Run().SetGenericFatalError(
time.Now(),
logstream.FailureType_FAILURE_TYPE_OTHER,
Expand Down Expand Up @@ -478,17 +478,17 @@ func errorWithPrefix(err string) string {
return "Error: " + err
}

func getHintErr(err error, grpcError *status.Status) (*hint.Error, bool) {
func getHintErr(err error, grpcError *status.Status) *hint.Error {
res := new(hint.Error)
if errors.As(err, &res) {
return res, true
return res
}

if grpcError != nil {
return hint.FromError(errors.New(grpcError.Message()))
}

return nil, false
return nil
}

func redactSecretsFromArgs(args []string) []string {
Expand Down
22 changes: 16 additions & 6 deletions cmd/earthly/subcmd/build_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,18 +415,22 @@ func (a *Build) ActionBuildImp(cliCtx *cli.Context, flagArgs, nonFlagArgs []stri

cfg := config.LoadDefaultConfigFile(os.Stderr)

var authChildren []authprovider.Child
var attachable session.Attachable

switch a.cli.Flags().ContainerFrontend.Config().Setting {
case containerutil.FrontendPodman, containerutil.FrontendPodmanShell:
authChildren = append(authChildren, authprovider.NewPodman(os.Stderr).(auth.AuthServer))

attachable = authprovider.NewPodman(os.Stderr)
default:
// includes containerutil.FrontendDocker, containerutil.FrontendDockerShell:
authChildren = append(authChildren, dockerauthprovider.NewDockerAuthProvider(cfg, nil).(auth.AuthServer))
attachable = dockerauthprovider.NewDockerAuthProvider(cfg, nil)
}

auth, ok := attachable.(auth.AuthServer)
if !ok {
return fmt.Errorf("want auth.AuthServer, got %T", attachable)
}

authProvider := authprovider.New(a.cli.Console(), authChildren)
authProvider := authprovider.New(a.cli.Console(), []authprovider.Child{auth})
attachables = append(attachables, authProvider)

gitLookup := buildcontext.NewGitLookup(a.cli.Console(), a.cli.Flags().SSHAuthSock)
Expand Down Expand Up @@ -890,7 +894,13 @@ func (a *Build) initAutoSkip(
console.VerboseWarnf("unable to detect all git metadata: %v", err.Error())
}

target = gitutil.ReferenceWithGitMeta(target, meta).(domain.Target)
var ok bool

target, ok = gitutil.ReferenceWithGitMeta(target, meta).(domain.Target)
if !ok {
return nil, false, errors.Errorf("want domain.Target, got %T", target)
}

target.Tag = ""
}

Expand Down
4 changes: 3 additions & 1 deletion conslogging/prefix_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ func (pb *prefixFormatter) Format(prefix string, padding int) (modifiedPrefix st
}

key := pb.getKey(prefix, padding)

if cachedPrefix, ok := pb.cache.Load(key); ok {
return cachedPrefix.(string)
s, _ := cachedPrefix.(string)
return s
}

defer func() {
Expand Down
6 changes: 5 additions & 1 deletion earthfile2llb/cachedmetaresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/containerd/platforms"
"github.com/moby/buildkit/client/llb"
"github.com/opencontainers/go-digest"
"github.com/pkg/errors"
)

var _ llb.ImageMetaResolver = &CachedMetaResolver{}
Expand Down Expand Up @@ -67,7 +68,10 @@ func (cmr *CachedMetaResolver) ResolveImageConfig(
return "", "", nil, err
}

entry := value.(cachedMetaResolverEntry)
entry, ok := value.(cachedMetaResolverEntry)
if !ok {
return "", "", nil, errors.Errorf("want cachedMetaResolverEntry, got %T", value)
}

return entry.ref, entry.dgst, entry.config, nil
}
21 changes: 18 additions & 3 deletions earthfile2llb/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,12 @@ func (c *Converter) FromDockerfile(
return errors.Wrap(err, "join targets")
}

dockerfileMetaTarget = dockerfileMetaTargetRef.(domain.Target)
var ok bool

dockerfileMetaTarget, ok = dockerfileMetaTargetRef.(domain.Target)
if !ok {
return errors.Errorf("want domain.Target, got %T", dockerfileMetaTargetRef)
}

var data *buildcontext.Data

Expand Down Expand Up @@ -473,7 +478,12 @@ func (c *Converter) FromDockerfile(
return errors.Wrap(err, "join targets")
}

dockerfileMetaTarget = dockerfileMetaTargetRef.(domain.Target)
var ok bool

dockerfileMetaTarget, ok = dockerfileMetaTargetRef.(domain.Target)
if !ok {
return errors.Errorf("want domain.Target, got %T", dockerfileMetaTargetRef)
}

var data *buildcontext.Data

Expand Down Expand Up @@ -2284,7 +2294,12 @@ func (c *Converter) absolutizeTarget(
return domain.Target{}, domain.Target{}, false, errors.Wrap(err, "join targets")
}

return targetRef.(domain.Target), relTarget, allowPrivileged, nil
target, ok := targetRef.(domain.Target)
if !ok {
return domain.Target{}, domain.Target{}, false, errors.Errorf("want domain.Target, got %T", targetRef)
}

return target, relTarget, allowPrivileged, nil
}

func (c *Converter) checkAutoSkip(
Expand Down
5 changes: 4 additions & 1 deletion earthfile2llb/earthfile2llb.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@ func Earthfile2LLB(
opt.waitBlock = newWaitBlock()
}

targetWithMetadata := bc.Ref.(domain.Target)
targetWithMetadata, ok := bc.Ref.(domain.Target)
if !ok {
return nil, errors.Errorf("want domain.Target, got %T", bc.Ref)
}

sts, found, err := opt.Visited.
Add(ctx, targetWithMetadata, opt.PlatformResolver, opt.AllowPrivileged, opt.OverridingVars, opt.parentDepSub)
Expand Down
5 changes: 4 additions & 1 deletion earthfile2llb/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2274,7 +2274,10 @@ func (i *Interpreter) handleDo(ctx context.Context, cmd spec.Command) error {
return i.wrapError(err, cmd.SourceLocation, "unable to resolve user command %s", ucName)
}

command := bc.Ref.(domain.Command)
command, ok := bc.Ref.(domain.Command)
if !ok {
return i.errorf(cmd.SourceLocation, "want domain.Command, got %T", bc.Ref)
}

if resolvedAllowPrivilegedSet {
allowPrivileged = allowPrivileged && resolvedAllowPrivileged
Expand Down
5 changes: 4 additions & 1 deletion inputgraph/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ func (l *loader) derefedTarget(targetName string) (domain.Target, error) {
return domain.Target{}, errors.Wrapf(err, "failed to join %s and %s", l.target, target)
}

target = targetRef.(domain.Target)
target, ok := targetRef.(domain.Target)
if !ok {
return domain.Target{}, errors.Errorf("want domain.Target, got %T", targetRef)
}

return target, nil
}
Expand Down
4 changes: 3 additions & 1 deletion logbus/formatter/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ func (f *Formatter) Manifest() *logstream.RunManifest {
f.mu.Lock()
defer f.mu.Unlock()

return proto.Clone(f.manifest).(*logstream.RunManifest)
manifest, _ := proto.Clone(f.manifest).(*logstream.RunManifest)

return manifest
}

func (f *Formatter) processDelta(delta *logstream.Delta) error {
Expand Down
19 changes: 14 additions & 5 deletions regproxy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ func (c *Controller) Start(ctx context.Context) (string, func(), error) {
go p.serve(ctx)

// Find the assigned port.
registryPort := ln.Addr().(*net.TCPAddr).Port
addr = fmt.Sprintf("127.0.0.1:%d", registryPort)
registry, ok := ln.Addr().(*net.TCPAddr)
if !ok {
return "", nil, errors.New("failed to get proxy listener address")
}

addr = fmt.Sprintf("127.0.0.1:%d", registry.Port)

c.cons.VerbosePrintf("Starting registry proxy on %s", addr)

Expand Down Expand Up @@ -100,7 +104,7 @@ func (c *Controller) Start(ctx context.Context) (string, func(), error) {
}
}

port, err := c.startDarwinProxy(ctx, containerName, registryPort)
port, err := c.startDarwinProxy(ctx, containerName, registry.Port)
if err != nil {
stopFn(ctx)
return "", nil, errors.Wrap(err, "failed to start Darwin support container")
Expand Down Expand Up @@ -240,9 +244,14 @@ func acquireFreePort(ctx context.Context) (int, error) {

ln, err := (&net.ListenConfig{}).Listen(ctx, "tcp", addr)
if err != nil {
return 0, errors.Wrap(err, "failed to listen on open port")
return 0, errors.Wrap(err, "listen on open port")
}
defer ln.Close() // Immediately close the listener

return ln.Addr().(*net.TCPAddr).Port, nil
tcpAddr, ok := ln.Addr().(*net.TCPAddr)
if !ok {
return 0, errors.New("get TCP address")
}

return tcpAddr.Port, nil
}
4 changes: 3 additions & 1 deletion slog/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ func GetLogger(ctx context.Context) Logger {
return Logger{}
}

return v.(Logger) // Note that this panics if not a real Logger.
logger, _ := v.(Logger)

return logger
}

// With adds logging metadata to the logger within the context.
Expand Down
Loading
Loading