Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI dogfood improvements #1984

Merged
merged 10 commits into from
Apr 5, 2022
Merged

CI dogfood improvements #1984

merged 10 commits into from
Apr 5, 2022

Conversation

aluzzardi
Copy link
Member

@aluzzardi aluzzardi commented Apr 1, 2022

DEPENDS ON #1983 and #1971

Improve CI configuration:

  • Use official Go package
  • Use golangci-lint package
  • Fix node_modules exclusion for local source
  • Improve CUE performance by optimizing cache hits

/cc @samalba @marcosnils

To make this happen, there's also some other universe changes:

  • universe: go: do not hardcode default platform
  • universe: go: improve cache management
  • client filesystem: remove .dagger from default exclusion
  • universe: go: add golangci-lint support

/cc @helderco @shykes

@aluzzardi aluzzardi requested review from helderco, shykes and a team as code owners April 1, 2022 02:24
@aluzzardi aluzzardi force-pushed the ci-improvement branch 6 times, most recently from 5e9f1cd to 2333709 Compare April 1, 2022 02:44
@aluzzardi
Copy link
Member Author

aluzzardi commented Apr 1, 2022

Dogfooding notes/wishlist @shykes @helderco @samalba:

  • I wish I could do dagger do build lint (a la Makefile)
  • I wish console outputs were available. It would have been a tremendous help to debug. Also very helpful to inform what just happened (e.g. dagger do build should print the revision we just built). I hacked around by writing a file and then removed that line before committing
  • I wish the platform defaulted to buildkitd's platform. The performance is horrible in any other setting. I know we had long discussions around the API for this, but it's so important my recommendation would be to default to buildkitd and provide a --platform flag (so we don't need to define the whole CUE DX before making this change)
  • It would be nice if dagger was GitHub-aware. I split build and lint into two different GH jobs because I want to see them separately in the status. However, that doesn't do any good with caching. Ideally the dagger GHA could report individual actions as "statuses" in the PR?
  • The docker.#Run / docker.#Build experience was a bit challenging: not sure when to use one or the other. On the one hand, I prefer usingdagger.#Build to define pipelines (e.g. do this, do that, XXX) -- much better than _doA: ... _doB: .... On the other hand, I can't do that as soon as I want to export files. I started writing docker.#Build steps then had to convert to manual operations (see actions.version)
  • Also, I'm using docker.#Build like a dagger.#Pipeline -- I'm not really building anything
  • Converting this line from our Makefile resulted in 40 lines of CUE: go build -ldflags '-s -w -X go.dagger.io/dagger/version.Revision=$(git rev-parse --short HEAD). Mostly because of the point above
  • Language Server: I spent my time jumping between upstream definitions to figure out the interface. I was able to do that because universe happens to be in the same repo as the CI config, anything else would have been a major PITA. Having auto-completion would have been a life saver.

@aluzzardi
Copy link
Member Author

On performance:

  • CI takes 47s to build dagger (make dagger), then dagger do build itself takes 1m19s to rebuild itself. Not sure why it's slower?

Screen Shot 2022-03-31 at 8 06 26 PM

  • Linting is worse. 1m19s vs 5m28s. No idea why either

@aluzzardi aluzzardi force-pushed the ci-improvement branch 3 times, most recently from aa526e7 to fbad661 Compare April 1, 2022 07:41
Copy link
Member

@TomChv TomChv left a comment

Choose a reason for hiding this comment

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

Nice improvement, I added a few comments and questions

.github/workflows/dagger-ci.yml Show resolved Hide resolved
.github/workflows/dagger-ci.yml Show resolved Hide resolved
.github/workflows/dagger-ci.yml Outdated Show resolved Hide resolved
ci/main.cue Outdated Show resolved Hide resolved
)

// Lint using golangci-lint
#Lint: {
Copy link
Member

Choose a reason for hiding this comment

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

golangci-lint can take a lot of flags to configure the lint. That would be useful to expose go.#Container instead of putting it in container key so the user can add fields to command.flags

Copy link
Member Author

Choose a reason for hiding this comment

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

We're already exposing go.#Container in container, not sure what you mean?

