Skip to content

Commit 2455ac3

Browse files
Merge pull request #27153 from rhatdan/cursor
Add --replace option to podman artifact add command
2 parents 14b68ba + b765c91 commit 2455ac3

File tree

14 files changed

+343
-12
lines changed

14 files changed

+343
-12
lines changed

cmd/podman/artifact/add.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ func init() {
5353
appendFlagName := "append"
5454
flags.BoolVarP(&addOpts.Append, appendFlagName, "a", false, "Append files to an existing artifact")
5555

56+
replaceFlagName := "replace"
57+
flags.BoolVar(&addOpts.Replace, replaceFlagName, false, "Replace an existing artifact")
58+
5659
fileMIMETypeFlagName := "file-type"
5760
flags.StringVarP(&addOpts.FileMIMEType, fileMIMETypeFlagName, "", "", "Set file type to use for the artifact (layer)")
5861
_ = addCmd.RegisterFlagCompletionFunc(fileMIMETypeFlagName, completion.AutocompleteNone)
@@ -62,6 +65,10 @@ func add(_ *cobra.Command, args []string) error {
6265
artifactName := args[0]
6366
blobs := args[1:]
6467

68+
if addOpts.Append && addOpts.Replace {
69+
return fmt.Errorf("--append and --replace options cannot be used together")
70+
}
71+
6572
annots, err := utils.ParseAnnotations(addOpts.AnnotationsCLI)
6673
if err != nil {
6774
return err
@@ -72,6 +79,7 @@ func add(_ *cobra.Command, args []string) error {
7279
ArtifactMIMEType: addOpts.ArtifactMIMEType,
7380
Append: addOpts.Append,
7481
FileMIMEType: addOpts.FileMIMEType,
82+
Replace: addOpts.Replace,
7583
}
7684

7785
artifactBlobs := make([]entities.ArtifactBlob, 0, len(blobs))

docs/source/markdown/podman-artifact-add.1.md.in

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
% podman-artifact-add 1
22

33
## NAME
4-
podman\-artifact\-add - Add an OCI artifact to the local store
4+
podman\-artifact\-add - Add an OCI artifact to local artifact store
55

66
## SYNOPSIS
7-
**podman artifact add** *name* *file* [*file*]...
7+
**podman artifact add** [*options*] *artifact-name* *file* [*file* ...]
88

99
## DESCRIPTION
1010

@@ -35,6 +35,11 @@ Set the media type of the artifact file instead of allowing detection to determi
3535

3636
Print usage statement.
3737

38+
#### **--replace**
39+
40+
If an artifact with the same name already exists, replace and remove it. The default is **false**.
41+
This option cannot be used with the **--append** option.
42+
3843
#### **--type**
3944

4045
Set a type for the artifact being added.
@@ -48,25 +53,29 @@ $ podman artifact add quay.io/myartifact/myml:latest /tmp/foobar.ml
4853
0fe1488ecdef8cc4093e11a55bc048d9fc3e13a4ba846efd24b5a715006c95b3
4954
```
5055

51-
Add multiple files to an artifact
56+
Add OCI artifact to the store with type:
57+
5258
```
53-
$ podman artifact add quay.io/myartifact/myml:latest /tmp/foobar1.ml /tmp/foobar2.ml
54-
1487acae11b5a30948c50762882036b41ac91a7b9514be8012d98015c95ddb78
59+
$ podman artifact add --artifact-type application/com.example.ai --file-type application/vnd.gguf quay.io/myimage/myartifact:latest /home/user/model.gguf
5560
```
5661

57-
Set an annotation for an artifact
62+
Replace an existing artifact with the same name
63+
5864
```
59-
$ podman artifact add --annotation date=2025-01-30 quay.io/myartifact/myml:latest /tmp/foobar1.ml
65+
$ podman artifact add quay.io/myartifact/myml:latest /tmp/foobar.ml
66+
0fe1488ecdef8cc4093e11a55bc048d9fc3e13a4ba846efd24b5a715006c95b3
6067
```
6168

62-
Append a file to an existing artifact
69+
Add multiple files to an artifact
6370
```
64-
$ podman artifact add --append quay.io/myartifact/tarballs:latest /tmp/foobar.tar.gz
71+
$ podman artifact add quay.io/myartifact/myml:latest /tmp/foobar1.ml /tmp/foobar2.ml
72+
1487acae11b5a30948c50762882036b41ac91a7b9514be8012d98015c95ddb78
6573
```
6674

67-
Override the media type of the artifact being added
75+
Add files to an existing OCI artifact
76+
6877
```
69-
$ podman artifact add --file-type text/yaml quay.io/myartifact/descriptors:latest /tmp/info.yaml
78+
$ podman artifact add --append quay.io/myimage/myartifact:latest /home/user/config.yaml
7079
```
7180

7281

docs/source/markdown/podman-artifact.1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ from its local "artifact store".
1717

1818
| Command | Man Page | Description |
1919
|---------|------------------------------------------------------------|--------------------------------------------------------------|
20-
| add | [podman-artifact-add(1)](podman-artifact-add.1.md) | Add an OCI artifact to the local store |
20+
| add | [podman-artifact-add(1)](podman-artifact-add.1.md) | Add an OCI artifact to local artifact store |
2121
| extract | [podman-artifact-extract(1)](podman-artifact-extract.1.md) | Extract an OCI artifact to a local path |
2222
| inspect | [podman-artifact-inspect(1)](podman-artifact-inspect.1.md) | Inspect an OCI artifact |
2323
| ls | [podman-artifact-ls(1)](podman-artifact-ls.1.md) | List OCI artifacts in local store |

pkg/api/handlers/libpod/artifacts.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ func AddArtifact(w http.ResponseWriter, r *http.Request) {
223223
Annotations []string `schema:"annotations"`
224224
ArtifactMIMEType string `schema:"artifactMIMEType"`
225225
Append bool `schema:"append"`
226+
Replace bool `schema:"replace"`
226227
}{}
227228

228229
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
@@ -246,6 +247,7 @@ func AddArtifact(w http.ResponseWriter, r *http.Request) {
246247
Annotations: annotations,
247248
ArtifactMIMEType: query.ArtifactMIMEType,
248249
FileMIMEType: query.FileMIMEType,
250+
Replace: query.Replace,
249251
}
250252

251253
artifactBlobs := []entities.ArtifactBlob{{

pkg/api/server/register_artifacts.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ func (s *APIServer) registerArtifactHandlers(r *mux.Router) error {
191191
// description: Append files to an existing artifact
192192
// type: boolean
193193
// default: false
194+
// - name: replace
195+
// in: query
196+
// description: Replace an existing artifact with the same name
197+
// type: boolean
198+
// default: false
194199
// - name: inputStream
195200
// in: body
196201
// description: Binary stream of the file to add to an artifact

pkg/bindings/artifacts/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ type AddOptions struct {
6464
ArtifactMIMEType *string
6565
Append *bool
6666
FileMIMEType *string
67+
Replace *bool
6768
}
6869

6970
// ExtractOptions

pkg/bindings/artifacts/types_add_options.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/domain/entities/artifact.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type ArtifactAddOptions struct {
1313
ArtifactMIMEType string
1414
Append bool
1515
FileMIMEType string
16+
Replace bool
1617
}
1718

1819
type ArtifactAddReport = entitiesTypes.ArtifactAddReport

pkg/domain/infra/abi/artifact.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,19 @@ func (ir *ImageEngine) ArtifactAdd(ctx context.Context, name string, artifactBlo
209209
return nil, err
210210
}
211211

212+
// If replace is true, try to remove existing artifact (ignore errors if it doesn't exist)
213+
if opts.Replace {
214+
if _, err = artStore.Remove(ctx, name); err != nil && !errors.Is(err, types.ErrArtifactNotExist) {
215+
logrus.Debugf("Artifact %q removal failed: %s", name, err)
216+
}
217+
}
218+
212219
addOptions := types.AddOptions{
213220
Annotations: opts.Annotations,
214221
ArtifactMIMEType: opts.ArtifactMIMEType,
215222
Append: opts.Append,
216223
FileMIMEType: opts.FileMIMEType,
224+
Replace: opts.Replace,
217225
}
218226

219227
artifactDigest, err := artStore.Add(ctx, name, artifactBlobs, &addOptions)

pkg/domain/infra/tunnel/artifact.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func (ir *ImageEngine) ArtifactAdd(_ context.Context, name string, artifactBlob
8989
Append: &opts.Append,
9090
ArtifactMIMEType: &opts.ArtifactMIMEType,
9191
FileMIMEType: &opts.FileMIMEType,
92+
Replace: &opts.Replace,
9293
}
9394

9495
for k, v := range opts.Annotations {

0 commit comments

Comments
 (0)