@@ -35,7 +35,7 @@ import (
35
35
"github.com/GoogleContainerTools/kaniko/pkg/util"
36
36
"github.com/coder/envbuilder/devcontainer"
37
37
"github.com/coder/envbuilder/internal/ebutil"
38
- "github.com/coder/envbuilder/internal/magicdir "
38
+ "github.com/coder/envbuilder/internal/workingdir "
39
39
"github.com/coder/envbuilder/log"
40
40
"github.com/containerd/platforms"
41
41
"github.com/distribution/distribution/v3/configuration"
@@ -120,7 +120,7 @@ func Run(ctx context.Context, opts options.Options, preExec ...func()) error {
120
120
func run (ctx context.Context , opts options.Options , execArgs * execArgsInfo ) error {
121
121
defer options .UnsetEnv ()
122
122
123
- magicDir := magicdir .At (opts .MagicDirBase )
123
+ workingDir := workingdir .At (opts .MagicDirBase )
124
124
125
125
stageNumber := 0
126
126
startStage := func (format string , args ... any ) func (format string , args ... any ) {
@@ -154,7 +154,7 @@ func run(ctx context.Context, opts options.Options, execArgs *execArgsInfo) erro
154
154
155
155
opts .Logger (log .LevelInfo , "%s %s - Build development environments from repositories in a container" , newColor (color .Bold ).Sprintf ("envbuilder" ), buildinfo .Version ())
156
156
157
- cleanupDockerConfigJSON , err := initDockerConfigJSON (opts .Logger , magicDir , opts .DockerConfigBase64 )
157
+ cleanupDockerConfigJSON , err := initDockerConfigJSON (opts .Logger , workingDir , opts .DockerConfigBase64 )
158
158
if err != nil {
159
159
return err
160
160
}
@@ -168,8 +168,8 @@ func run(ctx context.Context, opts options.Options, execArgs *execArgsInfo) erro
168
168
ContainerEnv : make (map [string ]string ),
169
169
RemoteEnv : make (map [string ]string ),
170
170
}
171
- if fileExists (opts .Filesystem , magicDir .Image ()) {
172
- if err = parseMagicImageFile (opts .Filesystem , magicDir .Image (), & runtimeData ); err != nil {
171
+ if fileExists (opts .Filesystem , workingDir .Image ()) {
172
+ if err = parseMagicImageFile (opts .Filesystem , workingDir .Image (), & runtimeData ); err != nil {
173
173
return fmt .Errorf ("parse magic image file: %w" , err )
174
174
}
175
175
runtimeData .Image = true
@@ -186,7 +186,7 @@ func run(ctx context.Context, opts options.Options, execArgs *execArgsInfo) erro
186
186
opts .ExportEnvFile = ""
187
187
}
188
188
}
189
- runtimeData .Built = fileExists (opts .Filesystem , magicDir .Built ())
189
+ runtimeData .Built = fileExists (opts .Filesystem , workingDir .Built ())
190
190
191
191
buildTimeWorkspaceFolder := opts .WorkspaceFolder
192
192
var fallbackErr error
@@ -233,7 +233,7 @@ func run(ctx context.Context, opts options.Options, execArgs *execArgsInfo) erro
233
233
if err != nil {
234
234
return fmt .Errorf ("git clone options: %w" , err )
235
235
}
236
- cloneOpts .Path = magicDir .Join ("repo" )
236
+ cloneOpts .Path = workingDir .Join ("repo" )
237
237
238
238
endStage := startStage ("📦 Remote repo build mode enabled, cloning %s to %s for build context..." ,
239
239
newColor (color .FgCyan ).Sprintf (opts .GitURL ),
@@ -259,7 +259,7 @@ func run(ctx context.Context, opts options.Options, execArgs *execArgsInfo) erro
259
259
260
260
if ! runtimeData .Image {
261
261
defaultBuildParams := func () (* devcontainer.Compiled , error ) {
262
- dockerfile := magicDir .Join ("Dockerfile" )
262
+ dockerfile := workingDir .Join ("Dockerfile" )
263
263
file , err := opts .Filesystem .OpenFile (dockerfile , os .O_CREATE | os .O_WRONLY , 0o644 )
264
264
if err != nil {
265
265
return nil , err
@@ -281,7 +281,7 @@ func run(ctx context.Context, opts options.Options, execArgs *execArgsInfo) erro
281
281
return & devcontainer.Compiled {
282
282
DockerfilePath : dockerfile ,
283
283
DockerfileContent : content ,
284
- BuildContext : magicDir .Path (),
284
+ BuildContext : workingDir .Path (),
285
285
}, nil
286
286
}
287
287
@@ -318,7 +318,7 @@ func run(ctx context.Context, opts options.Options, execArgs *execArgsInfo) erro
318
318
opts .Logger (log .LevelInfo , "No Dockerfile or image specified; falling back to the default image..." )
319
319
fallbackDockerfile = defaultParams .DockerfilePath
320
320
}
321
- buildParams , err = devContainer .Compile (opts .Filesystem , devcontainerDir , magicDir .Path (), fallbackDockerfile , opts .WorkspaceFolder , false , os .LookupEnv )
321
+ buildParams , err = devContainer .Compile (opts .Filesystem , devcontainerDir , workingDir .Path (), fallbackDockerfile , opts .WorkspaceFolder , false , os .LookupEnv )
322
322
if err != nil {
323
323
return fmt .Errorf ("compile devcontainer.json: %w" , err )
324
324
}
@@ -393,7 +393,7 @@ func run(ctx context.Context, opts options.Options, execArgs *execArgsInfo) erro
393
393
// So we add them to the default ignore list. See:
394
394
// https://github.com/GoogleContainerTools/kaniko/blob/63be4990ca5a60bdf06ddc4d10aa4eca0c0bc714/cmd/executor/cmd/root.go#L136
395
395
ignorePaths := append ([]string {
396
- magicDir .Path (),
396
+ workingDir .Path (),
397
397
opts .WorkspaceFolder ,
398
398
// See: https://github.com/coder/envbuilder/issues/37
399
399
"/etc/resolv.conf" ,
@@ -421,18 +421,18 @@ func run(ctx context.Context, opts options.Options, execArgs *execArgsInfo) erro
421
421
if err := util .AddAllowedPathToDefaultIgnoreList (opts .BinaryPath ); err != nil {
422
422
return fmt .Errorf ("add envbuilder binary to ignore list: %w" , err )
423
423
}
424
- if err := util .AddAllowedPathToDefaultIgnoreList (magicDir .Image ()); err != nil {
424
+ if err := util .AddAllowedPathToDefaultIgnoreList (workingDir .Image ()); err != nil {
425
425
return fmt .Errorf ("add magic image file to ignore list: %w" , err )
426
426
}
427
- if err := util .AddAllowedPathToDefaultIgnoreList (magicDir .Features ()); err != nil {
427
+ if err := util .AddAllowedPathToDefaultIgnoreList (workingDir .Features ()); err != nil {
428
428
return fmt .Errorf ("add features to ignore list: %w" , err )
429
429
}
430
- magicTempDir := magicdir .At (buildParams .BuildContext , magicdir .TempDir )
430
+ magicTempDir := workingdir .At (buildParams .BuildContext , workingdir .TempDir )
431
431
if err := opts .Filesystem .MkdirAll (magicTempDir .Path (), 0o755 ); err != nil {
432
432
return fmt .Errorf ("create magic temp dir in build context: %w" , err )
433
433
}
434
434
// Add the magic directives that embed the binary into the built image.
435
- buildParams .DockerfileContent += magicdir .Directives
435
+ buildParams .DockerfileContent += workingdir .Directives
436
436
437
437
envbuilderBinDest := filepath .Join (magicTempDir .Path (), "envbuilder" )
438
438
magicImageDest := magicTempDir .Image ()
@@ -467,7 +467,7 @@ func run(ctx context.Context, opts options.Options, execArgs *execArgsInfo) erro
467
467
}
468
468
469
469
// temp move of all ro mounts
470
- tempRemountDest := magicDir .Join ("mnt" )
470
+ tempRemountDest := workingDir .Join ("mnt" )
471
471
// ignorePrefixes is a superset of ignorePaths that we pass to kaniko's
472
472
// IgnoreList.
473
473
ignorePrefixes := append ([]string {"/dev" , "/proc" , "/sys" }, ignorePaths ... )
@@ -845,7 +845,7 @@ func run(ctx context.Context, opts options.Options, execArgs *execArgsInfo) erro
845
845
// Create the magic file to indicate that this build
846
846
// has already been ran before!
847
847
if ! runtimeData .Built {
848
- file , err := opts .Filesystem .Create (magicDir .Built ())
848
+ file , err := opts .Filesystem .Create (workingDir .Built ())
849
849
if err != nil {
850
850
return fmt .Errorf ("create magic file: %w" , err )
851
851
}
@@ -864,7 +864,7 @@ func run(ctx context.Context, opts options.Options, execArgs *execArgsInfo) erro
864
864
opts .Logger (log .LevelInfo , "=== Running the setup command %q as the root user..." , opts .SetupScript )
865
865
866
866
envKey := "ENVBUILDER_ENV"
867
- envFile := magicDir .Join ("environ" )
867
+ envFile := workingDir .Join ("environ" )
868
868
file , err := opts .Filesystem .Create (envFile )
869
869
if err != nil {
870
870
return fmt .Errorf ("create environ file: %w" , err )
@@ -962,7 +962,7 @@ func RunCacheProbe(ctx context.Context, opts options.Options) (v1.Image, error)
962
962
return nil , fmt .Errorf ("--cache-repo must be set when using --get-cached-image" )
963
963
}
964
964
965
- magicDir := magicdir .At (opts .MagicDirBase )
965
+ workingDir := workingdir .At (opts .MagicDirBase )
966
966
967
967
stageNumber := 0
968
968
startStage := func (format string , args ... any ) func (format string , args ... any ) {
@@ -978,7 +978,7 @@ func RunCacheProbe(ctx context.Context, opts options.Options) (v1.Image, error)
978
978
979
979
opts .Logger (log .LevelInfo , "%s %s - Build development environments from repositories in a container" , newColor (color .Bold ).Sprintf ("envbuilder" ), buildinfo .Version ())
980
980
981
- cleanupDockerConfigJSON , err := initDockerConfigJSON (opts .Logger , magicDir , opts .DockerConfigBase64 )
981
+ cleanupDockerConfigJSON , err := initDockerConfigJSON (opts .Logger , workingDir , opts .DockerConfigBase64 )
982
982
if err != nil {
983
983
return nil , err
984
984
}
@@ -1031,7 +1031,7 @@ func RunCacheProbe(ctx context.Context, opts options.Options) (v1.Image, error)
1031
1031
if err != nil {
1032
1032
return nil , fmt .Errorf ("git clone options: %w" , err )
1033
1033
}
1034
- cloneOpts .Path = magicDir .Join ("repo" )
1034
+ cloneOpts .Path = workingDir .Join ("repo" )
1035
1035
1036
1036
endStage := startStage ("📦 Remote repo build mode enabled, cloning %s to %s for build context..." ,
1037
1037
newColor (color .FgCyan ).Sprintf (opts .GitURL ),
@@ -1056,7 +1056,7 @@ func RunCacheProbe(ctx context.Context, opts options.Options) (v1.Image, error)
1056
1056
}
1057
1057
1058
1058
defaultBuildParams := func () (* devcontainer.Compiled , error ) {
1059
- dockerfile := magicDir .Join ("Dockerfile" )
1059
+ dockerfile := workingDir .Join ("Dockerfile" )
1060
1060
file , err := opts .Filesystem .OpenFile (dockerfile , os .O_CREATE | os .O_WRONLY , 0o644 )
1061
1061
if err != nil {
1062
1062
return nil , err
@@ -1078,7 +1078,7 @@ func RunCacheProbe(ctx context.Context, opts options.Options) (v1.Image, error)
1078
1078
return & devcontainer.Compiled {
1079
1079
DockerfilePath : dockerfile ,
1080
1080
DockerfileContent : content ,
1081
- BuildContext : magicDir .Path (),
1081
+ BuildContext : workingDir .Path (),
1082
1082
}, nil
1083
1083
}
1084
1084
@@ -1118,7 +1118,7 @@ func RunCacheProbe(ctx context.Context, opts options.Options) (v1.Image, error)
1118
1118
opts .Logger (log .LevelInfo , "No Dockerfile or image specified; falling back to the default image..." )
1119
1119
fallbackDockerfile = defaultParams .DockerfilePath
1120
1120
}
1121
- buildParams , err = devContainer .Compile (opts .Filesystem , devcontainerDir , magicDir .Path (), fallbackDockerfile , opts .WorkspaceFolder , false , os .LookupEnv )
1121
+ buildParams , err = devContainer .Compile (opts .Filesystem , devcontainerDir , workingDir .Path (), fallbackDockerfile , opts .WorkspaceFolder , false , os .LookupEnv )
1122
1122
if err != nil {
1123
1123
return nil , fmt .Errorf ("compile devcontainer.json: %w" , err )
1124
1124
}
@@ -1184,7 +1184,7 @@ func RunCacheProbe(ctx context.Context, opts options.Options) (v1.Image, error)
1184
1184
// So we add them to the default ignore list. See:
1185
1185
// https://github.com/GoogleContainerTools/kaniko/blob/63be4990ca5a60bdf06ddc4d10aa4eca0c0bc714/cmd/executor/cmd/root.go#L136
1186
1186
ignorePaths := append ([]string {
1187
- magicDir .Path (),
1187
+ workingDir .Path (),
1188
1188
opts .WorkspaceFolder ,
1189
1189
// See: https://github.com/coder/envbuilder/issues/37
1190
1190
"/etc/resolv.conf" ,
@@ -1207,10 +1207,10 @@ func RunCacheProbe(ctx context.Context, opts options.Options) (v1.Image, error)
1207
1207
// build via executor.RunCacheProbe we need to have the *exact* copy of the
1208
1208
// envbuilder binary available used to build the image and we also need to
1209
1209
// add the magic directives to the Dockerfile content.
1210
- // MAGICDIR
1211
- buildParams .DockerfileContent += magicdir .Directives
1210
+ // WORKINGDIR
1211
+ buildParams .DockerfileContent += workingdir .Directives
1212
1212
1213
- magicTempDir := filepath .Join (buildParams .BuildContext , magicdir .TempDir )
1213
+ magicTempDir := filepath .Join (buildParams .BuildContext , workingdir .TempDir )
1214
1214
if err := opts .Filesystem .MkdirAll (magicTempDir , 0o755 ); err != nil {
1215
1215
return nil , fmt .Errorf ("create magic temp dir in build context: %w" , err )
1216
1216
}
@@ -1546,11 +1546,11 @@ func maybeDeleteFilesystem(logger log.Func, force bool) error {
1546
1546
// We always expect the magic directory to be set to the default, signifying that
1547
1547
// the user is running envbuilder in a container.
1548
1548
// If this is set to anything else we should bail out to prevent accidental data loss.
1549
- // defaultMagicDir := magicdir.MagicDir ("")
1549
+ // defaultWorkingDir := workingdir.WorkingDir ("")
1550
1550
kanikoDir , ok := os .LookupEnv ("KANIKO_DIR" )
1551
- if ! ok || strings .TrimSpace (kanikoDir ) != magicdir .Default .Path () {
1551
+ if ! ok || strings .TrimSpace (kanikoDir ) != workingdir .Default .Path () {
1552
1552
if ! force {
1553
- logger (log .LevelError , "KANIKO_DIR is not set to %s. Bailing!\n " , magicdir .Default .Path ())
1553
+ logger (log .LevelError , "KANIKO_DIR is not set to %s. Bailing!\n " , workingdir .Default .Path ())
1554
1554
logger (log .LevelError , "To bypass this check, set FORCE_SAFE=true." )
1555
1555
return errors .New ("safety check failed" )
1556
1556
}
@@ -1627,13 +1627,13 @@ func parseMagicImageFile(fs billy.Filesystem, path string, v any) error {
1627
1627
return nil
1628
1628
}
1629
1629
1630
- func initDockerConfigJSON (logf log.Func , magicDir magicdir. MagicDir , dockerConfigBase64 string ) (func () error , error ) {
1630
+ func initDockerConfigJSON (logf log.Func , workingDir workingdir. WorkingDir , dockerConfigBase64 string ) (func () error , error ) {
1631
1631
var cleanupOnce sync.Once
1632
1632
noop := func () error { return nil }
1633
1633
if dockerConfigBase64 == "" {
1634
1634
return noop , nil
1635
1635
}
1636
- cfgPath := magicDir .Join ("config.json" )
1636
+ cfgPath := workingDir .Join ("config.json" )
1637
1637
decoded , err := base64 .StdEncoding .DecodeString (dockerConfigBase64 )
1638
1638
if err != nil {
1639
1639
return noop , fmt .Errorf ("decode docker config: %w" , err )
@@ -1656,7 +1656,7 @@ func initDockerConfigJSON(logf log.Func, magicDir magicdir.MagicDir, dockerConfi
1656
1656
}
1657
1657
logf (log .LevelInfo , "Wrote Docker config JSON to %s" , cfgPath )
1658
1658
oldDockerConfig := os .Getenv ("DOCKER_CONFIG" )
1659
- _ = os .Setenv ("DOCKER_CONFIG" , magicDir .Path ())
1659
+ _ = os .Setenv ("DOCKER_CONFIG" , workingDir .Path ())
1660
1660
newDockerConfig := os .Getenv ("DOCKER_CONFIG" )
1661
1661
logf (log .LevelInfo , "Set DOCKER_CONFIG to %s" , newDockerConfig )
1662
1662
cleanup := func () error {
0 commit comments