Copy link
Member

Choose a reason for hiding this comment

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

If someone want to customise flag, he will need to do

go.#Lint & {
    container: {
       flags: ...
    }
)

But if go.#Container isn't in container key, he'll just have to do

go.#Lint & {
       flags: ...
)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, agree with you. I followed the same convention as go.#Build though -- should we update that one?

Copy link
Member

Choose a reason for hiding this comment

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

The difference is that go.#Build produce an output that isn't an image but binaries so I didn't wanted to make users think they can use go.#Build as part of docker.#Build.

In you case, it's should be possible so I'm not sure we should update go.#Build ; just updating go.#Lint is enough IMO

pkg/universe.dagger.io/go/container.cue Show resolved Hide resolved
@shykes
Copy link
Contributor

shykes commented Apr 1, 2022

Dogfooding notes/wishlist @shykes @helderco @samalba:

  • I wish I could do dagger do build lint (a la Makefile)
  • I wish console outputs were available. It would have been a tremendous help to debug. Also very helpful to inform what just happened (e.g. dagger do build should print the revision we just built). I hacked around by writing a file and then removed that line before committing
  • I wish the platform defaulted to buildkitd's platform. The performance is horrible in any other setting. I know we had long discussions around the API for this, but it's so important my recommendation would be to default to buildkitd and provide a --platform flag (so we don't need to define the whole CUE DX before making this change)
  • It would be nice if dagger was GitHub-aware. I split build and lint into two different GH jobs because I want to see them separately in the status. However, that doesn't do any good with caching. Ideally the dagger GHA could report individual actions as "statuses" in the PR?
  • The docker.#Run / docker.#Build experience was a bit challenging: not sure when to use one or the other. On the one hand, I prefer usingdagger.#Build to define pipelines (e.g. do this, do that, XXX) -- much better than _doA: ... _doB: .... On the other hand, I can't do that as soon as I want to export files. I started writing docker.#Build steps then had to convert to manual operations (see actions.version)
  • Also, I'm using docker.#Build like a dagger.#Pipeline -- I'm not really building anything
  • Converting this line from our Makefile resulted in 40 lines of CUE: go build -ldflags '-s -w -X go.dagger.io/dagger/version.Revision=$(git rev-parse --short HEAD). Mostly because of the point above
  • Language Server: I spent my time jumping between upstream definitions to figure out the interface. I was able to do that because universe happens to be in the same repo as the CI config, anything else would have been a major PITA. Having auto-completion would have been a life saver.

Very useful feedback, could you make it a separate issue so we don't lose it? Thanks!

@helderco
Copy link
Contributor

helderco commented Apr 1, 2022

Great stuff 🙂

Dogfooding notes/wishlist @shykes @helderco @samalba:

  • I wish I could do dagger do build lint (a la Makefile)

Me too! And it makes it more portable. (windows anyone?)

  • I wish console outputs were available. It would have been a tremendous help to debug. Also very helpful to inform what just happened (e.g. dagger do build should print the revision we just built). I hacked around by writing a file and then removed that line before committing

Yeah, that's also what I've been doing. You know I'm partial to this 🙂

  • I wish the platform defaulted to buildkitd's platform. The performance is horrible in any other setting. I know we had long discussions around the API for this, but it's so important my recommendation would be to default to buildkitd and provide a --platform flag (so we don't need to define the whole CUE DX before making this change)

Not aware of this. Want to know more.

  • It would be nice if dagger was GitHub-aware. I split build and lint into two different GH jobs because I want to see them separately in the status. However, that doesn't do any good with caching. Ideally the dagger GHA could report individual actions as "statuses" in the PR?

This has been mentioned by multiple users.

  • The docker.#Run / docker.#Build experience was a bit challenging: not sure when to use one or the other. On the one hand, I prefer usingdagger.#Build to define pipelines (e.g. do this, do that, XXX) -- much better than _doA: ... _doB: .... On the other hand, I can't do that as soon as I want to export files. I started writing docker.#Build steps then had to convert to manual operations (see actions.version)

Interesting. I've been through this in January a lot, but it was because of the nesting issue. I know how frustrating it is to break those steps into correctly hooked fields. One small typo and you have an error that's not the root cause (incorrect #FS leading to errors elsewhere).

  • Also, I'm using docker.#Build like a dagger.#Pipeline -- I'm not really building anything

Yes, if there was a generic thing to hook any input: _ it could be reused for other things with the same workflow. I've done this in an abstraction for adding files to an #FS (instead of #Image).

  • Converting this line from our Makefile resulted in 40 lines of CUE: go build -ldflags '-s -w -X go.dagger.io/dagger/version.Revision=$(git rev-parse --short HEAD). Mostly because of the point above

I'll look into that more closely.

  • Language Server: I spent my time jumping between upstream definitions to figure out the interface. I was able to do that because universe happens to be in the same repo as the CI config, anything else would have been a major PITA. Having auto-completion would have been a life saver.

Yes, and having full reference docs could help as well.

@aluzzardi
Copy link
Member Author

aluzzardi commented Apr 1, 2022

Thanks for the response @helderco :)

I logged this into a separate issue: #1993

EDIT: @helderco mind copy pasting your message into that issue?

I just added spellcheck support and markdownlint -- for now in dagger/ci/pkg so we don't need for those packages to be "universe"quality.

I'd like to migrate our own CI to dagger ASAP so we can feel the pain :)

@aluzzardi
Copy link
Member Author

Update:

  • Moved universe.dagger.io/go/golangci into ci/pkg/golangci so we don't need universe quality
  • Add pkg/markdownlint, pkg/shellcheck

dagger CI linting is on par with Makefile linting

TomChv
TomChv previously requested changes Apr 1, 2022
Copy link
Member

@TomChv TomChv left a comment

Choose a reason for hiding this comment

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

Added a little comment, another question : package that you create specially for a plan should be in cue.mod/pkg or cue.mod/usr?
If I remember well, cue.mod/pkg is only for external dependencies

ci/main.cue Outdated Show resolved Hide resolved
@aluzzardi
Copy link
Member Author

Added a little comment, another question : package that you create specially for a plan should be in cue.mod/pkg or cue.mod/usr?

In this case I decided to add my packages to ci/pkg -- not in cue.mod. I think cue.mod is better suited for dependencies, not for my own code.

@TomChv
Copy link
Member

TomChv commented Apr 1, 2022

Added a little comment, another question : package that you create specially for a plan should be in cue.mod/pkg or cue.mod/usr?

In this case I decided to add my packages to ci/pkg -- not in cue.mod. I think cue.mod is better suited for dependencies, not for my own code.

Clear!

Copy link
Contributor

@shykes shykes left a comment

Choose a reason for hiding this comment

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

  • Love the factoring out into sub-packages
  • Reverting back to client.filesystem.".." is a regression (unnecessary tight coupling to current workdir).

Comment on lines +7 to +15
- "**.sh"
- "**.bash"
- "**.go"
- "**.cue"
- "**.bats"
- "Makefile"
- "go.mod"
- "go.sum"
- ".github/workflows/dagger-ci.yml"
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't wait to remove those and just rely on Dagger to do its thing...

ci/main.cue Outdated Show resolved Hide resolved
ci/main.cue Outdated
contents: core.#CacheDir & {
id: "go mod cache"
}
_source: client.filesystem["../"].read.contents
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above: access .. for this is an anti-pattern.

ci/main.cue Outdated
# Check that all formatted files where committed
test -z $(git status -s . | grep -e '^ M' | grep .cue | cut -d ' ' -f3)
"""#
cue: docker.#Build & {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a FIXME to spin this out into a cuelangci package like the equivalent golangci?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
- Use official Go package
- Use golangci-lint package
- Fix node_modules exclusion for local source
- Improve CUE performance by optimizing cache hits

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
@aluzzardi aluzzardi force-pushed the ci-improvement branch 2 times, most recently from 1fd0f92 to a8ccf33 Compare April 5, 2022 00:50
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
@aluzzardi aluzzardi merged commit a717ec0 into dagger:main Apr 5, 2022
@aluzzardi aluzzardi deleted the ci-improvement branch April 5, 2022 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants