@@ -59,17 +59,17 @@ type Docker struct {
5959 // The group ID to run the container as.
6060 gid string
6161
62+ // HostMount specifies a mount point from the Docker host into the Docker
63+ // container. The format is "{host-dir}:{local-dir}".
64+ HostMount string
65+
6266 // run runs the docker command.
6367 run func (args ... string ) error
6468}
6569
6670// BuildRequest contains all the information required for a language
6771// container to run the build command.
6872type BuildRequest struct {
69- // HostMount specifies a mount point from the Docker host into the Docker
70- // container. The format is "{host-dir}:{local-dir}".
71- HostMount string
72-
7373 // LibraryID specifies the ID of the library to build.
7474 LibraryID string
7575
@@ -87,10 +87,6 @@ type ConfigureRequest struct {
8787 // ApiRoot specifies the root directory of the API specification repo.
8888 ApiRoot string
8989
90- // HostMount specifies a mount point from the Docker host into the Docker
91- // container. The format is "{host-dir}:{local-dir}".
92- HostMount string
93-
9490 // libraryID specifies the ID of the library to configure.
9591 LibraryID string
9692
@@ -118,10 +114,6 @@ type GenerateRequest struct {
118114 // ApiRoot specifies the root directory of the API specification repo.
119115 ApiRoot string
120116
121- // HostMount specifies a mount point from the Docker host into the Docker
122- // container. The format is "{host-dir}:{local-dir}".
123- HostMount string
124-
125117 // LibraryID specifies the ID of the library to generate.
126118 LibraryID string
127119
@@ -147,12 +139,6 @@ type ReleaseInitRequest struct {
147139 // create a pull request. This flag is ignored if Push is set to true.
148140 Commit bool
149141
150- // HostMount is used to remap Docker mount paths when running in environments
151- // where Docker containers are siblings (e.g., Kokoro).
152- // It specifies a mount point from the Docker host into the Docker container.
153- // The format is "{host-dir}:{local-dir}".
154- HostMount string
155-
156142 // LibrarianConfig is a pointer to the [config.LibrarianConfig] struct, holding
157143 // global files configuration in a language repository.
158144 LibrarianConfig * config.LibrarianConfig
@@ -180,14 +166,33 @@ type ReleaseInitRequest struct {
180166 State * config.LibrarianState
181167}
182168
169+ // DockerOptions contains optional configuration parameters for invoking
170+ // docker commands.
171+ type DockerOptions struct {
172+ // UserUID is the user ID of the current user. It is used to run Docker
173+ // containers with the same user, so that created files have the correct
174+ // ownership.
175+ UserUID string
176+ // UserGID is the group ID of the current user. It is used to run Docker
177+ // containers with the same user, so that created files have the correct
178+ // ownership.
179+ UserGID string
180+ // HostMount is used to remap Docker mount paths when running in environments
181+ // where Docker containers are siblings (e.g., Kokoro).
182+ // It specifies a mount point from the Docker host into the Docker container.
183+ // The format is "{host-dir}:{local-dir}".
184+ HostMount string
185+ }
186+
183187// New constructs a Docker instance which will invoke the specified
184188// Docker image as required to implement language-specific commands,
185189// providing the container with required environment variables.
186- func New (workRoot , image , uid , gid string ) (* Docker , error ) {
190+ func New (workRoot , image string , options * DockerOptions ) (* Docker , error ) {
187191 docker := & Docker {
188- Image : image ,
189- uid : uid ,
190- gid : gid ,
192+ Image : image ,
193+ uid : options .UserUID ,
194+ gid : options .UserGID ,
195+ HostMount : options .HostMount ,
191196 }
192197 docker .run = func (args ... string ) error {
193198 return docker .runCommand ("docker" , args ... )
@@ -227,7 +232,7 @@ func (c *Docker) Generate(ctx context.Context, request *GenerateRequest) error {
227232 fmt .Sprintf ("%s:/output" , request .Output ),
228233 fmt .Sprintf ("%s:/source:ro" , request .ApiRoot ), // readonly volume
229234 }
230- return c .runDocker (ctx , request . HostMount , CommandGenerate , mounts , commandArgs )
235+ return c .runDocker (ctx , CommandGenerate , mounts , commandArgs )
231236}
232237
233238// Build builds the library with an ID of libraryID, as configured in
@@ -257,7 +262,7 @@ func (c *Docker) Build(ctx context.Context, request *BuildRequest) error {
257262 "--repo=/repo" ,
258263 }
259264
260- return c .runDocker (ctx , request . HostMount , CommandBuild , mounts , commandArgs )
265+ return c .runDocker (ctx , CommandBuild , mounts , commandArgs )
261266}
262267
263268// Configure configures an API within a repository, either adding it to an
@@ -302,7 +307,7 @@ func (c *Docker) Configure(ctx context.Context, request *ConfigureRequest) (stri
302307 mounts = append (mounts , fmt .Sprintf ("%s/%s:/repo/%s:ro" , request .RepoDir , globalFile , globalFile ))
303308 }
304309
305- if err := c .runDocker (ctx , request . HostMount , CommandConfigure , mounts , commandArgs ); err != nil {
310+ if err := c .runDocker (ctx , CommandConfigure , mounts , commandArgs ); err != nil {
306311 return "" , err
307312 }
308313
@@ -337,15 +342,15 @@ func (c *Docker) ReleaseInit(ctx context.Context, request *ReleaseInitRequest) e
337342 fmt .Sprintf ("%s:/output" , request .Output ),
338343 }
339344
340- if err := c .runDocker (ctx , request . HostMount , CommandReleaseInit , mounts , commandArgs ); err != nil {
345+ if err := c .runDocker (ctx , CommandReleaseInit , mounts , commandArgs ); err != nil {
341346 return err
342347 }
343348
344349 return nil
345350}
346351
347- func (c * Docker ) runDocker (_ context.Context , hostMount string , command Command , mounts []string , commandArgs []string ) (err error ) {
348- mounts = maybeRelocateMounts (hostMount , mounts )
352+ func (c * Docker ) runDocker (_ context.Context , command Command , mounts []string , commandArgs []string ) (err error ) {
353+ mounts = maybeRelocateMounts (c . HostMount , mounts )
349354 args := []string {
350355 "run" ,
351356 "--rm" , // Automatically delete the container after completion
0 commit comments