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

Use dagger for build and test pipeline #4186

Closed
wants to merge 9 commits into from

Conversation

kpenfound
Copy link

This PR changes the test CI workflow to use a dagger pipeline. The net result is that dependencies required to run the full test suite locally are reduced to just Go and Docker. Runtimes locally should be significantly reduced because of Dagger's caching abilities, and the same can be applied in CI with some infrastructure changes.

This work was previously seen in a demo of this from equinix demo day

TODO:

  • tidy up builder.go
  • feedback on structure
  • tests for the ci pipeline

@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 13, 2023
Copy link
Member

@caarlos0 caarlos0 left a comment

Choose a reason for hiding this comment

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

I don't know enough about dagger (its on my to study list, appreciate if you have any good material to point me to), but besides a couple of comments, looks good to me.

the lint issues can be solved by running gofumpt

go.mod Outdated
Comment on lines 69 to 70
// DO NOT UPDATE THIS!! needs to be v0.0.0-20210512092938-c05353c2d58c
require github.com/ProtonMail/go-crypto v0.0.0-20230626094100-7e9e0395ebec // indirect
Copy link
Member

Choose a reason for hiding this comment

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

can ignore the // DO NOT UPDATE thing, its outdated...

Copy link
Member

Choose a reason for hiding this comment

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

PS: I'll fix this on main later to not conflict with this pr :)

ci/main.go Outdated

builder = builder.WithExec([]string{"go", "mod", "tidy"}).
WithExec([]string{"go", "build"}).
WithExec([]string{"go", "test", "./..."})
Copy link
Member

Choose a reason for hiding this comment

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

in the original pipeline, this would call ./script/test.sh, which also appends to $GITHUB_STEP_SUMMARY... not sure if that's possible with dagger too..

Copy link
Author

Choose a reason for hiding this comment

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

Yeah that should be possible, I'll try it out

Taskfile.yml Outdated
Comment on lines 34 to 41
env:
LC_ALL: C
vars:
TEST_OPTIONS: '{{default "" .TEST_OPTIONS}}'
SOURCE_FILES: '{{default "./..." .SOURCE_FILES}}'
TEST_PATTERN: '{{default "." .TEST_PATTERN}}'
cmds:
- go test {{.TEST_OPTIONS}} -failfast -race -coverpkg=./... -covermode=atomic -coverprofile=coverage.txt {{.SOURCE_FILES}} -run {{.TEST_PATTERN}} -timeout=5m
Copy link
Member

Choose a reason for hiding this comment

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

I would leave this as is, maybe add a ci task, that calls go run ./ci

go.mod Outdated
@@ -4,6 +4,7 @@ go 1.20

require (
code.gitea.io/sdk/gitea v0.15.1
dagger.io/dagger v0.7.2
Copy link
Member

Choose a reason for hiding this comment

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

can we make ./ci its own module? so whoever go install goreleaser don't need to download dagger and all this other deps too...

Copy link
Author

Choose a reason for hiding this comment

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

Yeah good call

@gerhard
Copy link

gerhard commented Jul 13, 2023

Thank you for reviewing this @caarlos0!

We gave you a shout-out in today's Dagger Community Call (https://dagger.io/events fwiw). Recording will be uploaded to YouTube in a day (or a few at most). Will drop a link when it's public. cc @jpadams @mircubed @d3rp3tt3

Thank you @marcosnils for helping kick this off 💪

ci/builder.go Outdated
WithExec([]string{"chown", "-R", "nonroot", "/src"}).
WithNewFile("/usr/local/sbin/docker", dagger.ContainerWithNewFileOpts{
Contents: `#!/bin/sh
DOCKER_HOST=tcp://localhost:2375 /usr/bin/docker $@`,
Copy link
Contributor

Choose a reason for hiding this comment

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

@kpenfound given that @caarlos0 seems to be quite responsive to merge this maybe we can take the opportunity to make this change in goreleaser so this hack is not necessary?

@caarlos0 FWIW we had to do this beacuse goreleaser tests seem to overriding env variables when calling docker

Copy link
Author

Choose a reason for hiding this comment

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

Agreed. Originally this code ran outside of the goreleaser repo so it was running the tests without modifications. A few workarounds were necessary to accommodate that. In this case, there's a few tests where localhost is hardcoded and overriding any DOCKER_HOST env

Copy link
Member

Choose a reason for hiding this comment

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

hmmm, totally, feel free to make the necessary changes! <3

Copy link
Contributor

Choose a reason for hiding this comment

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

@caarlos0 basically goreleaser tests are overriding go test envs since they're being set here https://github.com/goreleaser/goreleaser/blob/7c6201f5f588fa1a8504f5cffa6264646fdee1eb/internal/pipe/docker/docker_test.go#LL992C17-L992C17 and then used here

cmd.Env = ctx.Env.Strings()
.

The change that would help us to remove this hack is if goreleaser appended ctx.Env envs to the current existing variables here

cmd.Env = ctx.Env.Strings()
instead of overriding them altogether. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's probably the right thing to do, and what most people would expect to happen.

Honestly kinda surprised no one reported that as a bug yet 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's probably the right thing to do, and what most people would expect to happen.

Honestly kinda surprised no one reported that as a bug yet thinking

#4187

Copy link
Member

Choose a reason for hiding this comment

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

merged!

marcosnils added a commit to marcosnils/goreleaser that referenced this pull request Jul 13, 2023
This is causing issues when trying to run tests in Dagger.
ref: goreleaser#4186 (comment)

Signed-off-by: Marcos Lilljedahl <marcosnils@gmail.com>
caarlos0 pushed a commit that referenced this pull request Jul 14, 2023
This is causing issues when trying to run tests in Dagger.
ref:
#4186 (comment)

Signed-off-by: Marcos Lilljedahl <marcosnils@gmail.com>

Signed-off-by: Marcos Lilljedahl <marcosnils@gmail.com>
@mircubed
Copy link

Thanks again @caarlos0 ! You can check out the recording for the shout out here (13:20 timestamp) :) https://www.youtube.com/watch?v=dRfcSIIAvG4

@caarlos0
Copy link
Member

Thanks again @caarlos0 ! You can check out the recording for the shout out here (13:20 timestamp) :) https://www.youtube.com/watch?v=dRfcSIIAvG4

Pretty cool! Thanks for the mention and the PR 💜

@caarlos0
Copy link
Member

one Q about this: can we automate updates, like we do with dependabot?

if not, is there any plans to do so?

@caarlos0 caarlos0 added the enhancement New feature or request label Jul 18, 2023
@caarlos0
Copy link
Member

hey, thanks for all the effort on this, but I think I'll leave it as-is for now.

@caarlos0 caarlos0 closed this Jan 14, 2024
@marcosnils
Copy link
Contributor

marcosnils commented Jan 14, 2024 via email

@kpenfound
Copy link
Author

hey, thanks for all the effort on this, but I think I'll leave it as-is for now.

sounds good @caarlos0 ! Maybe we can take another run at this with a future version of Dagger :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants