Skip to content

Commit

Permalink
[PLAT-6701] Enable zstd hephaestus
Browse files Browse the repository at this point in the history
  • Loading branch information
ddl-retornam committed Jun 26, 2023
1 parent c09a51c commit 8b23be8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
30 changes: 24 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 @@ -118,6 +119,26 @@ type Client struct {
dockerAuthConfig string
}

func validateCompression(compression string, name string) map[string]string {
attrs := make(map[string]string)
attrs["name"] = name
switch compression {
case "estargz":
attrs["push"] = "true"

Check failure on line 127 in pkg/buildkit/buildkit.go

View workflow job for this annotation

GitHub Actions / build

string `true` has 6 occurrences, make it a constant (goconst)
attrs["compression"] = "estargz"
attrs["force-compression"] = "true"
attrs["oci-mediatypes"] = "true"
case "zstd":
attrs["compression"] = "zstd"
attrs["force-compression"] = "true"
attrs["push"] = "true"
// default is gzip
default:
attrs["push"] = "true"
}
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 @@ -230,14 +251,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
4 changes: 4 additions & 0 deletions 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 @@ -18,6 +19,7 @@ func NewCommand() *cobra.Command {
Short: "OCI image build controller using buildkit",
}
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 +35,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

0 comments on commit 8b23be8

Please sign in to comment.