Skip to content

Commit

Permalink
fix: don't hardcode fly.toml in the warning message
Browse files Browse the repository at this point in the history
Fixes #4136.
  • Loading branch information
kzys committed Jan 7, 2025
1 parent 1d86052 commit 7eac344
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions internal/command/deploy/deploy_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func multipleDockerfile(ctx context.Context, appConfig *appconfig.Config) error
}

if found != config {
return fmt.Errorf("Ignoring %s, and using %s (from fly.toml).", found, config)
return fmt.Errorf("ignoring %s, and using %s (from %s)", found, config, appConfig.ConfigFilePath())
}
return nil
}
Expand Down Expand Up @@ -78,7 +78,7 @@ func determineImage(ctx context.Context, appConfig *appconfig.Config, useWG, rec

if err := multipleDockerfile(ctx, appConfig); err != nil {
span.AddEvent("found multiple dockerfiles")
terminal.Warnf("%s\n", err.Error())
terminal.Warnf("%s", err.Error())
}

resolver := imgsrc.NewResolver(daemonType, client, appConfig.AppName, io, useWG, recreateBuilder)
Expand Down
33 changes: 19 additions & 14 deletions internal/command/deploy/deploy_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,38 @@ package deploy

import (
"context"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/superfly/flyctl/internal/appconfig"
"github.com/superfly/flyctl/internal/state"
"os"
"path/filepath"
"testing"
)

func TestMultipleDockerfile(t *testing.T) {
dir := t.TempDir()

f, err := os.Create(filepath.Join(dir, "Dockerfile"))
dockerfile, err := os.Create(filepath.Join(dir, "Dockerfile"))
require.NoError(t, err)
defer dockerfile.Close() // skipcq: GO-S2307

flyToml, err := os.Create(filepath.Join(dir, "fly.production.toml"))
require.NoError(t, err)
defer f.Close() // skipcq: GO-S2307
defer flyToml.Close() // skipcq: GO-S2307

cfg, err := appconfig.LoadConfig(flyToml.Name())
require.NoError(t, err)
cfg.Build = &appconfig.Build{
Dockerfile: "Dockerfile.from-fly-toml",
}

ctx := state.WithWorkingDirectory(context.Background(), dir)
err = multipleDockerfile(ctx, &appconfig.Config{})

assert.NoError(t, err)

err = multipleDockerfile(
ctx,
&appconfig.Config{
Build: &appconfig.Build{
Dockerfile: "Dockerfile.from-fly-toml",
},
},
)
assert.Error(t, err)
err = multipleDockerfile(ctx, cfg)
assert.ErrorContains(t, err, "fly.production.toml")
}

0 comments on commit 7eac344

Please sign in to comment.