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(publish): add ability to select specific layers to publish #418

Merged
merged 1 commit into from
Feb 25, 2023
Merged
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
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
14 changes: 14 additions & 0 deletions test/publish.bats
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ 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/ls_out ]
# since we did not publish this layer, shouldn't be found
run umoci unpack --image oci_publish:layer2_test1 dest/layer2_test1
[ "$status" -ne 0 ]
}

@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