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

Rewrite using buildkite-builder 💥✨ #73

Merged
merged 93 commits into from
Jan 16, 2024
Merged

Rewrite using buildkite-builder 💥✨ #73

merged 93 commits into from
Jan 16, 2024

Conversation

zzak
Copy link
Member

@zzak zzak commented Nov 20, 2023

Here is the initial refactor to use buildkite-builder.

Things to note

meta-ci

You'll also notice there are a lint and test jobs in the buildkite-config pipeline:
https://buildkite.com/rails/config-sandbox/builds/70

These join the existing annotate job, which was refactored to use the same unprivileged docker container strategy as pipeline-generate.

Here is a rails/rails (main) build using the new pipeline format:
https://buildkite.com/rails/rails-sandbox/builds/56

I haven't yet tested this with branches and PRs since, probably the biggest risk there is how docker build uses the branches and pr info to generate the build cache.

Copy link
Contributor

@ngan ngan left a comment

Choose a reason for hiding this comment

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

This looks great! I left a couple of QOL comments. I think I can put up some more PRs for more improvements when I have time. Great work!

lib/buildkite_config/build_context.rb Outdated Show resolved Hide resolved
lib/buildkite_config/docker_build.rb Outdated Show resolved Hide resolved
pipelines/rails-ci/pipeline.rb Show resolved Hide resolved
zzak and others added 5 commits December 1, 2023 16:26
Copy of rails#72 for bkb branch

Co-authored-by: Petrik <[email protected]>
Copy of rails#74 for bkb branch

Co-authored-by: Hartley McGuire <[email protected]>
Originally I thought the bkb Lib extension adds lib path for you, so I would like to figure that out at some point /cc @ngan
pipelines/rails-ci/pipeline.rb Outdated Show resolved Hide resolved
zzak and others added 3 commits December 1, 2023 17:02
This gives us another hook to refactor later, but also we can stub the artifacts in the tests so even if the version changes the tests shouldn't fail

Co-authored-by: Ngan Pham <[email protected]>
@zzak
Copy link
Member Author

zzak commented Dec 1, 2023

@ngan Thanks for your review! I've applied your suggestions, and look forward to iterating on this together in the future 🙇

Copy link
Member

@skipkayhil skipkayhil left a comment

Choose a reason for hiding this comment

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

This seems really cool! I left a few higher level comments and a few lower level comments about some things that stood out to me.

I wonder if its worth trying to simplify some of the version checks before making this change... we only run CI on 6.1+ at this point and there are a bunch of conditions checking for Rails 5.x or 6.0

.rubocop.yml Show resolved Hide resolved
lib/buildkite_config.rb Outdated Show resolved Hide resolved
Comment on lines 24 to 36
"image-name" => build_context.ruby.image_name_for(build_context.build_id),
"cache-from" => [
build_context.rebuild_id && "base:" + build_context.image_base + ":" + build_context.ruby.image_name_for(build_context.rebuild_id),
build_context.pull_request && "base:" + build_context.image_base + ":" + build_context.ruby.image_name_for("pr-#{build_context.pull_request}"),
build_context.local_branch && build_context.local_branch !~ /:/ && "base:" + build_context.image_base + ":" + build_context.ruby.image_name_for("br-#{build_context.local_branch}"),
build_context.base_branch && "base:" + build_context.image_base + ":" + build_context.ruby.image_name_for("br-#{build_context.base_branch}"),
"base:" + build_context.image_base + ":" + build_context.ruby.image_name_for("br-main"),
].grep(String).uniq,
push: [
build_context.local_branch =~ /:/ ?
"base:" + build_context.image_base + ":" + build_context.ruby.image_name_for("pr-#{build_context.pull_request}") :
"base:" + build_context.image_base + ":" + build_context.ruby.image_name_for("br-#{build_context.local_branch}"),
],
Copy link
Member

Choose a reason for hiding this comment

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

For the most part I like how a lot of the abstraction looks, but this section feels incredibly hard to grok. It seems like a lot of these methods end up passing a param from the build_context to another method on the build_context, could these type of methods just be lifted to the build_context completely?

lib/buildkite_config/build_context.rb Outdated Show resolved Hide resolved
rubies.select { |r| !r.soft_fail? }.first
end

def setup_rubies(ruby_minors)
Copy link
Member

Choose a reason for hiding this comment

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

If I'm reading this correctly, this method takes ruby_minors as the only input and returns a list of RubyConfig? Feels like a class method on RubyConfig may be a better home, and it would allow us to split out some helper methods without polluting BuildContext as well (there's a lot going on in here)

@rafaelfranca
Copy link
Member

Missed this one and end up doing #82 because I introduced a lot of duplication and wanted to remove.

I like the DSL built here but I don't like the added dependency. Can we just evolve on top of #82 with a better DSL?

@rafaelfranca
Copy link
Member

I'm trying this approach so we go with it. I'll work on top of this branch

This is more like the default_ruby to use in pipelines that don't
need to run against multiple rubies.
Let's upgrade outside of the refactoring.
@rafaelfranca rafaelfranca merged commit 4510780 into rails:main Jan 16, 2024
1 check was pending
@zzak zzak deleted the bkb branch January 26, 2024 05:54
plugin :docker_compose, {
"env" => %w[PRE_STEPS RACK],
"run" => service,
"pull" => service,
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually need that pull? Looking at builds, every single job spend 30-40 seconds pulling images that are already there locally:

Capture d’écran 2024-02-09 à 10 48 33

I get that if these images were to change in the registry we'd risk having some workers run outdated images and some up to date ones, but that's probably an acceptable tradeoff to speed CI by this much, no?

Copy link
Member

Choose a reason for hiding this comment

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

NB: I'm quite familiar with docker, but pretty much not at all with docker-compose so perhaps I'm misunderstanding the purpose of that pull.

Copy link
Member Author

Choose a reason for hiding this comment

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

@byroot My naive understanding is that is there for downstream jobs to pull the base image from the build job, and pull is there to make sure we get the right one. But to be honest, I was only hoping to achieve as close to 1:1 with the existing pipeline before making any changes, so there is definitely room for improvement.

If you want to open a PR to here to confirm it, you can run a test build of the pipeline like here by click the "Review Build Script".

スクリーンショット 2024-02-09 19 56 50

There is a build triggered on PRs to this repo, but it requires approval from a team member to run, wasn't sure if you knew about this yet. 🙇

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

Successfully merging this pull request may close these issues.

5 participants