Skip to content

Commit 2ac95d2

Browse files
authored
deprecate devbox build + hide devbox plan (#336)
## Summary Title says it. ## How was it tested? - compile - try ./devbox build - try ./devbox plan
1 parent a1af823 commit 2ac95d2

File tree

5 files changed

+11
-175
lines changed

5 files changed

+11
-175
lines changed

boxcli/build.go

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
package boxcli
55

66
import (
7-
"os"
8-
9-
"github.com/pkg/errors"
107
"github.com/spf13/cobra"
11-
"go.jetpack.io/devbox"
128
"go.jetpack.io/devbox/docker"
139
)
1410

@@ -21,12 +17,13 @@ func BuildCmd() *cobra.Command {
2117
flags := buildCmdFlags{}
2218

2319
command := &cobra.Command{
24-
Use: "build",
25-
Short: "Build an OCI image that can run as a container",
26-
Long: "Builds your current source directory and devbox configuration as a Docker container. Devbox will create a plan for your container based on your source code, and then apply the packages and stage overrides in your devbox.json. \n To learn more about how to configure your builds, see the [configuration reference](/docs/configuration_reference)",
27-
Args: cobra.MaximumNArgs(1),
20+
Use: "build",
21+
Deprecated: "Please follow devbox documentation on how to build a container image around your devbox project.",
22+
Short: "(deprecated) Build an OCI image that can run as a container",
23+
Long: "(deprecated) Builds your current source directory and devbox configuration as a Docker container. Devbox will create a plan for your container based on your source code, and then apply the packages and stage overrides in your devbox.json. \n To learn more about how to configure your builds, see the [configuration reference](/docs/configuration_reference)",
24+
Args: cobra.MaximumNArgs(1),
2825
RunE: func(cmd *cobra.Command, args []string) error {
29-
return buildCmdFunc(cmd, args, flags)
26+
return nil
3027
},
3128
}
3229

@@ -42,18 +39,3 @@ func BuildCmd() *cobra.Command {
4239

4340
return command
4441
}
45-
46-
func buildCmdFunc(_ *cobra.Command, args []string, flags buildCmdFlags) error {
47-
path, err := configPathFromUser(args, &flags.config)
48-
if err != nil {
49-
return err
50-
}
51-
52-
// Check the directory exists.
53-
box, err := devbox.Open(path, os.Stdout)
54-
if err != nil {
55-
return errors.WithStack(err)
56-
}
57-
58-
return box.Build(&flags.docker)
59-
}

boxcli/plan.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ func PlanCmd() *cobra.Command {
2020
flags := planCmdFlags{}
2121

2222
command := &cobra.Command{
23-
Use: "plan",
24-
Short: "Preview the plan used to build your environment",
25-
Args: cobra.MaximumNArgs(1),
23+
Use: "plan",
24+
Hidden: true,
25+
Short: "Preview the plan used to build your environment",
26+
Args: cobra.MaximumNArgs(1),
2627
RunE: func(cmd *cobra.Command, args []string) error {
2728
return runPlanCmd(cmd, args, flags)
2829
},
@@ -52,14 +53,5 @@ func runPlanCmd(_ *cobra.Command, args []string, flags planCmdFlags) error {
5253
return err
5354
}
5455

55-
err = enc.Encode(shellPlan)
56-
if err != nil {
57-
return errors.WithStack(err)
58-
}
59-
60-
buildPlan, err := box.BuildPlan()
61-
if err != nil {
62-
return errors.WithStack(err)
63-
}
64-
return errors.WithStack(enc.Encode(buildPlan))
56+
return errors.WithStack(enc.Encode(shellPlan))
6557
}

devbox.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"go.jetpack.io/devbox/boxcli/featureflag"
2020
"go.jetpack.io/devbox/cuecfg"
2121
"go.jetpack.io/devbox/debug"
22-
"go.jetpack.io/devbox/docker"
2322
"go.jetpack.io/devbox/nix"
2423
"go.jetpack.io/devbox/pkgcfg"
2524
"go.jetpack.io/devbox/planner"
@@ -163,21 +162,6 @@ func (d *Devbox) Remove(pkgs ...string) error {
163162
return d.printPackageUpdateMessage(uninstall, uninstalledPackages)
164163
}
165164

166-
// Build creates a Docker image containing a shell with the devbox environment.
167-
func (d *Devbox) Build(flags *docker.BuildFlags) error {
168-
defaultFlags := &docker.BuildFlags{
169-
Name: flags.Name,
170-
DockerfilePath: filepath.Join(d.configDir, ".devbox/gen", "Dockerfile"),
171-
}
172-
opts := append([]docker.BuildOptions{docker.WithFlags(defaultFlags)}, docker.WithFlags(flags))
173-
174-
err := d.generateBuildFiles()
175-
if err != nil {
176-
return errors.WithStack(err)
177-
}
178-
return docker.Build(d.configDir, opts...)
179-
}
180-
181165
// ShellPlan creates a plan of the actions that devbox will take to generate its
182166
// shell environment.
183167
func (d *Devbox) ShellPlan() (*plansdk.ShellPlan, error) {
@@ -221,9 +205,6 @@ func (d *Devbox) Generate() error {
221205
if err := d.generateShellFiles(); err != nil {
222206
return errors.WithStack(err)
223207
}
224-
if err := d.generateBuildFiles(); err != nil {
225-
return errors.WithStack(err)
226-
}
227208
return nil
228209
}
229210

@@ -406,18 +387,6 @@ func (d *Devbox) generateShellFiles() error {
406387
return generateForShell(d.configDir, plan)
407388
}
408389

409-
func (d *Devbox) generateBuildFiles() error {
410-
// BuildPlan() will return error if plan is invalid.
411-
buildPlan, err := d.BuildPlan()
412-
if err != nil {
413-
return errors.WithStack(err)
414-
}
415-
if buildPlan.Warning() != nil {
416-
fmt.Printf("[WARNING]: %s\n", buildPlan.Warning().Error())
417-
}
418-
return generateForBuild(d.configDir, buildPlan)
419-
}
420-
421390
func (d *Devbox) profileDir() (string, error) {
422391
absPath := filepath.Join(d.configDir, nix.ProfilePath)
423392
if err := os.MkdirAll(filepath.Dir(absPath), 0755); err != nil {

devbox_test.go

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ func TestDevbox(t *testing.T) {
2626

2727
for _, testPath := range testPaths {
2828
testShell(t, testPath)
29-
testBuild(t, testPath)
3029
}
3130
}
3231

@@ -72,106 +71,14 @@ func testShell(t *testing.T, testPath string) {
7271
})
7372
}
7473

75-
func testBuild(t *testing.T, testPath string) {
76-
77-
currentDir, err := os.Getwd()
78-
require.New(t).NoError(err)
79-
80-
baseDir := filepath.Dir(testPath)
81-
testName := fmt.Sprintf("%s_build_plan", baseDir)
82-
t.Run(testName, func(t *testing.T) {
83-
assert := assert.New(t)
84-
buildPlanFile := filepath.Join(baseDir, "build_plan.json")
85-
hasBuildPlanFile := fileExists(buildPlanFile)
86-
87-
box, err := Open(baseDir, os.Stdout)
88-
assert.NoErrorf(err, "%s should be a valid devbox project", baseDir)
89-
90-
// Just for tests, we make configDir be a relative path so that the paths in plan.json
91-
// of various test cases have relative paths. Absolute paths are a no-go because they'd
92-
// be of the form `/Users/savil/...`, which are not generalized and cannot be checked in.
93-
box.configDir, err = filepath.Rel(currentDir, box.configDir)
94-
assert.NoErrorf(err, "expect to construct relative path from %s relative to base %s", box.configDir, currentDir)
95-
96-
buildPlan, err := box.BuildPlan()
97-
buildErrorExpectedFile := filepath.Join(baseDir, "build_error_expected")
98-
hasBuildErrorExpectedFile := fileExists(buildErrorExpectedFile)
99-
if hasBuildErrorExpectedFile {
100-
assert.NotNil(err)
101-
// Since build error is expected, skip the rest of the test
102-
return
103-
}
104-
assert.NoError(err, "devbox plan should not fail")
105-
106-
err = box.generateBuildFiles()
107-
assert.NoError(err, "devbox generate should not fail")
108-
109-
if !hasBuildPlanFile {
110-
assert.NotEmpty(buildPlan.DevPackages, "the plan should have dev packages")
111-
return
112-
}
113-
114-
data, err := os.ReadFile(buildPlanFile)
115-
assert.NoError(err, "plan.json should be readable")
116-
117-
expected := &plansdk.BuildPlan{}
118-
err = json.Unmarshal(data, &expected)
119-
assert.NoError(err, "plan.json should parse correctly")
120-
assertBuildPlansMatch(t, expected, buildPlan)
121-
})
122-
}
123-
12474
func assertShellPlansMatch(t *testing.T, expected *plansdk.ShellPlan, actual *plansdk.ShellPlan) {
12575
assert := assert.New(t)
12676

12777
assert.ElementsMatch(expected.DevPackages, actual.DevPackages, "DevPackages should match")
12878
assert.ElementsMatch(expected.NixOverlays, actual.NixOverlays, "NixOverlays should match")
12979
}
13080

131-
func assertBuildPlansMatch(t *testing.T, expected *plansdk.BuildPlan, actual *plansdk.BuildPlan) {
132-
assert := assert.New(t)
133-
134-
assert.ElementsMatch(expected.DevPackages, actual.DevPackages, "DevPackages should match")
135-
assert.ElementsMatch(expected.RuntimePackages, actual.RuntimePackages, "RuntimePackages should match")
136-
assert.Equal(expected.InstallStage.GetCommand(), actual.InstallStage.GetCommand(), "Install stage should match")
137-
assert.Equal(expected.BuildStage.GetCommand(), actual.BuildStage.GetCommand(), "Build stage should match")
138-
assert.Equal(expected.StartStage.GetCommand(), actual.StartStage.GetCommand(), "Start stage should match")
139-
// Check that input files are the same for all stages.
140-
// Depending on where the test command is invoked, the input file paths can be different.
141-
// We will compare the file name only.
142-
assert.ElementsMatch(
143-
expected.InstallStage.GetInputFiles(),
144-
getFileNames(actual.InstallStage.GetInputFiles()),
145-
"InstallStage.InputFiles should match",
146-
)
147-
assert.ElementsMatch(
148-
expected.BuildStage.GetInputFiles(),
149-
getFileNames(actual.BuildStage.GetInputFiles()),
150-
"BuildStage.InputFiles should match",
151-
)
152-
assert.ElementsMatch(
153-
expected.StartStage.GetInputFiles(),
154-
actual.StartStage.GetInputFiles(),
155-
"StartStage.InputFiles should match",
156-
)
157-
158-
assert.ElementsMatch(expected.Definitions, actual.Definitions, "Definitions should match")
159-
}
160-
16181
func fileExists(path string) bool {
16282
_, err := os.Stat(path)
16383
return err == nil
16484
}
165-
166-
func getFileNames(paths []string) []string {
167-
names := []string{}
168-
for _, path := range paths {
169-
if path == "." {
170-
names = append(names, path)
171-
} else {
172-
names = append(names, filepath.Base(path))
173-
}
174-
}
175-
176-
return names
177-
}

generate.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
var tmplFS embed.FS
2424

2525
var shellFiles = []string{"development.nix", "shell.nix"}
26-
var buildFiles = []string{"development.nix", "runtime.nix", "Dockerfile", "Dockerfile.dockerignore"}
2726

2827
func generateForShell(rootPath string, plan *plansdk.ShellPlan) error {
2928
outPath := filepath.Join(rootPath, ".devbox/gen")
@@ -61,19 +60,6 @@ func generateForShell(rootPath string, plan *plansdk.ShellPlan) error {
6160
return nil
6261
}
6362

64-
func generateForBuild(rootPath string, plan *plansdk.BuildPlan) error {
65-
outPath := filepath.Join(rootPath, ".devbox/gen")
66-
67-
for _, file := range buildFiles {
68-
err := writeFromTemplate(outPath, plan, file)
69-
if err != nil {
70-
return errors.WithStack(err)
71-
}
72-
}
73-
74-
return nil
75-
}
76-
7763
func writeFromTemplate(path string, plan interface{}, tmplName string) error {
7864
embeddedPath := fmt.Sprintf("tmpl/%s.tmpl", tmplName)
7965

0 commit comments

Comments
 (0)