chainguard-dev / melange

build APKs from source code
Apache License 2.0
411 stars 95 forks source link

List of available melange Pipelines #172

Open ArnobKumarSaha opened 1 year ago

ArnobKumarSaha commented 1 year ago

I was looking for a complete list of the action-names that we use in the pipeline.uses in melange files (For example: https://github.com/wolfi-dev/os/blob/main/bash.yaml#L42-L44), but didn't find any.

Even the docs has not specified anything. Is there any resources available on it ?

tuananh commented 1 year ago

here you go: https://github.com/chainguard-dev/melange/tree/main/pkg/build/pipelines

ArnobKumarSaha commented 1 year ago

Thanks for the quick response @tuananh. I missed this package somehow!!

imjasonh commented 1 year ago

I think it would be useful to have some commands like melange pipelines list, melange pipelines get split/dev, etc. to inspect the built-in pipelines from the commandline. Shouldn't be too hard to do either, if anybody's interested I can help.

ArnobKumarSaha commented 1 year ago

@imjasonh That sounds awesome!! I am interested to do that. Guide me please.

imjasonh commented 1 year ago

To add a new command, add a new cmd.AddCommand(Pipelines()) here: https://github.com/chainguard-dev/melange/blob/main/pkg/cli/commands.go#L33

Create pkg/cli/commands/pipelines.go. Take inspiration from sign.go -- it returns a cmd which specifies a RunE which gets called when the command is called. In this case, melange pipelines doesn't actually do anything, so its RunE should fail.

func Pipelines() *cobra.Command {
    cmd := &cobra.Command{
        Use:     "pipelines",
        Short:   "Commands for inspecting pipeline definitions",
        Args:    cobra.NoArgs,
        RunE: func(cmd *cobra.Command, args []string) error {
            return errors.New("must call get or list")
        },
    }
    cmd.AddCommand(list())
    cmd.AddCommand(get())
    return cmd
}

func list() *cobra.Command {
    //same as above, with a RunE that lists available pipelines.
}

To list pipelines, we need some method to inspect the contents of the embedded filesystem available here:

https://github.com/chainguard-dev/melange/blob/3a5d6762d567e56937aa403f30899a3e774aeac8/pkg/build/pipeline.go#L378

To list files, call f.ReadDir("pipelines/") (I think) to get entries. Each available pipeline is named after its path, so fetch.yaml is fetch, and split/dev.yaml is split/dev, and so on.

That should be enough to list available pipelines for melange pipelines list.

For melange pipelines get <name> it's pretty much the same, except once you find a pipeline with that name you need to read it and print it out. If no pipeline is found with that name (melange pipelines get does-not-exist) then return an error.

Let me know if there's anything else I can help with, I'd love to see this work, and I think it would be a helpful addition to the tool.

ArnobKumarSaha commented 1 year ago

Hi @imjasonh , I was going to start. But seems like, @tuananh is already working on this. Have a check on his pr https://github.com/chainguard-dev/melange/pull/165 .

mritunjaysharma394 commented 1 year ago

Hello folks, I see that the PR #165 of @tuananh is closed and if no one is actively working on it, I would love to contribute!