Skip to content

Modularize CI - #6843

Merged
jedevc merged 52 commits into
dagger:mainfrom
jedevc:dagger-ci
Apr 8, 2024
Merged

jedevc merged 52 commits into
dagger:mainfrom
jedevc:dagger-ci

Conversation

@jedevc

@jedevc jedevc commented Mar 6, 2024 •

Copy link
Copy Markdown
Contributor

This PR introduces a fully-operational ci/ directory, replacing the old non-functional one.

This new CI allows for all of the following:

  • Running our tests
  • Utilities like linting, code-gen, bumping
  • Building the engine/cli/sdks

Warning

This isn't fully ready yet, but opening a work-in-progress PR to make it easier to track.

The aim isn't to get everything perfect on a first-pass, but to do a lift-and-shift of the existing internal/mage CI into dagger functions. Then we can follow-up with improvements.

A few things I've realized while doing this that I think are technically out-of-scope for this particular piece of work, but we should make sure to tackle:

  • Syncing the source directory is slooow - running commands over-and-over takes a lot of time, and it feels it (we need Need equiv of include / exclude for directories with dagger call CLI #6155)
  • Working with multi-platform images with functions feels very manual (see platformVariants is unwieldy in modules #6675)
  • I keep finding myself doing --source=. ... export --path=. to generate code. I get the technical reasons for this, but the verbosity of this makes me want to reach for a wrapper, which I know we're looking to avoid.
  • I keep wanting a nice way to load an image into the docker engine, without needing to do the intermediate export/import. This one is tricky, since it would be a CLI-facing change, instead of an engine side change - it would also need to integrate into various other compute drivers (e.g. podman) Compute Drivers #5583.
  • The build changes from core: speed up loading of builtin SDKs #6714 create a Sync in the middle of the chain, meaning that large parts are done in serial - this slows the build down, but struggling to work out how we can make those operations parallel again (cc @sipsma)
    • This was present before, but with the new TUI, it's much easier to visualize what's actually happening at each point, so it's easy to see that the chain gets broken.
  • Some operations just seem... slow. I can't quite put a finger on what this is, but even when there are no real changes, it seems to take much longer than it should to get a cached result.
    • Again, I don't think this is introduced by this change, but the TUI shows that there's lots of bottlenecks at different points - it would be interesting to try and track where we're spending all this time just to serve a purely cached result.

TODO:

  • Port engine+cli building and tests to new modules structure
    • GPU images need some additional work here
  • Port the SDKs
    • Port the Go SDK
    • Port Java/PHP/Elixir/Rust SDKs
    • Port Python/Typscript SDKs
    • Port Python/Typscript SDKs (using dev modules)
  • Port publishing
    • Port engine publishing
    • Port cli publishing
  • Port docs
  • Remove the old mage targets, and alias them to the new functions
  • Run all the CI in github actions, and fix inevitable breakages 😆

@wingyplus

Copy link
Copy Markdown
Contributor

I can help port or testing elixir part if you want. :)

@helderco

helderco commented Mar 6, 2024

Copy link
Copy Markdown
Contributor

Don't port the Python and TS SDKs. Me and @TomChv will handle that as we have dev modules in these SDKs that were intended to be installed in the ci module so the mage code is outdated.

@jedevc

jedevc commented Mar 7, 2024

Copy link
Copy Markdown
Contributor Author

Don't port the Python and TS SDKs

SGTM - I'll just put in some stubs for now for where I think they should fit in to everything (though of course, we can change that later).

@jedevc

jedevc commented Mar 7, 2024 •

Copy link
Copy Markdown
Contributor Author

I can help port or testing elixir part if you want. :)

Feel free @wingyplus - I've done the Go + Rust + Most of the PHP one now 🎉 Feel free to either push a commit to this branch (if you have permissions), post a commit link here (I'll pull it in), or open a PR against this branch in my fork 😄

I've now ported all the SDKs except for Python/Typescript - feel free to test the elixir SDK though! I've noticed dry-run doesn't quite work with elixir for whatever reason 🤔

but we should make sure to tackle

Another few for my list:

  • It's really hard to structure code in a reasonable way - I keep having to try and balance getting the Go SDK to do what I want it to, and doing what's best Go practice.
    • As a concrete example, I'd really like to have a sub-package of sdks/{go,typescript,python,...}.go, and then expose these types. However, I can't do this - because of the requirement that we generate code in each package with exposed types. Maybe we should just bite the bullet and code-gen in every sub-package that contains exposed types, and just go for it (and accept that *.gen.go files end up everywhere).
  • I've started wanting dynamic creation and attachment of typedefs 😆 Again, think of the SDKs - today I have to declare an intermediate struct and do some weird config passing to get to initialize it. But ideally, I could just have Dagger.SDK declared as a map[string]DaggerObject or something, and then the Go SDK / engine should be able to treat this as exactly the same.

