@@ -30,16 +30,22 @@ type dockerVolumeWorkspaceCreator struct {
3030
3131var _ Creator = & dockerVolumeWorkspaceCreator {}
3232
33- func (wc * dockerVolumeWorkspaceCreator ) Create (ctx context.Context , repo * graphql.Repository , steps []batcheslib.Step , archive repozip.Archive ) (Workspace , error ) {
33+ func (wc * dockerVolumeWorkspaceCreator ) Create (ctx context.Context , repo * graphql.Repository ,
34+ steps []batcheslib.Step , archive repozip.Archive ) (ws Workspace , err error ) {
3435 volume , err := wc .createVolume (ctx )
3536 if err != nil {
3637 return nil , errors .Wrap (err , "creating Docker volume" )
3738 }
3839
40+ defer func () {
41+ if err != nil {
42+ deleteVolume (ctx , volume )
43+ }
44+ }()
45+
3946 // Figure out the user that containers will be run as.
4047 ug := docker.UIDGID {}
4148 if len (steps ) > 0 {
42- var err error
4349 img , err := wc .EnsureImage (ctx , steps [0 ].Container )
4450 if err != nil {
4551 return nil , err
@@ -74,6 +80,10 @@ func (*dockerVolumeWorkspaceCreator) createVolume(ctx context.Context) (string,
7480 return string (bytes .TrimSpace (out )), nil
7581}
7682
83+ func deleteVolume (ctx context.Context , volume string ) error {
84+ return exec .CommandContext (ctx , "docker" , "volume" , "rm" , volume ).Run ()
85+ }
86+
7787func (* dockerVolumeWorkspaceCreator ) prepareGitRepo (ctx context.Context , w * dockerVolumeWorkspace ) error {
7888 script := `#!/bin/sh
7989
@@ -219,7 +229,7 @@ var _ Workspace = &dockerVolumeWorkspace{}
219229
220230func (w * dockerVolumeWorkspace ) Close (ctx context.Context ) error {
221231 // Cleanup here is easy: we just get rid of the Docker volume.
222- return exec . CommandContext (ctx , "docker" , "volume" , "rm" , w .volume ). Run ( )
232+ return deleteVolume (ctx , w .volume )
223233}
224234
225235func (w * dockerVolumeWorkspace ) DockerRunOpts (ctx context.Context , target string ) ([]string , error ) {
0 commit comments