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

feat: Remove magic strings from Source type #77

Merged
merged 52 commits into from
Jan 23, 2024

Conversation

pmengelbert
Copy link
Contributor

Replaces PR #57 , see #57 for all comments which have been addressed by now.

There was a snafu with the Azure/dalec repo going public, so I had to re-fork.

@pmengelbert pmengelbert requested a review from cpuguy83 January 19, 2024 18:06
@pmengelbert
Copy link
Contributor Author

pmengelbert commented Jan 19, 2024

  • unit test for validate
  • unit test for fillDefaults

The source variants, with all sub-fields, have been added to the
`Source` struct. Note that this code does not yet work, and will not
compile.

Signed-off-by: Peter Engelbert <[email protected]>
These are basic getters and setters for the `Ref` subfields on various
`Source` variants. Because any one of these variants could be non-nil,
we first have to determine which is in use. Not all Source vaiants have
a `.Ref` field, so those cases need to be handled as well.

These methods each return an additional `bool` value depending on
whether or not the `.Ref` field exists in the Source variant.

Signed-off-by: Peter Engelbert <[email protected]>
Change switch on scheme to union variant in `source2LLBGetter`
(`source.go`).

Signed-off-by: Peter Engelbert <[email protected]>
Continue implementing the necessary switches. This code compiles.

Signed-off-by: Peter Engelbert <[email protected]>
This field is now found on `Source.Git`.

Signed-off-by: Peter Engelbert <[email protected]>
Also, remove `Source.Source` and `SourceAnotherSource`.

Signed-off-by: Peter Engelbert <[email protected]>
* Remove source.GetRef and source.SetRef
* Add source.processArgs and use it where necessary

Signed-off-by: Peter Engelbert <[email protected]>
It's often convenient to use files and directories from the local
filesystem as a source. This commit essentially exposes `llb.Local(...)`
to the user via the spec.

This implementation may be incomplete, and should be reviewed.

Signed-off-by: Peter Engelbert <[email protected]>
Validate that a source does not have multiple variants defined, and that
it has at least one variant defined.

If there's a more elegant implementation, feel free to suggest it.

Signed-off-by: Peter Engelbert <[email protected]>
It may be necessary in the future to allow specification of commands on
`Build` and `Context` source variants. For now, it is only possible for
Docker images.

Signed-off-by: Peter Engelbert <[email protected]>
Signed-off-by: Peter Engelbert <[email protected]>
The format has changed, and this check is no longer correct.

This commit also re-runs the `go generate` command and commits the
changes.

Signed-off-by: Peter Engelbert <[email protected]>
Note: Only some of the tests will run properly. The logic for
`SourceBuild` needs to be re-tooled in order to run one of the tests
properly. I will come back later to edit the rest of the test fixtures.

Signed-off-by: Peter Engelbert <[email protected]>
`SourceBuild` needs a base state of some sort, in which the specified
Dockerfile will be executed. This implementation allows the base state
to be made up of a local path, a build context, or another source.

This may not be final, and it's likely that there are mistakes in here.

Signed-off-by: Peter Engelbert <[email protected]>
The tests are still not completing successfully, so more troubleshooting
is needed.

Signed-off-by: Peter Engelbert <[email protected]>
Signed-off-by: Peter Engelbert <[email protected]>
After discussion with Brian, this is the correct struct layout for this.
The context string is a path which will be used as the `.` context for
the dockerfile build.

Signed-off-by: Peter Engelbert <[email protected]>
Signed-off-by: Peter Engelbert <[email protected]>
Signed-off-by: Peter Engelbert <[email protected]>
Signed-off-by: Peter Engelbert <[email protected]>
To pass the linter

Signed-off-by: Peter Engelbert <[email protected]>
Because of the patching PR.

Signed-off-by: Peter Engelbert <[email protected]>
We can no longer reference other sources. Instead, we can specify a
`local` source with the current directory in order to build the
frontend.

Signed-off-by: Peter Engelbert <[email protected]>
Signed-off-by: Peter Engelbert <[email protected]>
Signed-off-by: Peter Engelbert <[email protected]>
Signed-off-by: Peter Engelbert <[email protected]>
Signed-off-by: Peter Engelbert <[email protected]>
Additionally, ensure that the defaults are filled correctly for the
`context` source type (which made the `local` type redundant).

Signed-off-by: Peter Engelbert <[email protected]>
We're no longer using the schemes

Signed-off-by: Peter Engelbert <[email protected]>
Signed-off-by: Peter Engelbert <[email protected]>
Use them instead of pointers. Also, validate them up-front in the
`validate` function, so that they do not need to be checked later.

Signed-off-by: Peter Engelbert <[email protected]>
Signed-off-by: Peter Engelbert <[email protected]>
Also, validate sources recursively.

Signed-off-by: Peter Engelbert <[email protected]>
Also:
- update `processArgs` to do substitutions inline.
- update `fillDefaults` to set the default Source.Path to `"."` when the
  Source type is Context.

Signed-off-by: Peter Engelbert <[email protected]>
Clearer to do it with some code repetition

Signed-off-by: Peter Engelbert <[email protected]>
Signed-off-by: Peter Engelbert <[email protected]>
Ensure the commit specified in the spec makes it to the call to
`llb.Git`.

Signed-off-by: Peter Engelbert <[email protected]>
The unit test revealed some bugs, which have been fixed.
Also, validation error messages have been improved.

Signed-off-by: Peter Engelbert <[email protected]>
@pmengelbert pmengelbert force-pushed the pmengelbert/remove_magic_strings/4 branch from 4ea0dca to 97a52f5 Compare January 23, 2024 15:14
Signed-off-by: Peter Engelbert <[email protected]>
Signed-off-by: Peter Engelbert <[email protected]>
Signed-off-by: Peter Engelbert <[email protected]>
spec.go Outdated
// === Begin Source Variants ===
DockerImage *SourceDockerImage `yaml:"image,omitempty" json:"image,omitempty"`
Git *SourceGit `yaml:"git,omitempty" json:"git,omitempty"`
HTTPS *SourceHTTPS `yaml:"https,omitempty" json:"https,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Nit: this should probably just be http.
Tried to think of a better name than that but am coming up short.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The field name? The Struct name? The json tag? All of the above?

Copy link
Member

Choose a reason for hiding this comment

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

All of the above.

Copy link
Contributor 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: Peter Engelbert <[email protected]>
See previous commit

Signed-off-by: Peter Engelbert <[email protected]>
@pmengelbert pmengelbert force-pushed the pmengelbert/remove_magic_strings/4 branch from 19cb65b to 44760a6 Compare January 23, 2024 20:08
@cpuguy83 cpuguy83 merged commit 14e095e into Azure:main Jan 23, 2024
6 checks passed
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