Skip to content

Standardize project entrypoint #4414

Closed
Closed

Description

@shykes

This has been resolved with Dagger Functions. Thank you all for your help!

Problem

TLDR: Dagger does not define a standard interface for project entrypoints, which limits what it can do for users.

Dagger works by writing an entrypoint for your project: custom software that defines the pipelines for that project, and how to run them.

graph LR;

subgraph program["Project entrypoint"]
  lib["Dagger SDK"]
end

engine["Dagger Engine"]

subgraph A["Project build pipeline"]
  A1[" "] -.-> A2[" "] -.-> A3[" "]
end
subgraph B["Project test pipeline"]
  B1[" "] -.-> B2[" "] -.-> B3[" "] -.-> B4[" "]
end
subgraph C["Project deploy pipeline"]
  C1[" "] -.-> C2[" "] -.-> C3[" "] -.-> C4[" "]
end

lib -..-> engine -..-> A1 & B1 & C1
Loading

The problem is that Dagger does not define a standard interface that a project entrypoint must implement. This causes several problems:

  1. Friction. Each project author must do the work of defining an interface, with minimal guidance. For first-time users especially, this can lead to confusion and uncertainty.
  2. Fragmentation. In the absence of a standardized interface, each project has its own unique snwowflake of an interface. As a result, the benefits of a unified Dagger ecosystem (reusable code, tooling and skills) does not extend to tooling. Notably, it becomes impossible to create CI or developer productivity tooling that can works out of the box with any Dagger projects. Instead, custom tooling must be developed for each project: an artificial limitation since the underlying pipelines are fully reusable!
graph LR;

operator
subgraph toolingEcosystem["Fragmented tooling ecosystem 😢"]
tool1["Project-specific tool"]
tool2["Project-specific tool"]
tool3["Project-specific tool"]
end
interface1["Project-specific entrypoint interface"]
interface2["Project-specific entrypoint interface"]
interface3["Project-specific entrypoint interface"]

entrypoint1["Project entrypoint"]
entrypoint2["Project entrypoint"]
entrypoint3["Project entrypoint"]

subgraph pipelineEcosystem["Unified pipeline ecosystem 🥳"]

A1[" "]
A2[" "]
A3[" "]
A4[" "]
B1[" "]
B2[" "]
B3[" "]
B4[" "]
C1[" "]
C2[" "]
C3[" "]
C4[" "]
D1[" "]
D2[" "]
D3[" "]
D4[" "]
E1[" "]
E2[" "]
E3[" "]
E4[" "]

A1 -.-> A2 -.-> D3
B1 -.-> B2 -.-> B3 -.-> B4
C1 -.-> C2 -.-> D3 -.-> C4
D1 -.-> D2 -.-> D3 -.-> D4 & E4
E1 -.-> E2 -.-> D4

end


operator -.->  tool1 & tool2 & tool3
tool1 -.-> interface1 -.-> entrypoint1 -.-> A1 & B1
tool2 -.-> interface2 -.-> entrypoint2 -.-> C1 & D1
tool3 -.-> interface3 -.-> entrypoint3 -.-> E1
Loading

Examples of features that would be unlocked by a standardized entrypoint interface:

These are basic features of existing CI/CD systems. Until the Dagger ecosystem can offer equivalent features and make them work on all Dagger projects, we will be stuck using legacy CI systems as a crutch.

This makes it more difficult to appreciate the more advanced features which set it apart from other CI/CD platforms. In fact, user feedback so far indicates that even the most motivated power users cannot fully replace their legacy CI platform with Dagger, even if they are committed to doing so.

Solution

Define a standard interface for project entrypoints; implement it in official tooling to demonstrate its value; encourage implementation by third-party tooling; and make sure to make it optional, so that early adopters who have already defined their own interface out of necessity, are not left behind.

graph LR;

operator
subgraph toolingEcosystem["Unified tooling ecosystem 🥳"]
tool1["Universal tool"]
tool2["Universal tool"]
tool3["Universal tool"]
end
interface["Standard entrypoint interface"]


entrypoint1["Project entrypoint"]
entrypoint2["Project entrypoint"]
entrypoint3["Project entrypoint"]

subgraph pipelineEcosystem["Unified pipeline ecosystem 🥳"]

A1[" "]
A2[" "]
A3[" "]
A4[" "]
B1[" "]
B2[" "]
B3[" "]
B4[" "]
C1[" "]
C2[" "]
C3[" "]
C4[" "]
D1[" "]
D2[" "]
D3[" "]
D4[" "]
E1[" "]
E2[" "]
E3[" "]
E4[" "]

A1 -.-> A2 -.-> D3
B1 -.-> B2 -.-> B3 -.-> B4
C1 -.-> C2 -.-> D3 -.-> C4
D1 -.-> D2 -.-> D3 -.-> D4 & E4
E1 -.-> E2 -.-> D4

end


operator -.->  tool1 & tool2 & tool3 -.-> interface -.-> entrypoint1 & entrypoint2 & entrypoint3
entrypoint1 -.-> A1 & B1
entrypoint2 -.-> C1 & D1
entrypoint3 -.-> E1
Loading

Traditional CI/CD platforms implement these features in roughly the same way:

  1. A concept of "project", "workspace" or equivalent
  2. A platform-specific declarative configuration, encoded in a language such as JSON or YAML, saved at a project-specific path

This should be our starting point with Dagger

Design

Design for this is TBD. Please submit your ideas snd proposals below,. At this stage, crazy ideas and bikeshedding is encouraged :)

Other tools

Below are examples of how other tools define entrypoints.

Tool Entrypoint file Outer object Inner objects
docker Dockerfile Build context targets
docker-compose docker-compose.yaml project services, networks, volumes
make Makefile ? Rules
bazel WORKSPACE and/or BUILD workspace and/or package targets, which are either files or rules
GIthub Actions .github/workflows repository workflows, events, jobs
Circle CI .circle/config
Gitlab CI .gitlab-ci.yml
Ninja Build build.ninja - targets
Tup Tupfile
Redo *.do - rules

