Skip to content

Commit

Permalink
feat(publish): add ability to select specific layers to publish
Browse files Browse the repository at this point in the history
Currently, publish cmd will push every layer in a stacker.yaml file by
default.

This patch adds support to push only required layers.

Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
  • Loading branch information
rchincha committed Feb 25, 2023
1 parent 89709e6 commit 0f4e19d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/stacker/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ var publishCmd = cli.Command{
Usage: "set the output layer type (supported values: tar, squashfs); can be supplied multiple times",
Value: &cli.StringSlice{"tar"},
},
cli.StringSliceFlag{
Name: "layer",
Usage: "layer to be published; can be specified multiple times",
},
},
Before: beforePublish,
}
Expand Down Expand Up @@ -120,6 +124,7 @@ func doPublish(ctx *cli.Context) error {
Progress: shouldShowProgress(ctx),
SkipTLS: ctx.Bool("skip-tls"),
LayerTypes: layerTypes,
Layers: ctx.StringSlice("layer"),
}

var stackerFiles []string
Expand Down
14 changes: 14 additions & 0 deletions pkg/stacker/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type PublishArgs struct {
Progress bool
SkipTLS bool
LayerTypes []types.LayerType
Layers []string
}

// Publisher is responsible for publishing the layers based on stackerfiles
Expand Down Expand Up @@ -117,6 +118,19 @@ func (p *Publisher) Publish(file string) error {
log.Infof("will not publish: %s build_only %s", file, name)
continue
}
if len(p.opts.Layers) > 0 {
found := false
for _, lname := range p.opts.Layers {
if lname == name {
found = true
break
}
}

if !found {
continue
}
}

// Verify layer is in build cache
_, ok, err = buildCache.Lookup(name)
Expand Down
13 changes: 13 additions & 0 deletions test/publish.bats
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ function teardown() {
[ -f dest/layer2_test1/rootfs/root/import1 ]
}

@test "publish selected multiple layers" {
stacker recursive-build -d ocibuilds
stacker publish -d ocibuilds --url oci:oci_publish --tag test1 --layer layer1 --layer layer6

# Unpack published image and check content
umoci unpack --image oci_publish:layer1_test1 dest/layer1_test1
[ -f dest/layer1_test1/rootfs/root/import1 ]
umoci unpack --image oci_publish:layer6_test1 dest/layer6_test1
[ -f dest/layer6_test1/rootfs/root/import6 ]
umoci unpack --image oci_publish:layer2_test1 dest/layer2_test1
[ "$status" -eq 1 ]
}

@test "publish single layer with docker url" {
stacker build -f ocibuilds/sub1/stacker.yaml
stacker publish -f ocibuilds/sub1/stacker.yaml --url docker://docker-reg.fake.com/ --username user --password pass --tag test1 --show-only
Expand Down

0 comments on commit 0f4e19d

Please sign in to comment.