Skip to content

Container: add withDirectory and withFile #3264

Closed

Description

@vito
type Container {
  withDirectory(path: String!, directory: DirectoryID!): Container!
  withFile(path: String!, file: FileID!): Container!
}

Use case: copying the contents of a directory/file into a container's rootfs, rather than mounting it.

Some discussion in #3219 (comment)

Activity

  1. changed the title [-]Container: add withDirectory[/-] [+]Container: add `withDirectory`[/+] on Oct 6, 2022
  2. vito commented on Oct 21, 2022

    @vito
    ContributorAuthor

    Now that Container.withFS exists I don't think we need this, because you can just take the existing FS and replace it with a copied one:

    func TestContainerDirectoryCopy(t *testing.T) {
    	c, ctx := connect(t)
    
    	dirID, err := c.Core().Directory().
    		WithNewFile("hello.txt", api.DirectoryWithNewFileOpts{
    			Contents: "hi there",
    		}).
    		ID(ctx)
    	require.NoError(t, err)
    
    	ctr := c.Core().Container().From("alpine:3.16.2")
    
    	cpID, err := ctr.FS().WithCopiedDirectory(dirID, "/content").ID(ctx)
    	require.NoError(t, err)
    
    	rootfs := t.TempDir()
    
    	ctr = ctr.WithFS(cpID)
    	ok, err := ctr.FS().Export(ctx, rootfs)
    	require.NoError(t, err)
    	require.True(t, ok)
    
    	content, err := os.ReadFile(filepath.Join(rootfs, "content", "hello.txt"))
    	require.NoError(t, err)
    	require.Equal(t, "hi there", string(content))
    
    	content, err = os.ReadFile(filepath.Join(rootfs, "etc", "alpine-release"))
    	require.NoError(t, err)
    	require.Equal(t, "3.16.2\n", string(content))
    }

    Erring on the side of closing this since we've used similar justification to turn down other duplicative APIs, e.g. here: #3179 (comment)

  3. reopened this on Oct 24, 2022
  4. self-assigned this
    on Oct 24, 2022
  5. changed the title [-]Container: add `withDirectory`[/-] [+]Container: add `withCopiedDirectory`[/+] on Oct 26, 2022
  6. changed the title [-]Container: add `withCopiedDirectory`[/-] [+]Container: add `withCopiedDirectory` and `withCopiedFile`[/+] on Oct 26, 2022
  7. vito commented on Oct 26, 2022

    @vito
    ContributorAuthor

    Reopening as it's way more convenient to just have this directly in the API, since it'll propagate to all codegen'd SDKs.

  8. removed their assignment
    on Oct 26, 2022
  9. changed the title [-]Container: add `withCopiedDirectory` and `withCopiedFile`[/-] [+]Container: add `withDirectory` and `withFile`[/+] on Oct 28, 2022
  10. added
    area/engine
    and removed on Dec 5, 2022
  11. sipsma commented on Dec 6, 2022

    @sipsma
    Contributor

    Done here #3827

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/engine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions