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

[PLAT-6701] Enable zstd hephaestus #105

Merged
merged 2 commits into from
Jul 27, 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
31 changes: 25 additions & 6 deletions pkg/buildkit/buildkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"k8s.io/apimachinery/pkg/util/wait"

"github.com/dominodatalab/hephaestus/pkg/buildkit/archive"
hephconfig "github.com/dominodatalab/hephaestus/pkg/config"
)

var clientCheckBackoff = wait.Backoff{ // retries after 500ms 1s 2s 4s 8s 16s 32s 64s with jitter
Expand Down Expand Up @@ -122,6 +123,27 @@ type Client struct {
dockerConfigDir string
}

func validateCompression(compression string, name string) map[string]string {
attrs := make(map[string]string)
attrs["name"] = name
const truth = "true"
switch compression {
case "estargz":
attrs["push"] = truth
attrs["compression"] = "estargz"
attrs["force-compression"] = truth
attrs["oci-mediatypes"] = truth
case "zstd":
attrs["compression"] = "zstd"
attrs["force-compression"] = truth
attrs["push"] = truth
// default is gzip
default:
attrs["push"] = truth
}
return attrs
}

func (c *Client) Build(ctx context.Context, opts BuildOptions) error {
// setup build directory
buildDir, err := os.MkdirTemp("", "hephaestus-build-")
Expand Down Expand Up @@ -241,14 +263,11 @@ func (c *Client) Build(ctx context.Context, opts BuildOptions) error {
solveOpt.FrontendAttrs[k] = v
}
}

for _, name := range opts.Images {
bkclientattrs := validateCompression(hephconfig.CompressionMethod, name)
solveOpt.Exports = append(solveOpt.Exports, bkclient.ExportEntry{
Type: bkclient.ExporterImage,
Attrs: map[string]string{
"name": name,
"push": "true",
},
Type: bkclient.ExporterImage,
Attrs: bkclientattrs,
})
}

Expand Down
8 changes: 7 additions & 1 deletion pkg/cmd/controller/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controller

import (
"context"
"fmt"

"github.com/spf13/cobra"

Expand All @@ -17,7 +18,10 @@ func NewCommand() *cobra.Command {
Use: "hephaestus-controller",
Short: "OCI image build controller using buildkit",
}
cmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "hephaestus.yaml", "configuration file")
cmd.PersistentFlags().StringVarP(&cfgFile, "config", "c",
"hephaestus.yaml", "configuration file")
cmd.PersistentFlags().StringVarP(&config.CompressionMethod,
"compression", "d", "gzip", "Compression method options: zstd,estargz")
cmd.AddCommand(
newStartCommand(),
newRunGCCommand(),
Expand All @@ -33,6 +37,8 @@ func newStartCommand() *cobra.Command {
Use: "start",
Short: "Start controller",
RunE: func(cmd *cobra.Command, _ []string) error {
config.CompressionMethod, _ = cmd.Flags().GetString("compression")
fmt.Printf("BuildKit compression method: %s enabled\n", config.CompressionMethod)
cfgFile, err := cmd.Flags().GetString("config")
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"gopkg.in/yaml.v3"
)

var CompressionMethod string

type Controller struct {
Logging Logging `json:"logging" yaml:"logging"`
Manager Manager `json:"manager" yaml:"manager"`
Expand Down