@@ -123,6 +123,10 @@ type Options struct {
123
123
// to using a devcontainer that some might find simpler.
124
124
DockerfilePath string `env:"DOCKERFILE_PATH"`
125
125
126
+ // CacheTTLDays is the number of days to use cached layers before
127
+ // expiring them. Defaults to 7 days.
128
+ CacheTTLDays int `env:"CACHE_TTL_DAYS"`
129
+
126
130
// DockerConfigBase64 is a base64 encoded Docker config
127
131
// file that will be used to pull images from private
128
132
// container registries.
@@ -557,6 +561,10 @@ func Run(ctx context.Context, options Options) error {
557
561
logf (codersdk .LogLevelInfo , "%s" , scanner .Text ())
558
562
}
559
563
}()
564
+ cacheTTL := time .Hour * 24 * 7
565
+ if options .CacheTTLDays != 0 {
566
+ cacheTTL = time .Hour * 24 * time .Duration (options .CacheTTLDays )
567
+ }
560
568
561
569
endStage := startStage ("🏗️ Building image..." )
562
570
// At this point we have all the context, we can now build!
@@ -578,7 +586,7 @@ func Run(ctx context.Context, options Options) error {
578
586
CompressionLevel : 3 ,
579
587
CacheOptions : config.CacheOptions {
580
588
// Cache for a week by default!
581
- CacheTTL : time . Hour * 24 * 7 ,
589
+ CacheTTL : cacheTTL ,
582
590
CacheDir : options .BaseImageCacheDir ,
583
591
},
584
592
ForceUnpack : true ,
@@ -931,20 +939,23 @@ func OptionsFromEnv(getEnv func(string) (string, bool)) Options {
931
939
if env == "" {
932
940
continue
933
941
}
942
+ e , ok := getEnv (env )
943
+ if ! ok {
944
+ continue
945
+ }
934
946
switch fieldTyp .Type .Kind () {
935
947
case reflect .String :
936
- v , _ := getEnv (env )
937
- field .SetString (v )
948
+ field .SetString (e )
938
949
case reflect .Bool :
939
- e , _ := getEnv (env )
940
950
v , _ := strconv .ParseBool (e )
941
951
field .SetBool (v )
952
+ case reflect .Int :
953
+ v , _ := strconv .ParseInt (e , 10 , 64 )
954
+ field .SetInt (v )
942
955
case reflect .Slice :
943
- v , ok := getEnv (env )
944
- if ! ok {
945
- continue
946
- }
947
- field .Set (reflect .ValueOf (strings .Split (v , "," )))
956
+ field .Set (reflect .ValueOf (strings .Split (e , "," )))
957
+ default :
958
+ panic (fmt .Sprintf ("unsupported type %s in OptionsFromEnv" , fieldTyp .Type .String ()))
948
959
}
949
960
}
950
961
0 commit comments