Skip to content

Commit

Permalink
Use zstd for artifact compression instead of gzip.
Browse files Browse the repository at this point in the history
  • Loading branch information
gnutix committed Dec 5, 2023
1 parent 6ffaaca commit fc740b6
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion client/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var artifactCmd = &cobra.Command{

var errors []string
for i, task := range finishedTasks {
file := path.Join(lo.Must(cmd.Flags().GetString("output")), fmt.Sprintf("%s.tar.gz", task))
file := path.Join(lo.Must(cmd.Flags().GetString("output")), fmt.Sprintf("%s.tar.zst", task))
if err := downloadArtifact(cmd.Context(), job.Name, task, file); err != nil {
errors = append(errors, err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion provisioner/local/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (f *fs) SaveContainerLogs(containerId, p string) error {
}

func (f *fs) Archive(p string) (rc io.ReadCloser, err error) {
cmd := exec.Command("tar", "-c", "-f", "-", "-z", "-C", f.root, strings.TrimLeft(p, "/"))
cmd := exec.Command("tar", "--create", "--use-compress-program", "zstd --compress --adapt=min=5,max=8", "--file", "-", "--directory", f.root, strings.TrimLeft(p, "/"))
if rc, err = cmd.StdoutPipe(); err != nil {
return
}
Expand Down
5 changes: 3 additions & 2 deletions provisioner/openstack/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (f *fs) SaveContainerLogs(containerId, p string) error {
))
}

// Archive returns a .tar.gz of the given path
// Archive returns a .tar.zst of the given path
func (f *fs) Archive(p string) (io.ReadCloser, error) {
session, err := f.ssh.NewSession()
if err != nil {
Expand All @@ -74,7 +74,8 @@ func (f *fs) Archive(p string) (io.ReadCloser, error) {

out := lo.Must(session.StdoutPipe())
if err = session.Start(fmt.Sprintf(
"tar -c -f - -z -C %s %s",
"tar --create --use-compress-program=%s --file - --directory %s %s",
shellescape.Quote("zstd --compress --adapt=min=5,max=8"),
shellescape.Quote(f.root),
shellescape.Quote(strings.TrimLeft(p, "/")),
)); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion server/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func preserveArtifacts(reader io.Reader, task *schedulerpkg.Task) error {
return fmt.Errorf("failed to create artifacts directory: %w", err)
}

artifactFile := fmt.Sprintf("%s.tar.gz", task.Name)
artifactFile := fmt.Sprintf("%s.tar.zst", task.Name)
file, err := os.OpenFile(path.Join(artifactsDir, artifactFile), os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return fmt.Errorf("failed to create artifact file: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion server/server_artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func (s *server) DownloadArtifact(req *proto.DownloadArtifactRequest, srv proto.Alfred_DownloadArtifactServer) error {
artifact := path.Join(dataRoot, "artifacts", req.Job, fmt.Sprintf("%s.tar.gz", req.Task))
artifact := path.Join(dataRoot, "artifacts", req.Job, fmt.Sprintf("%s.tar.zst", req.Task))

if _, err := os.Stat(artifact); err != nil {
return status.Errorf(codes.NotFound, "artifact not found")
Expand Down

0 comments on commit fc740b6

Please sign in to comment.