Skip to content

Commit b808abd

Browse files
committed
[content-service] download s3 content using s5cmd
Fixes ENG-884
1 parent 0a44cfa commit b808abd

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

components/content-service/pkg/storage/s3.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"errors"
1010
"fmt"
1111
"os"
12+
"os/exec"
1213
"path/filepath"
1314
"strings"
1415

@@ -289,33 +290,36 @@ func (s3st *s3Storage) DownloadSnapshot(ctx context.Context, destination string,
289290
return s3st.download(ctx, destination, name, mappings)
290291
}
291292

293+
// download object using s5cmd (prior to which we used aws sdk)
292294
func (s3st *s3Storage) download(ctx context.Context, destination string, obj string, mappings []archive.IDMapping) (found bool, err error) {
293-
downloader := s3manager.NewDownloader(s3st.client, func(d *s3manager.Downloader) {
294-
d.Concurrency = defaultCopyConcurrency
295-
d.PartSize = defaultPartSize * megabytes
296-
d.BufferProvider = s3manager.NewPooledBufferedWriterReadFromProvider(25 * megabytes)
297-
})
298-
299-
s3File, err := os.CreateTemp("", "temporal-s3-file")
295+
tempFile, err := os.CreateTemp("", "temporal-s3-file")
300296
if err != nil {
301297
return true, xerrors.Errorf("creating temporal file: %s", err.Error())
302298
}
303-
defer os.Remove(s3File.Name())
299+
tempFile.Close()
304300

305-
_, err = downloader.Download(ctx, s3File, &s3.GetObjectInput{
306-
Bucket: aws.String(s3st.Config.Bucket),
307-
Key: aws.String(obj),
308-
})
301+
args := []string{
302+
"--numworkers", "20",
303+
"cp", "--part-size", "25",
304+
destination,
305+
tempFile.Name(),
306+
}
307+
cmd := exec.Command("s5cmd", args...)
308+
out, err := cmd.CombinedOutput()
309309
if err != nil {
310-
return false, err
310+
log.WithError(err).WithField("out", string(out)).Error("unexpected error downloading file")
311+
return true, xerrors.Errorf("unexpected error downloading file")
311312
}
312313

313-
_, err = s3File.Seek(0, 0)
314+
tempFile, err = os.Open(tempFile.Name())
314315
if err != nil {
315-
return false, err
316+
return true, xerrors.Errorf("unexpected error opening downloaded file")
316317
}
317318

318-
err = archive.ExtractTarbal(ctx, s3File, destination, archive.WithUIDMapping(mappings), archive.WithGIDMapping(mappings))
319+
defer os.Remove(tempFile.Name())
320+
defer tempFile.Close()
321+
322+
err = archive.ExtractTarbal(ctx, tempFile, destination, archive.WithUIDMapping(mappings), archive.WithGIDMapping(mappings))
319323
if err != nil {
320324
return true, xerrors.Errorf("tar %s: %s", destination, err.Error())
321325
}

components/ws-daemon/leeway.Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ RUN apk add --no-cache curl file \
99
&& chmod +x runc.amd64 \
1010
&& if ! file runc.amd64 | grep -iq "ELF 64-bit LSB pie executable"; then echo "runc.amd64 is not a binary file"; exit 1;fi
1111

12+
RUN curl -OsSL https://github.com/peak/s5cmd/releases/download/v2.2.2/s5cmd_2.2.2_Linux-64bit.tar.gz \
13+
&& tar -xzvf s5cmd_2.2.2_Linux-64bit.tar.gz s5cmd \
14+
&& chmod +x s5cmd \
15+
&& if ! file s5cmd | grep -iq "ELF 64-bit LSB pie executable"; then echo "s5cmd is not a binary file"; exit 1;fi
16+
1217
FROM ubuntu:22.04
1318

1419
# trigger manual rebuild increasing the value
@@ -46,6 +51,7 @@ RUN apt update \
4651
/var/tmp/*
4752

4853
COPY --from=dl /dl/runc.amd64 /usr/bin/runc
54+
COPY --from=dl /dl/s5cmd /usr/bin/s5cmd
4955

5056
# Add gitpod user for operations (e.g. checkout because of the post-checkout hook!)
5157
RUN groupadd -r -g 33333 gitpod \

0 commit comments

Comments
 (0)