Activity

  1. sagikazarmark commented on Jan 19, 2023

    @sagikazarmark
    Contributor

    What makes this problem really hard to solve IMO is that the entrypoint to running those pipelines is not actually Dagger.

    Dagger provides the mid-level SDKs (on top of the low-level GraphQL layer) and people end up building their own entrypoints and pipelines based on those.

    (Yes, pipelines as well (ie. Dagger is oblivious to running multiple containers in a sequence, it doesn't recognize the pipeline as a higher level construct).)

    That's both powerful and limits Dagger's capability to understand how pipelines are built.

    One crazy idea I had before is asking people to implement a "dummy mode" in their pipelines that allows injecting a noop Client into all call paths discovering the potential different pipelines and the sequence of container executions within.

  2. controlpl4n3 commented on Jan 19, 2023

    @controlpl4n3

    @sagikazarmark

    One crazy idea I had before is asking people to implement a "dummy mode" in their pipelines that allows injecting a noop Client into all call paths discovering the potential different pipelines and the sequence of container executions within.

    OK, now about another crazy idea? ...
    Would it be useful to have folks describe their pipelines in a structured format like yaml and then use something like pypyr.io to pre-process the piipeline and pass data (like an abstract syntax tree) to dagger ?

    FWIW, the guy behind pypyr is really smart and interested in use cases like this.

    Edit: or, as @cpdeethree suggests, a dag oriented approach: https://dagster.io/blog/introducing-dagster ?

  3. c-p-b commented on Jan 19, 2023

    @c-p-b

    @sagikazarmark

    One crazy idea I had before is asking people to implement a "dummy mode" in their pipelines that allows injecting a noop Client into all call paths discovering the potential different pipelines and the sequence of container executions within.

    OK, now about another crazy idea? ... Would it be useful to have folks describe their pipelines in a structured format like yaml and then use something like pypyr.io to pre-process the piipeline and pass data (like an abstract syntax tree) to dagger ?

    FWIW, the guy behind pypyr is really smart and interested in use cases like this.

    Personally, if going the declarative route, I really like the idea of literally using a dag to do this: Here's a guy who did a POC of similar: https://github.com/samsquire/mazzle-starter https://github.com/samsquire/mazzle

    Feels like it would be quite on brand for this project

  4. c-p-b commented on Jan 19, 2023

    @c-p-b

    Some further feedback/ideas based on how I've implemented dagger so far in my production level use cases. Mostly inspired by Github Actions

    • I have a .pipelines folder in every project
    • In that .pipelines folder i have two subfolders, /actions and /images
    • In the top level of the .pipelines folder I have a pipeline declaration e.g. ci.py. This bootstraps the dagger client, loads environment variables, and calls actions and images. "actions" and "images" expect the dagger client to be passed to them. It's essentially my DAG declaration.
    • Actions folder contains stuff like cloudrun.py (deploy to cloudrun), credentials.py (utils for loading gcloud and aws credentials into containers, etc). These are meant to be reusable across multiple pipelines. Could be in a shared repository
    • Images folder contains image specific stuff for specific artifacts - my_custom_nextjs_app.py has a function called build that will build the image from node:alpine and run tests, then create the production image from the outputs (multi-stage). Could even call this /artifacts to make it more generic
  5. robertu94 commented on Jan 20, 2023

    @robertu94

    A few comments. tl;dr I'm not sure that I fully "see the thread" here. That may be because I don't understand certain key words in context.

    For example, take the 4 identified missing features:

    Every CI/CD platform (except Dagger) can, given a directory, detect whether it is configured to use that platform

    I don't know what you mean here configured to use that platform. What are we trying to detect exactly?

    Every CI/CD platform (except Dagger) can, given a directory, discover available pipelines and how to run them

    This one I think I see the story for. Discovering the list pipelines is important (for example to show pass/fail status) in a ui.

    Every CI/CD platform (except Dagger) can, given a directory and a change event, can determine which pipelines to run in response to the change

    Depending on the granularity of this, this could be extremely complex. At one extreme this would need to implement something like bazel's knowledge of the relationship between built artifacts, source files, and unit tests so only a minimum number of tests needs to get run. While awesome, this is probably out of scope for dagger's core. A user could implement this if they could export such a list from their build system -- ninja and bazel provide tools for that, but I don't see it as Dagger's responsibility to do that but for me.

    What I am looking for from Dagger is to give me at a minimum an API which returns a python dict/json object of "CI" specific change events that triggers this run of dagger (ie a GitHub PR event may have different fields than a gitlab one), and eventually ideally a thin abstraction that handles the common cases (PR, new commit, human action, timer event, there could be others) consistently (with a subobject/dict containing the CI runner specifics) of events so I as the programmer can implement some basic things without knowing the full details of each.

    At the other extreme (and more reasonable) is some finer grain controls (I.e. we can reuse layers that run 'dnf install' within a calendar day unless there a specific manual override, because the user told use we could) around buildkit cache invalidation. This also is useful, but doesn't require deep knowledge of the build systems of say C++ which could be a nightmare.

    Every CI/CD platform (except Dagger) can, given a directory, provide a standard user interface (CLI or web) to its users, to interact with that directory's pipelines without having to write code of their own. This is independent from that platform's ability to be programmed

    I see the use case here if you want (and I expect you do want to eventually have) a hosted service offering. What is more important to me is if there is a an easy way to export this status to whatever channels (slack, GitHub UI, GitLab UI) I already look at for failures, and once I see a failure, I want to see the failure logs and artifacts. A web ui is less important to me (I could be convinced otherwise if it was truly awesome)

    --

    Lastly I wanted to respond to these two remarks

    (we should add) A platform-specific declarative configuration, encoded in a language such as JSON or YAML, saved at a project-specific path

    I think should be as absolutely minimal as possible. A huge reason I love dagger is that it's not YAML or JSON. One approach to have consistent paths and allow the different SDKs could be to leverage something like "shebangs" (the #!/usr/bin/env python lines at the top of files), and just require the file be named something like Daggerfile.

    In fact, user feedback so far indicates that even the most motivated power users cannot fully replace their legacy CI platform with Dagger, even if they are committed to doing so.

    This is me. But for me the key bottlenecks:

    1. how to handle events (ie a PR came in), see above
    2. executor support for non Linux things (i.e. Windows and MacOS, and at some level I'll probably have to work around Cray (Proprietary High Performance Computing (HPC) Linux variant used by nearly all of the "National capability" supercomputers in the US with almost as many oddities as AIX). Windows and Mac support would be awesome, but I understand would need to added to buildkit first. Cray is challenging for license reasons dagger has no control over, not technical ones. Not having these won't stop me from using Dagger, but to cover everything it would be Dagger+X
    3. and supporting some of the other run and build mount types on so I can get good CI performance, which I understand is being worked
    4. and how to import platform things like secrets or cache things between CI jobs using GitLab or GitHub specific things (and sane replacements when run locally for development)
    5. Quality debug logs -- I think a massive step forward was made with the Group api. Can't wait to have tooling available that was demonstrated using it to replay builds.

    Keep up the great work.

  6. shykes commented on Jan 20, 2023

    @shykes
    ContributorAuthor

    Some further feedback/ideas based on how I've implemented dagger so far in my production level use cases. Mostly inspired by Github Actions

    • I have a .pipelines folder in every project
    • In that .pipelines folder i have two subfolders, /actions and /images
    • In the top level of the .pipelines folder I have a pipeline declaration e.g. ci.py. This bootstraps the dagger client, loads environment variables, and calls actions and images. "actions" and "images" expect the dagger client to be passed to them. It's essentially my DAG declaration.
    • Actions folder contains stuff like cloudrun.py (deploy to cloudrun), credentials.py (utils for loading gcloud and aws credentials into containers, etc). These are meant to be reusable across multiple pipelines. Could be in a shared repository
    • Images folder contains image specific stuff for specific artifacts - my_custom_nextjs_app.py has a function called build that will build the image from node:alpine and run tests, then create the production image from the outputs (multi-stage). Could even call this /artifacts to make it more generic

    @cpdeethree thanks for the details. Could you share an example of your ci.py? Do you use this pattern in more than one repository, and if so do you have duplication of code between your different ci.py files?

  7. shykes commented on Jan 21, 2023

    @shykes
    ContributorAuthor

    A few comments. tl;dr I'm not sure that I fully "see the thread" here. That may be because I don't understand certain key words in context.

    That's probably my fault for wording it in a vague and confusing way 😄

    Every CI/CD platform (except Dagger) can, given a directory, detect whether it is configured to use that platform

    I don't know what you mean here configured to use that platform. What are we trying to detect exactly?

    I simply meant that, for example, Github Actions can look for .github/workflows; CircleCI can look for .circleci; but Dagger doesn't have an equivalent entrypoint for its configuration.

    Obviously this is not very useful on its own - perhaps this point is too granular and can simply be rolled into the next one .

    Every CI/CD platform (except Dagger) can, given a directory and a change event, can determine which pipelines to run in response to the change

    Depending on the granularity of this, this could be extremely complex. At one extreme this would need to implement something like bazel's knowledge of the relationship between built artifacts, source files, and unit tests so only a minimum number of tests needs to get run. While awesome, this is probably out of scope for dagger's core. A user could implement this if they could export such a list from their build system -- ninja and bazel provide tools for that, but I don't see it as Dagger's responsibility to do that but for me.

    Dagger actually handles this transparently :) As you construct your pipelines with the Dagger API, you are implicitly constructing a DAG which Dagger uses to infer which operations need to be executed, and which can be retrieved from cache. Typically the granularity is coarser than Bazel, because a typical Dagger pipeline operates on directories (possibly refined by exclude/include patterns), whereas Bazel operates on individual files. Dagger does support file-level granularity, though, so in theory you could reimplement a Bazel-like tool on top of the Dagger engine. Possibly even more powerful, since unlike Bazel, Dagger supports adding nodes to the DAG dynamically, so tooling like "gazelle" would become redundant.

    What I'm picturing as a "change hook" would be extremely simple: something like the all rule in a Makefile: basically a default entrypoint that is known, by convention, to be OK to run every time you make a change. And even multiple times in between changes, without ill side effects ie; idempotent.

    What I am looking for from Dagger is to give me at a minimum an API which returns a python dict/json object of "CI" specific change events that triggers this run of dagger (ie a GitHub PR event may have different fields than a gitlab one), and eventually ideally a thin abstraction that handles the common cases (PR, new commit, human action, timer event, there could be others) consistently (with a subobject/dict containing the CI runner specifics) of events so I as the programmer can implement some basic things without knowing the full details of each.

    This sounds like a hook system, correct? A way for the project's author to specify which pipelines to run when?

    At the other extreme (and more reasonable) is some finer grain controls (I.e. we can reuse layers that run 'dnf install' within a calendar day unless there a specific manual override, because the user told use we could) around buildkit cache invalidation. This also is useful, but doesn't require deep knowledge of the build systems of say C++ which could be a nightmare.

    I'm sure I understand this part. Could you give examples of what you mean?

    Every CI/CD platform (except Dagger) can, given a directory, provide a standard user interface (CLI or web) to its users, to interact with that directory's pipelines without having to write code of their own. This is independent from that platform's ability to be programmed

    I see the use case here if you want (and I expect you do want to eventually have) a hosted service offering. What is more important to me is if there is a an easy way to export this status to whatever channels (slack, GitHub UI, GitLab UI) I already look at for failures, and once I see a failure, I want to see the failure logs and artifacts. A web ui is less important to me (I could be convinced otherwise if it was truly awesome)

    We do indeed plan on shipping an awesome web UI :) But separately from that, there is currently no standardized way to discover and run a project's Dagger pipelines from the command-line. I can checkout a random open-source project, and run docker build, docker-compose up, vagrant up, etc. If the project has been configured to use that tool, something will happen. We used to have that feature in Dagger 0.2 (dagger do), but lost it in 0.3. I am observing that many users are confused by that regression, and would love for us to solve it. I think we can do it in a way that doesn't break our programming model (which is extremely powerful and has no equivalent today). I think we can make Dagger both programmable and familiar and approachable from the command-line.

    Lastly I wanted to respond to these two remarks

    (we should add) A platform-specific declarative configuration, encoded in a language such as JSON or YAML, saved at a project-specific path

    I think should be as absolutely minimal as possible. A huge reason I love dagger is that it's not YAML or JSON.

    I completely agree. This file should be complementary to the Dagger API. The goal is not to replace your pipeline code with inferior JSON and YAML, but to make it easier to find and run from the command-line and third-party tools.

    One approach to have consistent paths and allow the different SDKs could be to leverage something like "shebangs" (the #!/usr/bin/env python lines at the top of files), and just require the file be named something like Daggerfile.

    I would be interested in learning more about this idea :)

    This is me. But for me the key bottlenecks:

    1. how to handle events (ie a PR came in), see above

    May I ask what are the most important events for you to handle?

    1. executor support for non Linux things (i.e. Windows and MacOS, and at some level I'll probably have to work around Cray (Proprietary High Performance Computing (HPC) Linux variant used by nearly all of the "National capability" supercomputers in the US with almost as many oddities as AIX). Windows and Mac support would be awesome, but I understand would need to added to buildkit first. Cray is challenging for license reasons dagger has no control over, not technical ones. Not having these won't stop me from using Dagger, but to cover everything it would be Dagger+X

    I would love to have Windows and MacOS support... I think we will get there, but not in the short term, for the reasons you describe. Unless of course you find an acceptable way to run windows or macos in a Linux container :) Possibly using some of the recent bridges between containers and VMs; or perhaps projects such as Docker-OSX could help?

    1. and supporting some of the other run and build mount types on so I can get good CI performance, which I understand is being worked

    Could you share more details on this one? We may be able to solve these quickly. I would need more details to be sure.

    1. and how to import platform things like secrets or cache things between CI jobs using GitLab or GitHub specific things (and sane replacements when run locally for development)

    We are working on both of these :)

    For secrets: may I ask which tools or services you use to store them, that Dagger would need to integrate with?

    For cache persistence: what do you currently use, and what are your requirements for any new solution?

    1. Quality debug logs -- I think a massive step forward was made with the Group api. Can't wait to have tooling available that was demonstrated using it to replay builds.

    More on the way :)

    Keep up the great work.

    Thank you very much, this is all extremely useful.

  8. robertu94 commented on Jan 21, 2023

    @robertu94

    Thanks for the detailed response. I think I understand your goal more.

    I'm going to respond out of order to a few things to group some related things:

    Every CI/CD platform (except Dagger) can, given a directory, detect whether it is configured to use that platform

    I don't know what you mean here configured to use that platform. What are we trying to detect exactly?

    I simply meant that, for example, Github Actions can look for .github/workflows; CircleCI can look for .circleci; but Dagger doesn't have an equivalent entrypoint for its configuration.
    Obviously this is not very useful on its own - perhaps this point is too granular and can simply be rolled into the next one .

    Got it!

    One approach to have consistent paths and allow the different SDKs could be to leverage something like "shebangs" (the #!/usr/bin/env python lines at the top of files), and just require the file be named something like Daggerfile

    I would be interested in learning more about this idea :)

    Let me explain my shebang idea then. As you likely know, on Linux/Unix platforms, if a file begins with a sequence like this #!/usr/bin/env python the system know that the script is a python script, and will launch the file using the python interpreter. You can do a similar thing with node. For Go and Rust, this is of course optional, a compiled binary can be used instead, but there are also things like go run and cargo-script that do similar things.

    The idea was that the entry point of the project would be any file with the name that matches the regex ^Daggerfile(\..+)?$ in the root of the repo


    At the other extreme (and more reasonable) is some finer grain controls (I.e. we can reuse layers that run 'dnf install' within a calendar day unless there a specific manual override, because the user told use we could) around buildkit cache invalidation. This also is useful, but doesn't require deep knowledge of the build systems of say C++ which could be a nightmare.

    I'm sure I understand this part. Could you give examples of what you mean?

    Here is an issue that happens with Docker some times. Suppose that you have a docker file like this:

    IMAGE fedora:35
    RUN dnf install -y boost-devel
    ADD ./myproject /build
    ...
    

    Now layers 1, 2, and 3 are built and the image gets created. Some time later, the code in ./myproject is changed. However what happened behind our backs is that boost-devel went from version X to version Y, and suppose that myproject no longer builds with version Y. However, only layer 3 is invalidated, and we build with the cached layer 2 which still has version X so we don't know that our build is now broken. Being able to say that layer 2 needs to expire say every week allows us to catch these failures without invalidating the entire docker cache with --no-cache which is a really blunt instrument, and invalidates more than we need.

    It would be cool if dagger gave us a middle ground.

    May I ask what are the most important events for you to handle?

    For me, I imagine the same things as most folks: PR is updated, new commit was added, user manually requested something be re-run, a "release" was tagged (via a new or changed git tag), and nightly builds.


    so in theory you could reimplement a Bazel-like tool on top of the Dagger engine. Possibly even more powerful, since unlike Bazel, Dagger supports adding nodes to the DAG dynamically, so tooling like "gazelle" would become redundant.

    Compiling C++ is complicated -- dependency relationships can be implicit and cannot fully be determined without a C++ parser, and involve multiple stages that need to be executed in parallel and distributed to multiple workers with effective caching painfully slow for large projects. Doing it without something like CMake, Meson, or Bazel would be a nightmare. I really don't want to re-invent that in Dagger.

    I do take your point that is is possible though


    Unless of course you find an acceptable way to run windows or macos in a Linux container :) Possibly using some of the recent bridges between containers and VMs; or perhaps projects such as Docker-OSX could help?

    worth thinking about. I'll give this more thought.


    and how to import platform things like secrets or cache things between CI jobs using GitLab or GitHub specific things (and sane replacements when run locally for development)

    We are working on both of these :)

    For secrets: may I ask which tools or services you use to store them, that Dagger would need to integrate with?
    For cache persistence: what do you currently use, and what are your requirements for any new solution?

    In both cases, I use what the platform (GitHub (personal), Jenkins, and GitLab (work)) provides for these. Each of these have a native API for both caching and secrets. I need the variety of platforms because I have to go with what each HPC platform supports. I should probably find a more portable solution, but I haven't yet. For secrets, I've used ansible-vault before and liked it, but I think all of these need something from the platform to bootstrap them, and I don't have that many secrets to keep. For caching, I have copied certain artifacts to remote storage using NFS or SCP, but this takes more effort and isn't worth it unless the thing to store is really large.

  9. robertu94 commented on Jan 21, 2023

    @robertu94

    Ah, I forgot one:

    #4301

    This is what I meant by cache types were added.

  10. changed the title [-]Project entrypoints[/-] [+]Project entrypoint[/+] on Jan 21, 2023
  11. shykes commented on Jan 21, 2023

    @shykes
    ContributorAuthor

    Here is an issue that happens with Docker some times. Suppose that you have a docker file like this:

    IMAGE fedora:35
    RUN dnf install -y boost-devel
    ADD ./myproject /build
    ...
    

    Now layers 1, 2, and 3 are built and the image gets created. Some time later, the code in ./myproject is changed. However what happened behind our backs is that boost-devel went from version X to version Y, and suppose that myproject no longer builds with version Y. However, only layer 3 is invalidated, and we build with the cached layer 2 which still has version X so we don't know that our build is now broken. Being able to say that layer 2 needs to expire say every week allows us to catch these failures without invalidating the entire docker cache with --no-cache which is a really blunt instrument, and invalidates more than we need.

    It would be cool if dagger gave us a middle ground.

    Ah, I understand! I believe this can be solved in powerful ways on top of the primitives already available in the Dagger API.

    • To invalidate cache at a given interval, you can use the "rounded cachebuster trick". Get the current time; round it down to the desired interval (in your case, say 00:00:00 on the monday of the current week); inject the resulting value as an environment variable or file mount of the desired container. And voila!

    • But why stop there? Since your cache invalidation is just regular code, you could simply have your pipeline check for the latest released version of the boost-devel package, and use that value as a cache buster. Or, if you trust the boost-devel developers to respect semver, round it down to the major version so that cache is only invalidated on major releases. You get the idea. You are now fully in control of your own caching strategy.

    This all works in Dagger today. I'm sure we could (and eventually will) add some polish, for example we could add a cacheKeys argument, to abstract away the injection of environment variables or files (we would probably do that anyway under the hood, but you wouldn't have to know 😛 ).

    Note: I find this topic very interesting, and hope I'm being helpful. But I don't understand how this relates to project entrypoints 😄

    May I ask what are the most important events for you to handle?

    For me, I imagine the same things as most folks: PR is updated, new commit was added, user manually requested something be re-run, a "release" was tagged (via a new or changed git tag), and nightly builds.

    How would you feel if Dagger limited itself to defining available pipelines (similar to how, say a Makefile limits itself to defining rules), and it would be the CI service's job to map events to pipelines?

    It's been fashionable lately for CI-specific configuration to leak into the contents of the git repository, but that doesn't necessarily mean it's a good design. It always felt like a weird abstraction leak to me.

    so in theory you could reimplement a Bazel-like tool on top of the Dagger engine. Possibly even more powerful, since unlike Bazel, Dagger supports adding nodes to the DAG dynamically, so tooling like "gazelle" would become redundant.

    Compiling C++ is complicated -- dependency relationships can be implicit and cannot fully be determined without a C++ parser, and involve multiple stages that need to be executed in parallel and distributed to multiple workers with effective caching painfully slow for large projects. Doing it without something like CMake, Meson, or Bazel would be a nightmare. I really don't want to re-invent that in Dagger.

    I do take your point that is is possible though

    I am fully aware of the domain-specific complexity of a good C++ builder, and I want to reassure you that we have no intention of re-inventing that wheel in Dagger 😄 That said, I believe Dagger provides a set of primitives that will in the future make it 10x easier to create a Bazel or Meson competitor. This could help fuel much-needed competition on developer experience and ergonomics. Right now the core execution engine is just too much engineering work to be worth it for most toolmakers.

    In both cases, I use what the platform (GitHub (personal), Jenkins, and GitLab (work)) provides for these. Each of these have a native API for both caching and secrets. I need the variety of platforms because I have to go with what each HPC platform supports. I should probably find a more portable solution, but I haven't yet. For secrets, I've used ansible-vault before and liked it, but I think all of these need something from the platform to bootstrap them, and I don't have that many secrets to keep. For caching, I have copied certain artifacts to remote storage using NFS or SCP, but this takes more effort and isn't worth it unless the thing to store is really large.

    Very useful, thanks.

    • For portability of secrets, here's the issue to keep an eye on: Dynamic secrets #4426
    • For caching: I believe Dagger makes CI-specific caching obsolete. When porting a pipeline to Dagger, you get superior caching by basically doing nothing (assuming Dagger itself has a way to persist its own cache). The very concept of explicitly managing the caching of your artifacts becomes redundant.
  12. robertu94 commented on Jan 21, 2023

    @robertu94

    Note: I find this topic [cache invalidation] very interesting, and hope I'm being helpful. But I don't understand how this relates to project entrypoints 😄

    Your solutions to the caching problem are inspiring! I brought cache invalidation up in response to this:

    Every CI/CD platform (except Dagger) can, given a directory and a change event, can determine which pipelines to run in response to the change (emphasis added)

    My point with the dnf example was that not all changes are observable from inside the repo and trackable via git 😞 , and may require invalidating part of the cache to detect. However, your solutions address this very cleanly.

    How would you feel if Dagger limited itself to defining available pipelines (similar to how, say a Makefile limits itself to defining rules), and it would be the CI service's job to map events to pipelines?

    That is certainly an approach, and one that I would respect. It is really important to limit scope creep, and do what you do best and leave the rest to others.

    However, I don't really like writing trigging code in YAML on each platform either 😏 : so part of me thinks something thin that encodes events for at least the common cases so I can handle them in a proper programming language is useful.

    For caching: I believe Dagger makes CI-specific caching obsolete. When porting a pipeline to Dagger, you get superior caching by basically doing nothing (assuming Dagger itself has a way to persist its own cache). The very concept of explicitly managing the caching of your artifacts becomes redundant.

    But for example in GitHub CI, don't I then need to cache the Dagger cache and reload it? I'm in total agreement that Dagger's cache is better, but I think it would be valuable to encode that saving and loading for the "platform" (i.e. gitlab, github, etc...) cache into a reuseable block to integrate with each platforms's native features.

  13. c-p-b commented on Jan 22, 2023

    @c-p-b

    @cpdeethree thanks for the details. Could you share an example of your ci.py? Do you use this pattern in more than one repository, and if so do you have duplication of code between your different ci.py files?

    Sure.
    Here's a simple workflow that calls "terraform" action multiple times to bootstrap a management project in GCP. This pattern passes terraform outputs between images for modules that depend on each other. For example, bootstrap module outputs a project id which is stored as JSON. That project ID is used as input for kms and artifactrepository

    from pathlib import Path
    import os
    import asyncclick as click
    import sys
    import anyio
    import dagger
    from images.infra_runner import infra_runner
    from actions import terraform, secrets
    
    from dotenv import load_dotenv, dotenv_values
    
    app_env = os.getenv("APP_ENV")
    env_filepath = f"environments/{app_env}-infra.env" if app_env else "environments/management-infra.env"
    
    load_dotenv(env_filepath)
    
    
    @click.command()
    @click.option('--apply', help='If specified, applies the terraform automatically. Off by default. If not specified, just run plan.', is_flag=True)
    async def run_workflow(apply):
        config = dagger.Config(log_output=sys.stderr, execute_timeout=3000)
        async with dagger.Connection(config) as client: 
    
            secrets_file = await secrets.decrypt(env_filepath, client) #TODO: MAKE MORE SECRETER
            runner_image_tag = os.getenv('INFRA_RUNNER_IMAGE_TAG')
            runner_image = infra_runner.build_image_from_tag(runner_image_tag, client)
            bootstrap_output = await terraform.run_module("bootstrap/gcp", runner_image, None, apply, env_filepath, secrets_file, client)
            # TODO: These two calls could easily be run in parallel
            await terraform.run_module("artifactrepository/gcp", runner_image, bootstrap_output, apply, env_filepath, secrets_file, client)
            await terraform.run_module("kms/gcp", runner_image, bootstrap_output, apply, env_filepath, secrets_file, client)
    
            
            print("All tasks have finished")
    
    if __name__ == "__main__":
        run_workflow(_anyio_backend="asyncio")

    Here's a complex workflow in a different repository that builds a nextjs app frontend, spins up a clean, fresh supabase instance with docker-compose, runs e2e tests against that instance, then optionally deploys it to cloud run

    import anyio
    from io import StringIO
    import os
    import subprocess
    import sys
    from dagger import Connection, Config, Socket
    from actions import supabase, cloudrun, secrets
    from images import maintainers
    from graphql import GraphQLError
    from pathlib import Path
    
    from dotenv import load_dotenv
    
    
    async def run_workflow():
        cfg = Config(log_output=sys.stderr, execute_timeout=None)
        app_env = os.getenv("APP_ENV")  # decide which env file to load
        deploy = os.getenv("DEPLOY_APP")  # decide whether to deploy the app
    
        env_filepath = f".env.{app_env}" if app_env else ".env"
    
        build_outputs = ""
        build_passed = True
    
        if os.getenv("CI"):
            subprocess.run(
                [
                    "docker",
                    "login",
                    "-u",
                    "_json_key",
                    "-p",
                    os.getenv("GCLOUD_GITHUB_ACTIONS_SERVICE_ACCOUNT_JSON"),
                    "https://us-west3-docker.pkg.dev",
                ]
            )
    
        async with Connection(cfg) as client:
            # only decrypt if running an actual app env.
            # if local, just use .env and .env.local
            print(f"using env file {env_filepath} for dagger pipeline")
            load_dotenv(env_filepath)
            secrets_file = client.file(f"{env_filepath}.local")
            if app_env:
                secrets_file = await secrets.decrypt(env_filepath, client)
                secrets_contents = await secrets_file.contents()
                load_dotenv(stream=StringIO(secrets_contents))
            else:
                load_dotenv(f"{env_filepath}.local")
    
            short_hash = (
                subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])
                .decode("ascii")
                .strip()
            )
            image_tag = os.getenv("GCLOUD_ARTIFACT_REGISTRY_TAG") + f":{short_hash}"
    
            proc = subprocess.run(
                ["docker", "manifest", "inspect", image_tag], stdout=subprocess.DEVNULL
            )
    
            if proc.returncode == 0:
                print(f"Skipping build task since image {short_hash} already exists.")
            else:
                docker_host: Socket = client.host().unix_socket("/var/run/docker.sock")
                local_src = client.host().directory(str(Path(os.getcwd())))
                host_volumes_path = "/tmp/supabase/docker"
                try:
                    await supabase.create_volumes(docker_host, host_volumes_path, client)
                    await supabase.docker_compose(
                        "up", docker_host, host_volumes_path, client
                    )
                    build_outputs = await maintainers.build(
                        local_src, env_filepath, secrets_file, client
                    )
    
                except Exception as e:
                    print(e)
                    build_passed = False
                finally:
                    await supabase.docker_compose(
                        "down", docker_host, host_volumes_path, client
                    )
                    subprocess.run(["rm", "-rf", "/tmp/supabase"])
            if build_passed and deploy:
                await maintainers.publish(build_outputs, image_tag, client)
                await cloudrun.deploy(
                    os.getenv("CLOUDRUN_PROJECT_ID"),
                    os.getenv("CLOUDRUN_APP_NAME"),
                    image_tag,
                    client,
                )
    
    
    if __name__ == "__main__":
        try:
            anyio.run(run_workflow)
        except GraphQLError as e:
            print(e.message, file=sys.stderr)
            sys.exit(1)

    No duplication of code between ci.py files.It's intended to be analogous to a github workflow yml. In both cases "actions" can be part of some shared repository (or in a single repository and shared between workflows, I have other terraform workflows that use the same "terraform.py" action and "images" has application/infra specific stuff. Actions can also call other actions that just serve as utility functions. For example I have "credentials.py" that is called only by actions and serves to load GCP/AWS credentials if other actions need those to authenticate:

    from pathlib import Path
    import os
    import anyio
    
    
    async def get_gcloud_creds_file(
        client, creds_path="/.config/gcloud/application_default_credentials.json"
    ):
        # first look for gcloud local creds on the host machine
        # if those aren't present try to load a service account key from env
        local_creds_path = str(Path.home()) + creds_path
        creds_folder = local_creds_path.rsplit("/", 1)[0]
        os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = local_creds_path
        if not os.path.exists(local_creds_path):
            Path(creds_folder).mkdir(exist_ok=True)
            with open(local_creds_path, "w") as json_file:
                json_file.write(os.getenv("GCLOUD_GITHUB_ACTIONS_SERVICE_ACCOUNT_JSON"))
    
        local_creds_file = (
            client.host()
            .directory(local_creds_path.rsplit("/", 1)[0])
            .file("application_default_credentials.json")
        )
    
        return local_creds_file
    
    
    if __name__ == "__main__":
        anyio.run(get_gcloud_creds_file)

    By specific design, we instantiate the dagger client in the ci.py, so we purposefully don't allow ci.py files to call each other (multiple dagger clients). All "actions" and "images" functions have to take the dagger client as an argument.

    This is in contrast to the github actions workflow design, where workflows can call other workflows. I've found in my org that makes heavy, heavy use of github actions right now that allowing workflows to call each other confuses people on whether they should be making "actions" or "workflows" when they want to do something reusable. In this approach, you HAVE to use actions if you want to make something reusable so that it's clear what the role of /actions, /images and workflow defintions are.

    So the three distinct roles that I have in this setup is

    • ci.py (top level python file in .pipelines folder): workflow orchestration and environments setup
    • actions/*.py (reusable code)
    • images/*.py (application specific declaration of input/output artifacts)

    Currently my github actions ci.yml that is the entrypoint works exactly like you guys do in github.com/dagger/dagger. I just load environment variables, install python, install poetry dependencies, and then

    poetry run python .pipelines/ci.py

  14. shykes commented on Jan 25, 2023

    @shykes
    ContributorAuthor

    What makes this problem really hard to solve IMO is that the entrypoint to running those pipelines is not actually Dagger.

    Dagger provides the mid-level SDKs (on top of the low-level GraphQL layer) and people end up building their own entrypoints and pipelines based on those.

    (Yes, pipelines as well (ie. Dagger is oblivious to running multiple containers in a sequence, it doesn't recognize the pipeline as a higher level construct).)

    That's both powerful and limits Dagger's capability to understand how pipelines are built.

    One crazy idea I had before is asking people to implement a "dummy mode" in their pipelines that allows injecting a noop Client into all call paths discovering the potential different pipelines and the sequence of container executions within.

    I like this idea :) Now that we have Pipeline(), there is actually a way for Dagger to "understand how pipelines are built".

    cc @vito @sipsma @aluzzardi

  15. controlpl4n3 commented on Jan 25, 2023

    @controlpl4n3

    So much good stuff here, it seems a waste to keep it buried in a GitHub thread

  16. 8 remaining items

  17. marcosnils commented on Feb 6, 2023

    @marcosnils
    Contributor

    Note that at this time we are not recommending any one best practice.

    Is it there a best practice in general? I mean.. I could argue that the same thing happens from Makefiles. Even though they have been used for ages, I'm not sure if you'll find a consensus on what's a "best practice" to use them.

    The way I think about it, generally "best practices" arise from either:

    • Common "natural" wide-spread usage and patterns
    • A specific approach to mitigate / minimize some trade-offs.

    Even though we do have some "best practices" in regards to some aspects of Dagger pipelines like excludes, caching, parallelization... etc, regarding entrypoints, I'm not aware about a specific pattern or recommendation emerging. Probably that's mostly the reason why the quickstart entrypoint didn't raise a particular warning to me.

    Having said that, it'd be great to have a "good practice" around this. How can we help @shykes to move this forward?

  18. c-p-b commented on Feb 7, 2023

    @c-p-b

    To @marcosnils point, I think a somewhat opinionated approach is going to be necessary here, since there really isn't one single best way. My personal design thoughts were informed by the major pain points I see managing the GHA pipelines for a 75-ish member engineering org, namely:

    • No clear "right answer" on how to do things. It's hard with Github Actions to know the correct component of abstraction for what you are trying to do. What is a "Pipeline" (Workflow in Github Actions parlance)?. Is it a group of DAG nodes? What is a "DAG Node?" is it a container? Is it simply something you designate? What is the "DAG Edge?"? Ideally these things should be pretty clear and not leave the end user guessing as to what to do or implementing their own interfaces
    • YAML syntax being really limiting when you need to do fancy stuff. Notably we hit a lot of limitations and weird behavior with conditionals for jobs with YAML syntax. Here is one example
    • Really hard to get a good idea of what is running where when you have 10+ different workflow files and no one easy way to tie them all together and understand what is going on. Check out all of the workflows that we run at Airbyte. The events and triggers that drive all of these, and subsequently which folders that trigger them, are spread out over tens of different files. It makes it REALLY hard to fully answer the question "if I change this random file in the repository, what all is going to run?"

    I see two kind of major themes that have surfaced from the thread - one can take either a more rigid declarative approach like existing CI systems use that uses YAML or JSON to define workflows or one could lean fully into the pipelines-as-code approach and delegate that work to code but with some existing patterns, API's and best practices to hold the developer's hand and give them the building blocks and tools necessary to do things the "right" way.

    • If we are letting the code itself dictate the structure of the pipeline (e.g. run the dagger code as a no-op and construct the DAG dynamically for visualization purposes) then it feels appropriate to designate a single entrypoint for the repository and define all workflows that make up the DAG with code from that one single entrypoint. Then the code itself can decide what the workflow consists of and whether it gets run. When doing this we could retain opinionated structure by using and extending the existing Pipeline API (or creating a new API) to do stuff like:
    1. "spawn a new runner to execute things in" or
    2. "Declare pipeline steps and dependencies" (rather than having them inferred via Buildkit, could even use this to discover discrepancies between what the developer intended and what Buildkit actually did)
    3. Run this pipeline only if these requirements are satisfied (file changed according to some glob pattern, subscription to some event trigger like opening a pull request or pushing to main)

    This gives a lot of freedom at the expense of less structure than the yaml/json/whatever approach. It would still be less freedom than what end users have currently, and also pave the way for an abstraction over common tasks existing runners like Gitlab or Jenkins or Github Actions - you could have the API abstract away, for instance, spawning a runner with a Pipeline.spawn_runner() function that would call the appropriate method depending whether you are running it in GHA or Gitlab or Jenkins. End users get an opinionated way to do things using Dagger API, but also an escape hatch to do whatever they want if they need to. The "carrot" approach is that end users prefer using the Dagger API to do stuff like that because it's simply easier and works and is portable across pipelines and there's some sweet visualization that shows exactly what is happening.

    • If we are doing something more declarative, say, JSON/YAML/whatever, we have to handle all of the complications that Github Actions, Gitlab CI, Circle CI etc. already handle - we would just be wrapping them in a custom syntax that is purportedly pipeline agnostic. To me that doesn't seem like as much of an improvement over the status quo - though it does enforce a more rigid and opinionated way to do things. If we really wanted to be declarative in the traditional sense I would go back to my original suggestion of an annotated DAG - that's essentially what you really are making anyway with systems like Github Actions, it's just not clear at all that's what you are doing when you just declare a bunch of yaml and throw it into a black box and the output doesn't show you the complete picture.

    Of course, if the visualization tools are powerful enough, it doesn't really matter whether the entrypoint is single file or allowed to be spread out over multiple files - but you need the tooling to be there to do that. Which is one of my main gripes with GHA: the tooling to visualize all this behavior is just not great. Plus, if you went single entrypoint file vs multiple, there's always the escape hatch that you could later go to using multiple entrypoints if you really needed to. No such escape hatch to go the other direction.

    All in all, my preference is really to lean towards "Give developers the right API to construct this DAG behavior dynamically and the right tools to visualize what exactly they are doing" rather than the more-limiting "Let's have some static files that dictate some of this behavior and hope that we don't fall into some of the same pitfalls other ci systems before us have done".

  19. marcosnils commented on Feb 7, 2023

    @marcosnils
    Contributor

    All in all, my preference is really to lean towards "Give developers the right API to construct this DAG behavior dynamically and the right tools to visualize what exactly they are doing" rather than the more-limiting "Let's have some static files that dictate some of this behavior and hope that we don't fall into some of the same pitfalls other ci systems before us have done".

    💯 you've synthesized my thoughts in a detailed and well structured response. My feelings navigate towards this approach as well.

  20. robertu94 commented on Feb 15, 2023

    @robertu94

    Several of the posts here have mentioned Makefiles which I think are an apt comparison here. I think it may be useful to think about exactly what Makefiles and the make frontend provide to the user both humans and machines.

    What does Make provide?

    • They provide a default entry point: by default the $PWD/Makefile is the main entry point. Depending on your implementation of Make (e.g. BSD or GNU), there may be other variants like $PWD/GNUMakefile that are tried first but the order these is considered is documented. You can also override this with -f
    • There is a default target, but Make isn't picky about what that does. In Make the first defined target is the default. By convention established by autotools and cemented by CMake (meta build system tools that produce makefiles to enable easier to abstract away differences between compilers and operating systems) this target builds everything required to build all targets 1.
    • Make allows the definition of other arbitrary entry-points with arbitrary names. By convention check (autotools) or test (cmake and meson) are used to run tests cases. clean cleans the caches and artifacts built by the pipelines. install installs the targets. Autotools defines a few other targets related to packaging (e.g. RPMs and DEBs), but these aren't standardized by the successor tools.
    • They provide primitive timestamp based caching and dependency ordering. A target is considered up to date and will not be rebuilt if all of the dependencies are up to date unless one of these dependencies is declared as "PHONY" in which case it is always rebulit. People have implemented arbitary caching strategies on top of this with a combination of PHONY rules that always run to check the status of the cache, and touch files to force it to be cleared. People often also augment this cache with tools specific to languages by setting CC or CXX to ccache for even better caching based on semantic contents.
    • The provide a standard mechanism to dump all caches with -B They also provide a mechanism to assume that a cache has not expired with -o even if it has.
    • They provide a choice between "best-effort" and "fail-fast" building of tasks with -k
    • There are 3rd party tools provide visualize DAGs of tasks and make provide sufficient information to produce them. It's worth noting that ninja which in many ways is a successor to Make provides this functionality built-in.
    • They provide a mechanism to explain why a task was re-run with --trace. The version of this for ninja shows this as JSON which makes it much easier for 3rd party tools to integrate with. I'm guessing it would have used protobuf if it was bulit today.
    • They provide a dry run mode with -n
    • They provide mechanisms to control the level of parallelism with -j (max limit of concurrent tasks) and --load-average (max CPU usage since some tasks may take multiple CPU cores).

    So what IMHO can dagger learn from Make?

    • Makefile in the $PWD having a consistent name and location gives developers a default place to look. Since dagger supports multiple frontend languages, I think multiple filenames are ok as long as they are consistently named. I'm also Ok with it being in a subdirectory. If multiple of these files (e.g. Python and Go) exist we need to either 1) document which one is preferred by dagger or 2) provide an error if multiple of these files exist requiring the user to specify which one they prefer either with an environmental variable or a CLI flag.
    • the make command with no arguments does a reasonable thing of building all targets giving machines a reasonable default. There are a few other standard targets people have come to expect and are generated by default by 3rd party tools such as CMake and Autotools and consumed by various IDEs. There is also a standard way for building named targets to make it easy for a machine to call them without requiring text box/file with a bunch of flags. Dagger should have something analogous to "build everything" and clean targets. It may make sense for the default for dagger to be test (which pulls in "build everything" by dependency).
    • the frontend provides ways to override execution behavior for errors (-k) , to override caching (-B and -o), parallelism (-l and -j) and to print/visualize the task graph (-n and --trace). Dagger should provide similar flags because these are orthogonal to the main goal of the developer of defining their pipeline, but super useful in practice and can be done programmatically from the pipeline definition.
    • Successors to make provide task information in both human and machine readable formats to allow these to be populated into menus in tools/autocomplete on the CLI.

    Footnotes

    1. you can exclude things from everything in Autotools and CMake, but this has to be done explicitly. The default is all tasks related to building the program or library get built. Meson also follows this pattern but with ninja files. ↩

  21. marcosnils commented on Feb 15, 2023

    @marcosnils
    Contributor

    Nice analysis @robertu94! I guess the questions that come to my mind are:

    • can we do better than makefiles? there's still some struggle in some ecosystems (like full stack apps) where devs try to escape makefiles as much as possible and encode these entrypoints in their language runner (i.e: npm/yarn)
    • what can we learn from Makefiles limitations / drawbacks and try to overcome them in Dagger?
  22. robertu94 commented on Feb 16, 2023

    @robertu94

    @marcosnils to answer your questions:

    can we do better than makefiles?

    For many complex things yes. There have been decades of tools that fulfill parts of make's functionality as I explain in the next section. However, for truly simple things (i.e. compiling a single file C project with few if any dependencies) its really hard to beat make for C or C++. I primarily use CMake for C++, but still have a folder full of code samples with Makefiles instead of Cmake because they are stupidly simple and Cmake would be overkill. A lot of them look like this

    CXXFLAGS+=-std=c++17
    example:
    test: example
        ./example

    And with this I can build with gcc or clang, change my optimization levels or compiler flags and run tests even from vi even without the niceties of vim or neovim. The ubiquity and simplicity of make in the simple cases Dagger as much as I love it won't beat a purpose built tool used for its intended purpose.

    what can we learn from Makefiles limitations / drawbacks and try to overcome them in Dagger?

    I think this question is best understood thought what came after Makefiles and the gaps that they leave.

    • autotools was the first. The primary issue that it solved was portability and conditionality. Make uses it's own bespoke language to describe the relationships between sources and targets which made it difficult to hand differences like where the a particular system header or library was installed. It solved this by allowing users to write logic to generate Makefiles in languages like m4, bourne shell, or perl.
    • cmake was next. The primary challenges that it solved over autotools were workflow simplicity and configure time speeds. Autotools isn't just one command but several (I think more than 7 or 8). Understanding the whole ecosystem is somewhat complicated which made fixing issues with it complex. cmake addressed this by simplifying the model down to 2 commands cmake and your build system (make on Unix-like systems). Secondly, Autotools configure steps can really take forever because they aggressively utilize the filesystem. cmake addressed that by making smarter use of the filesystem in common cases.
    • In the meantime, there are also tools like mage and rake which try to be more minimal and in the spirit of make, but with improved syntax and language semantics with go and ruby respectively which is nice if you know those languages, but you are unlikely to use if you don't.
    • ninja came after that. The problem that it solves is better parallelism. Because of features like recursive make files and embedded programming features added as non-standard extensions on top of POSIX make, it can be hard to parallelize the parsing and execution of make files. Ninja solves this problem by using a much simpler programming model which is easier to schedule, but leaves the complexity of writing the files themselves to a higher level tool like cmake or `meson. However, even with these tools digging though multiple processes logs or tons of small log files makes debugging parallel builds a pain.
    • meson followed ninja and cmake and tries to provide both dependency management and a more proper programming language than cmake's string-ly typed programming language. I would argue that they didn't solve dependency management for C++, but they did spur cmake and other tools to make massive strides in fixing the problem. It also uses a non-turing complete python-esque language with proper types and type semantics and a more interpretable set of scope rules. It provides also easy mechanisms for common tasks used in modern C++ tooling.
    • bazel but I also could have said buck or pants. The problem that they really try to solve are build isolation and distributed builds. Some might say multi-language, but autotools and cmake had that decades ago. Build isolation technically existed before with Dockerfiles, and tools like Gentoo's sandbox, but bazel was the first that "made it easy" and could still handle complex builds with maximal parallelism. Distributed builds also technically existed with things like distcc or icecream, but since these weren't also hermetic, it was and is a pain to use. Where bazel falls short in my mind is that they don't have a good solution to the dependency problem (it is getting better with bzlmod) since Google didn't need to solve this problem internally because they use a mono-repo (for good reasons, just not ones that everyone lives with). However, other projects like cmake (after prodding from meson), spack can solve this problem better.

    Three other classes of tools which don't fit neatly into the history above.

    There is a enormous list of language specific tools like setuptools/pep517, maven, gradle, cargo, fpm, cabal, npm, and go which are really language specific workflow tools and sometimes decent dependency managers. Their primary goal it simplify the common workflows for their specific language. If they support using another language, it is because you used some escape hatch to call a series of shell commands. IMHO, you are unlikely to be a better python workflow tool than poetry. Your aren't going to supplant cargo in rust. They in my mind solve a different problem.

    There are also dozens of bespoke "workflow" tools tailored for specific applications (e.g. Genomics) or computing environments (e.g. AWS SWF) or distributed programming paradigms like parsec and legion which have specific applications in mind that they are optimizing aggressively for. You probably won't replace these either for the same reason.

    Lastly, There are also cross-language dependency managers which moonlight as build systems such as Gentoo's portage user level-only versions like nix and spack. These are interesting in the since that they make it somewhat easy to create a reproducible environment from source and then in some cases compile it in parallel on a super computer or cluster of servers. Tools like poudriere for FreeBSD and koji for Fedora also moonlight in this space and manage the building of packages for these distributions. These tools generally produce a fixed set of artifacts but may not handle more complex workflows.

    Given this landscape, here is where I think dagger can make a difference to go beyond the tools that exist overcome limitations:

    • Anything involving distributed with long running services supporting a pipeline is a pain -- i.e. we need to launch 1 or more postgres server to run while a set of commands run potentially on separate nodes and then tear them down where appropriate.
    • Providing isolation, caching, and parallelization as a service to language specific tools through additional SDKs which don't currently use them because the tools for doing these tasks well aren't easily available in their language (i.e. most of the higher-level container ecosystem libraries are written in Go). I think the bias to "i want to use a language I know" drives the shoehorning of things into npm and other places they don't belong.
    • Providing fine grained resource controls for builds -- because things are running in containers we can finely control how much memory and CPU are used so a build won't for example take 99% of the available memory and disk throughput while the user is doing something else. Yes, this could be done with systemd-run, but not as easily at a per task level.
    • provide a seamless it runs on my laptop to it scales on CI experience with things like using the appropriate caching mechanisms.
    • First in class logging, debugging, and observability tools for parallel tasks as they run. The logging and playback demo from the community call that I saw recently was miles ahead of any other tool that I've seen. Making it easy for the user to inspect state of the sandbox at the time of failure and get both time correlated logs as well as task segregated logs would go a long way of being able to figure out failures after the fact. Something like core file for compiled languages, but for your CI which may consist of multiple processes.
  23. sipsma commented on May 1, 2023

    @sipsma
    Contributor

    For those following this issue, there is an early POC of support for entrypoints here: #5060

    All the feedback in this issue is extremely helpful. That first draft of the POC is more focused on just getting something to work, but I'll be referencing all the suggestions here as I keep iterating. Please feel free to continue discussing high-level topics here or leave any feedback specific to the POC on that PR.

  24. sipsma commented on May 17, 2023

    @sipsma
    Contributor

    To update, #5060 has been merged, but it's just a first step. I've created public github issues for a few of the follow ups that I think are most likely to get commented on by the community:

    1. project commands: close on whether we should support "default" commands #5146
    2. project commands: close on using spaces or colons for separators in dagger do #5145
    3. Finish project API #5144

    The rest of the follow-up TODOs in that PR are in our internal issue tracker, but I am more than happy to get any input from the community on them and discuss in a public issue in Github. Just let me know here, or feel free to leave any other feedback/ideas on this issue as we keep iterating.

  25. shykes commented on Mar 26, 2024

    @shykes
    ContributorAuthor

    Hello everyone. As many of you know, this has finally been implemented in Dagger 0.10, with Dagger Functions.

    Thank you all for your patience and feedback. There is still much left to do!

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions