@@ -9,8 +9,11 @@ import (
99 "dagger.io/dockersdk/utils"
1010)
1111
12- func (d * Docker ) build (platform * dagger.Platform , target * string , dockerfile * string ) * dagger.Container {
13- opts := dagger.DirectoryDockerBuildOpts {}
12+ func (d * Docker ) build (platform * dagger.Platform , target * string , dockerfile * string , buildArgs []dagger.BuildArg , secrets []* dagger.Secret ) * dagger.Container {
13+ opts := dagger.DirectoryDockerBuildOpts {
14+ BuildArgs : buildArgs ,
15+ Secrets : secrets ,
16+ }
1417
1518 if platform != nil {
1619 opts .Platform = * platform
@@ -30,11 +33,38 @@ func (d *Docker) build(platform *dagger.Platform, target *string, dockerfile *st
3033func (d * Docker ) buildFctTypeDef (ctx context.Context ) (* dagger.Function , * dagger.TypeDef ) {
3134 typedef := dag .Function ("Build" , dag .TypeDef ().WithObject ("Container" )).
3235 WithDescription ("Build a container from the Dockerfile in the current directory" ).
33- WithArg ("dockerfile" , dag .TypeDef ().WithKind (dagger .TypeDefKindStringKind ).WithOptional (true ), dagger.FunctionWithArgOpts {
34- DefaultValue : utils .LoadDefaultValue (d .dockerfile .Filename ()),
35- Description : "Path to the Dockerfile to use." ,
36- })
36+ WithArg ("dockerfile" ,
37+ dag .TypeDef ().WithKind (dagger .TypeDefKindStringKind ).WithOptional (true ),
38+ dagger.FunctionWithArgOpts {
39+ DefaultValue : utils .LoadDefaultValue (d .dockerfile .Filename ()),
40+ Description : "Path to the Dockerfile to use." ,
41+ })
42+
43+ /////
44+ // Add the build arguments
45+ for key , value := range d .dockerfile .Args () {
46+ buildArgOpts := dagger.FunctionWithArgOpts {
47+ Description : fmt .Sprintf ("Set %s build argument" , key ),
48+ }
49+
50+ if value != "" {
51+ buildArgOpts .DefaultValue = utils .LoadDefaultValue (value )
52+ }
53+
54+ typedef = typedef .WithArg (key , dag .TypeDef ().WithKind (dagger .TypeDefKindStringKind ), buildArgOpts )
55+ }
56+
57+ //////
58+ // Add the secrets arguments
59+ for _ , secret := range d .dockerfile .Secrets () {
60+ typedef = typedef .WithArg (secret ,
61+ dag .TypeDef ().WithObject ("Secret" ),
62+ dagger.FunctionWithArgOpts {
63+ Description : fmt .Sprintf ("Set %s secret" , secret ),
64+ })
65+ }
3766
67+ /////
3868 // Add the platform argument
3969 defaultPlatformArgOpts := dagger.FunctionWithArgOpts {
4070 Description : "Platform to build." ,
@@ -55,6 +85,7 @@ func (d *Docker) buildFctTypeDef(ctx context.Context) (*dagger.Function, *dagger
5585 defaultPlatformArgOpts ,
5686 )
5787
88+ /////
5889 // If stages are declared in the Dockerfile, we add an enum and the stage option to the function.
5990 if len (d .dockerfile .Stages ()) != 0 {
6091 stageTypeDef := dag .TypeDef ().WithEnum (fmt .Sprintf ("%sStage" , d .name ))
0 commit comments