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

Allow overriding Repository / Tag on Get #337

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,26 @@ Fetches an image at the exact digest specified by the version.
needing to download the image you just uploaded.
</td>
</tr>
<tr>
<td><code>repository</code> <em>(Optional)</em></td>
<td>
Override the repository defined in the <code>source</code> configuration.
Useful when dynamically passing a repo in a job. Not intended to be used with `trigger`.
</td>
</tr>
<tr>
<td><code>insecure</code> <em>(Optional)<br>Default: false</em></td>
<td>
Allow insecure registry.
</td>
</tr>
<tr>
<td><code>tag</code> <em>(Optional)</em></td>
<td>
Override the tag defined in the <code>source</code>.
Useful when dynamically passing a tag in a job. Not intended to be used with `trigger`.
</td>
</tr>
</tbody>
</table>

Expand Down
16 changes: 14 additions & 2 deletions commands/in.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,24 @@ func (i *In) Execute() error {
}
}

repo, err := req.Source.NewRepository()
// override source if repository is passed in get param
repo := name.Repository{}
if req.Params.Repository != "" {
repo, err = req.Params.NewRepository()
} else {
repo, err = req.Source.NewRepository()
}
if err != nil {
return fmt.Errorf("failed to resolve repository: %w", err)
}

tag := repo.Tag(req.Version.Tag)
// override source if tag is passed in get param
tag := name.Tag{}
if req.Params.Tag != "" {
tag = repo.Tag(req.Params.Tag.String())
} else {
tag = repo.Tag(req.Version.Tag)
}

if !req.Params.SkipDownload {
mirrorSource, hasMirror, err := req.Source.Mirror()
Expand Down
15 changes: 15 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@ type MetadataField struct {
type GetParams struct {
RawFormat string `json:"format"`
SkipDownload bool `json:"skip_download"`
Repository string `json:"repository,omitempty"`
Insecure bool `json:"insecure"`
Tag Tag `json:"tag,omitempty"`
}

func (p GetParams) Format() string {
Expand All @@ -489,6 +492,18 @@ func (p GetParams) Format() string {
return p.RawFormat
}

func (p GetParams) NewRepository() (name.Repository, error) {
return name.NewRepository(p.Repository, p.RepositoryOptions()...)
}

func (p GetParams) RepositoryOptions() []name.Option {
var opts []name.Option
if p.Insecure {
opts = append(opts, name.Insecure)
}
return opts
}

type PutParams struct {
// Path to an OCI image tarball to push.
Image string `json:"image"`
Expand Down