@wingyplus

Copy link
Copy Markdown
Contributor

I've now ported all the SDKs except for Python/Typescript - feel free to test the elixir SDK though! I've noticed dry-run doesn't quite work with elixir for whatever reason 🤔

Hmm, I am looking at it.

@wingyplus

Copy link
Copy Markdown
Contributor

@jedevc Just push a fix on --dry-run option to your branch at 498118f.

Screenshot 2567-03-08 at 23 49 21

Test with the following command:

env HEX_API_KEY=abcd ./hack/with-dev dagger call --progress=plain --source=. sdk elixir publish --hex-apikey env:HEX_API_KEY --tag 0.1.0

@wingyplus

Copy link
Copy Markdown
Contributor

By the way, I tried sdk elixir test and got the following error:

✦ ❯ ./hack/with-dev dagger call --source=. sdk elixir test
✘ DaggerElixirSdk.test: Void 28.2s
  ✘ exec /runtime 28.2s
  ┃ input: container.from.withWorkdir.withDirectory.withExec.withExec.withExec.withServiceBinding.withEnvVariable.withMountedFile.withEnvVariable.withExec.withExec.sync sta
  ┃ jkl1jj1alh0c (aliased as dagger-engine): exited: exit code: 125
  ┃ output: fork/exec /usr/local/bin/dagger-entrypoint.sh: exec format error
  ┃
  ┃
  ✘ Container.sync: ContainerID! 2.1s
    ✘ start dagger-entrypoint.sh 2.1s
    ┃ fork/exec /usr/local/bin/dagger-entrypoint.sh: exec format error
      ∅ check jjkl1jj1alh0c.ok6tisd2csl2k.dagger.local 1234/tcp 0.4s
      ┃ polling for port jjkl1jj1alh0c.ok6tisd2csl2k.dagger.local:1234
      ┃ port not ready: dial tcp 10.87.0.22:1234: connect: connection refused; elapsed: 1.628508ms
      ┃ port not ready: dial tcp 10.87.0.22:1234: connect: connection refused; elapsed: 96.4224ms
      ┃ port not ready: dial tcp: lookup jjkl1jj1alh0c.ok6tisd2csl2k.dagger.local on 10.87.0.1:53: no such host; elapsed: 266.201958ms
  ● Container.sync: ContainerID! 2.2s

Error: response from query: input: dagger.sdk.elixir.test call function "Test": process "/runtime" did not complete successfully: exit code: 2

Stdout:
input: container.from.withWorkdir.withDirectory.withExec.withExec.withExec.withServiceBinding.withEnvVariable.withMountedFile.withEnvVariable.withExec.withExec.sync start jjkl1jj1alh0c (aliased as dagger-engine): exited: exit code: 125
output: fork/exec /usr/local/bin/dagger-entrypoint.sh: exec format error

My machine runs docker under lima (limactl) on Macbook Pro M1.

@wingyplus

wingyplus commented Mar 26, 2024 •

Copy link
Copy Markdown
Contributor

@jedevc I just merge #6559 and have a changes in generate code. I can help working on it after rebase this branch. :)

jedevc added 13 commits March 26, 2024 17:06
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>

add the rest of the test things

Signed-off-by: Justin Chadwell <[email protected]>

do a bit more

Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>

@sipsma sipsma left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks great, so glad we're finally doing this. Left comments but can all be done in follow ups if preferred.

There's obviously a ton more cleanups and improvements to iterate on here but 100% agree that starting here is the right place even if we can't rm -rf mage entirely quite yet.

with:
go-version: "1.21"
cache-dependency-path: "internal/mage/go.sum"
- name: Install dagger

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is tricky - because we're doing ./hack/dev to the nested engine, it's not super trivial.

I'll have a think about this, and try and do a follow-up, but this also is entertwined with removing mage in general.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this is going away in the CI setup.

Once we declare the Dagger version that we want - e.g. dagger-v0-10-3 - the runner is provisioned with all the necessary tooling, including the Dagger CLI. The code is available in this private repository: https://github.com/dagger/dagger.io/blob/3d37ad6abaf31634aa941796ea4fe8a107e68bcd/infra/ci/eks-2023-12-15/argocd/dagger-runners/dagger-gh-runners.yaml#L164-L202

We are integrating this in #7018, currently working through a few issues.

