Skip to content

Move core actions to dagger/core sub-package #1825

Closed

Description

@shykes

Problem

All core actions are currently available under dagger.io/dagger. For example dagger.#Exec, dagger.#Pull etc.

From observing new developers, I am noticing that they tend to go to these core actions first. This makes sense because dagger.io/dagger is the primary entrypoint for the Dagger API. However, often these core actions are not what developers should be using: they are relatively low-level, and a higher-level package might be a better fit in most cases.

Example:

B62BD24A-65C1-419D-AD6C-165BABD61E7B

Solution

Move core actions to a sub-package which makes their low-level nature more clear. I suggest dagger.io/dagger/core as originally proposed by @gerhard .

Since some developers already rely on the current paths, we can leave some hidden compatibility aliases, but direct all new developers to use the new API.

Activity

  1. shykes commented on Mar 21, 2022

    @shykes
    ContributorAuthor

    @helderco does this feel right to you?

    • If not: let's discuss
    • If so: can you add it to your "last call for API changes" list? :)
  2. added this to the milestone on Mar 21, 2022
  3. helderco commented on Mar 26, 2022

    @helderco
    Contributor

    With dagger.#Dockerfile vs docker.#Dockerfile it makes it harder to know which one to use. By moving to core.#Dockerfile it's a bit more clear that's a bit more lower level.

    Since the point is to discourage the use of dagger/core directly, there's a few details worth discussing.

    Plan

    Currently, actions are matched against a single namespace. The biggest issue are the client actions (to keep dagger.#Plan). There's two options:

    1. Look for actions both in core and dagger packages (/cc @aluzzardi);
    2. Move everything to core and alias in dagger what we want to be "public" use;
    Option 2 (implemented in #1866)
    package dagger
    
    import "dagger.io/dagger/core"
    
    #Plan: core.#Plan
    
    // Types
    
    #FS:      core.#FS
    #Scratch: core.#Scratch
    #Secret:  core.#Secret
    #Service: core.#Service
    
    #Address: core.#Address
    
    // Image
    
    #Ref:         core.#Ref
    #ImageConfig: core.#ImageConfig
    
    #HealthCheck: core.#HealthCheck
    
    // Mounts
    
    #CacheDir: core.#CacheDir
    #TempDir:  core.#TempDir
    

    Secrets

    We don't have higher level abstractions on top of our secret actions, so this conflicts with the idea to discourage direct usage of core actions.

    We could make an exception here for a dagger.io/dagger/secrets package with secrets.#Decode, secrets.#Trim, etc. Or alias in dagger.

    Mounts

    I don't think it's necessary to scope exec.#Mount (same issue as secrets above) because you don't necessarily need to use it explicitly when setting values for docker.#Run, since it already sets it:

    #Run: {
        mounts: [name=string]: core.#Mount
    }

    So:

    dagger.#Plan & {
    -	_nodeModulesMount: "/src/node_modules": core.#Mount & {
    +	_nodeModulesMount: "/src/node_modules": {
    		dest:     "/src/node_modules"
    -		type:     "cache"
    -		contents: core.#CacheDir & {
    -		contents: {
    			id: "todoapp-modules-cache"
    		}
    	}

    See https://cuelang.org/play/?id=Ju4lItnwo4M#cue@export@cue 👈

    Although, putting #CacheDir and #TempDir in contents makes it a bit clearer, especially if we add another type with conflicting fields later on.

    Maybe alias them in dagger?

  4. shykes commented on Mar 27, 2022

    @shykes
    ContributorAuthor

    With dagger.#Dockerfile vs docker.#Dockerfile it makes it harder to know which one to use. By moving to core.#Dockerfile it's a bit more clear that's a bit more lower level.

    Since the point is to discourage the use of dagger/core directly, there's a few details worth discussing.

    Plan

    Currently, actions are matched against a single namespace. The biggest issue are the client actions (to keep dagger.#Plan). There's two options:

    1. Look for actions both in core and dagger packages (/cc @aluzzardi);
    2. Move everything to core and alias in dagger what we want to be "public" use;

    I like option 1 better.

    • From a CUE point of view, it's cleaner: core (short for "core actions") is a higher-level package which depends on dagger, but not the other way around. (That's a slight downside of the word "core": it implies that there is nothing below, but in fact "dagger" holds core types that are more "core" than core actions :)

    • From a Go point of view, I already have implemented support for actions in two packages. The PR containing it was never merged, but the code itself worked just fine. I hope I can retrieve it, it would save you a little bit of time (nothing super hard, just code plumbing).

    • Aliasing creates new problems that are best avoided.

    Secrets

    We don't have higher level abstractions on top of our secret actions, so this conflicts with the idea to discourage direct usage of core actions.

    We could make an exception here for a dagger.io/dagger/secrets package with secrets.#Decode, secrets.#Trim, etc. Or alias in dagger.

    I think it's fine that it stays in core. They are in fact core actions, and I would love for higher-level packages to wrap them, for example a sops package, a yaml package, etc.

    Note: separately, I do like the feel of secrets.#Foo instead of core.#FooSecret, that's an argument in favor of dagger.io/dagger/core/secrets (note the /core).

    Mounts

    Maybe alias them in dagger?

    I really think we should avoid aliasing as much as possible, it forces us to be more rigorous - one-off exceptions are a slippery slope.

    I know we discussed it already and decided against it, but note that having dagger.io/dagger/core/exec would slightly improve the DX here, because mounts would be scoped to exec and not pollute top-level core.

  5. helderco commented on Mar 28, 2022

    @helderco
    Contributor

    Agreed. 🙂

    I've implemented option 2, please review #1866.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions