Skip to content

Use one stable go sdk version to execute CI steps. - #4087

Merged
gerhard merged 1 commit into
dagger:mainfrom
sipsma:fix-catch22
Dec 5, 2022
Merged

gerhard merged 1 commit into
dagger:mainfrom
sipsma:fix-catch22

Conversation

@sipsma

@sipsma sipsma commented Dec 3, 2022 •

Copy link
Copy Markdown
Contributor

After trying many different approaches that all had very subtle flaws which eventually doomed them, I ended up with this majorly stripped down change from what I was originally going for. However, it is still a step in the right direction.

I realize everything involving the current state of our CI is confusing, so trying to over-explain it a bit here, hope it's helpful to keep everyone in sync.

Goals

  1. ✅ Fix catch 22 where backwards incompatible API change would result in our CI being unrunnable: Fix catch 22 in api back incompat changes in CI #4041
    • This fixes it by just using one stable Go SDK version as controlled in a go.mod in the magefile directory. We no longer switch back and forth between running the same mage code on different versions of the go sdk.
  2. ❌ Enable running of lint against SDK default engine target right before publish: Lint sdk code before publishing. #4065
    • This was so close to being possible+trivial as part of this change, but I hit a completely independent bug where our provisioning of the engine-session binary from docker seems to fail but only inside a dagger exec (described here: TestContainerWithUnixSocket fails when run directly on macos host #4073 (comment))
    • That bug meant we couldn't just allow provisioning to run inside the container in order to exercise the default codepaths there.
    • We would need to get the engine session binary that the SDK defaults to "out of band" and mount it in there. We do that for the dev engine-session bin, but that's easy cause we just build it from local code. Doing it for the image that the SDK we want to run against is much less straightforward than it would seem.
      • I spent time trying to do exactly that, but every attempt devolved into tons of complication and/or hacky changes to our non-test code, so I just abandoned it for now.
    • The actual solution here will be to switch provisioning to just download the CLI and use it as the engine-session bin, which we are planning on doing in the extremely near future anyways: Simplify and clarify how to open a GraphQL session #3830

Major Changes

  1. There's a stable go sdk version controlled in internal/mage/go.mod which is what we now use to run all the mage code on the host.
    • Dev code (aka code in the local git repo) now only ever executes inside of a Container Exec that has been setup with that stable go sdk.
  2. We don't use ExperimentalPrivlegedNesting at all anymore
    • I think we should still support this for users in the long run, but using it in our CI creates too many entanglements whose secondary and tertiary effects are confusing and lead to subtle flaws
    • For example, using that flag meant that in order to test against a dev engine, you had to exec the tests inside of that dev engine.
    • But that in turn meant that you needed to provision that dev engine using a dev SDK. Otherwise you could create catch 22s for backwards incompatible changes (both of internal and external interfaces)
    • But if you use a dev SDK to provision, you hit another catch 22 where you need to build the dev engine in the first place to give the dev SDK something guaranteed compatible to run against
    • etc. 😵‍💫
  3. We now just mount the docker socket into execs and let the same codepaths that run on the host also run inside the containers
    • So if you want to test against a dev engine, you still provision it as a docker container, the same as before, but now the SDKs inside dagger execs access it through that docker socket rather than the previous nesting approach.
    • Eventually this will also allow us to test full provisioning code paths inside dagger, but wasn't quite possible yet (see goal #2 above)
  4. I've removed ./hack/make-prod entirely for now
    • This is mostly because of the issue I mentioned in goal #2 above where it's just not yet possible to do this in any sane way due to a bug
    • However, I also realized that even before there was a subtle flaw in how it worked: it resulted in you testing against not the dev SDK's default engine dependency, it resulted you in testing the default engine dependency of the stable SDK specified in our go.mod
    • That extremely subtle difference leads to more catch 22s and mind melting
    • We can re-add it in the near future once we switch to provisioning the CLI via download, which avoids the current bug.
  5. ./hack/make doesn't call ./hack/dev anymore; they are just independent
    • This just became the obvious thing to do after the above changes, but is nice in that it's less confusing now.

Diagrams

Made modifications to the one worked on with @gerhard earlier:

Before

flowchart TD
    make(./hack/make sdk:go:test)
    dev(./hack/dev go run main.go sdk:go:test)

    dev -.- sdk -.- test

    StableGoSDK(Go SDK: dagger.io/dagger v0.4.1) ==> dev

    sdk(Go SDK) --> |mount| docker-container://test-dagger-engine 

    make --> dev ==> |provision ghcr.io/dagger/dagger:v0.3.6| docker-container://dagger-engine-sha256
    build --> tar(/tmp/dagger-engine-export)
    tar --> |load & run| docker-container://test-dagger-engine

    subgraph Docker
        subgraph docker-container://dagger-engine-sha256
            build
        end
        subgraph docker-container://test-dagger-engine
            subgraph buildkit-exec
                binary(DAGGER_HOST=bin:///.dagger_engine_session)
                socket(DAGGER_RUNNER_HOST=unix:///dagger-runner.sock)
                test(go test)
            end 
        end
    end
Loading

After

flowchart TD
    make(./hack/make sdk:go:test)
    make --> test

    StableGoSDK(Go SDK: dagger.io/dagger v0.4.2) ==> make

    make ==> |provision ghcr.io/dagger/dagger:v0.3.7| docker-container://dagger-engine-sha256
    build --> tar(/tmp/dagger-engine-export)
    tar --> |load & run| docker-container://test-dagger-engine
        sdk(Go SDK) --> |mount| docker-container://test-dagger-engine 


    dockersock(/var/run/docker.sock) --> |mount| buildkit-exec
    subgraph Docker
        subgraph docker-container://dagger-engine-sha256
            build
        end
        subgraph docker-container://test-dagger-engine
            subgraph buildkit-exec
                binary(DAGGER_HOST=bin:///.dagger_engine_session)
                socket(DAGGER_RUNNER_HOST=unix:///dagger-runner.sock)
                test(go test)
            end 
        end
    end
Loading

Follow-ups

The biggest follow up will be to implement the refined engine session interface: #3830

That will allow us to run the full default provisioning codepath in execs, which means we can address this issue (among others): #4065

At that time we can re-add something like the equivalent of ./hack/make-prod (but with a more clear name this time).

This fixes a catch22 where the fact that we switched between a stable
and dev version of the Go SDK could create impossible to solve
situations if we made a backwards incompatible API change.

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
sipsma requested review from aluzzardi and gerhard December 3, 2022 01:05

@gerhard gerhard 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.

Love the simpler approach, make-prod felt awkward since the beginning. I'm glad that we were able to clarify these interactions.

👍 🚀

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.

2 participants