Comment thread ci/build/builder.go
// NOTE: wrapping the apk installs with this time based env ensures that the cache is invalidated
// once-per day. This is a very unfortunate workaround for the poor caching "apk add" as an exec
// gives us.
// Fortunately, better approaches are on the horizon w/ Zenith, for which there are already apk

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non blocker but I guess we can actually do this now :-)

Comment thread ci/test.go Outdated
Comment on lines +166 to +168
// TODO: re-enable this, to avoid rate-limiting
// introduced in https://github.com/dagger/dagger/commit/20241ba7a8d39da8f6ff185d512953b6b0ec1a55
// WithMountedDirectory("/root/.docker", util.HostDockerDir(dag)),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you know what, I think I remember now why this was a thing.

As mentioned in the discord thread, in theory the auth session attachable should handle this. But the problem is we are creating a nested exec and currently nested execs end up as their own completely isolated session, so they don't get that auth session attachable.

Fortunately, that will no longer be the case after #6916 lands. So I think we can just rm these comments; it's not possible to implement this now and the need to should disappear soon.

cc @vito since you were on that discord thread too, just in case you're curious

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh, I've had a realization as to why we had it like this 😆

https://github.com/dagger/dagger/actions/runs/8603708206/job/23576176153

Since we spin up nested engines (for things like code gen / sdk tests / etc), we need a way of passing our token through. We seem to have hit this pretty quickly, so we either need #6916 to land soon, or we need to chuck in this little hack again, which is sad.

Comment thread internal/mage/go.mod Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily a blocker, but while we still have mage involved, can we move this to a be subpackage of ci/ and share a go.mod with ci/? I've just been trying to think through all catch-22 scenarios that have bitten us way back when we first added the dagger-based CI for dagger and, while I haven't thought of any yet, the fact that there's now 3 modules involved gives me a headache 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this works! I've moved internal/mage into ci/mage, which I'm pretty happy with, and merged their go.mods together. Eventually, we can remove the old mage targest, but I'll keep them as a compat layer just for now.

Comment thread ci/go.mod

@sipsma sipsma Apr 4, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related to my comment on mage's go.mod, but I think we could actually share the go.mod of this ci module with the root go.mod up a parent directory (so just delete this one).

The reason we needed multiple go modules in the past was that we had to bootstrap mage on the previous dagger engine release via it's dep on the Go SDK, but afaict that's no longer gonna be a thing 🎉 Reason being that now the "previous stable engine" is entirely determined by the version of the CLI you use to call the ci module. This is awesome for general simplification and also specifically means we can simplify the step in our release process where we update mage's go.mod to the new engine (now it would just be a matter of updating the version of the dagger CLI in the GHA yamls).

Not a blocker though, can be in follow up if it's more complicated than I'm thinking right now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh, yes. So there's still one job I haven't converted yet, the helm.go job. I'll take a look at this one in a follow-up, but I guess after that it's probably possible?

One note - potentially this means that the build for the module is a bit larger? Not 100% sure, need to check this experimentally really.

Comment thread ci/README.md Resolved
Comment thread ci/README.md

Start a little dev shell with dagger-in-dagger:

$ dagger call --source=. dev

@gmile gmile Apr 5, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, would running this command result in entering a typical OS shell, or is this something much more specific to dagger, e.g. interactive dagger shell where you can run functions, etc.? 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This launches a shell into a linux container that's connected to the dagger engine so you can run little experiments, etc.

@jedevc jedevc added this to the v0.11.1 milestone Apr 5, 2024
Comment on lines -55 to -76
if: ${{ github.repository == 'dagger/dagger' }}
# Use our own Dagger runner when running in the dagger/dagger repo (including PRs)
runs-on: dagger-runner-2c-8g
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
cache-dependency-path: "internal/mage/go.sum"
- name: "Build Dev Engine"
run: |
./hack/dev
env:
_EXPERIMENTAL_DAGGER_RUNNER_HOST: "unix:///var/run/buildkit/buildkitd.sock"
DAGGER_CLOUD_TOKEN: "${{ secrets.DAGGER_CLOUD_TOKEN }}"
- name: "Scan Dev Engine for Vulnerabilities"
uses: aquasecurity/[email protected]
with:
input: ./bin/engine.tar
format: "json"
exit-code: "1"
severity: "CRITICAL,HIGH"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This job used to be different because we need to build a Dev Engine, but not run it. Good to see this refactored!

Comment thread ci/README.md

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads very nice! Great job @jedevc 💪

@jedevc
jedevc merged commit b583add into dagger:main Apr 8, 2024
@jedevc
jedevc deleted the dagger-ci branch April 8, 2024 10:01
@jedevc

jedevc commented Apr 8, 2024

Copy link
Copy Markdown
Contributor Author

Boom 🎉 Let's do the typescript / python dev module integrations in follow-ups.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants