Skip to content

Commit 61aa5c9

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

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

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

Lines changed: 40 additions & 2 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

@@ -281,12 +282,12 @@ func (s3st *s3Storage) BackupObject(name string) string {
281282

282283
// Download implements DirectAccess
283284
func (s3st *s3Storage) Download(ctx context.Context, destination string, name string, mappings []archive.IDMapping) (found bool, err error) {
284-
return s3st.download(ctx, destination, s3st.objectName(name), mappings)
285+
return s3st.downloadS5cmd(ctx, destination, s3st.objectName(name), mappings)
285286
}
286287

287288
// DownloadSnapshot implements DirectAccess
288289
func (s3st *s3Storage) DownloadSnapshot(ctx context.Context, destination string, name string, mappings []archive.IDMapping) (found bool, err error) {
289-
return s3st.download(ctx, destination, name, mappings)
290+
return s3st.downloadS5cmd(ctx, destination, name, mappings)
290291
}
291292

292293
func (s3st *s3Storage) download(ctx context.Context, destination string, obj string, mappings []archive.IDMapping) (found bool, err error) {
@@ -323,6 +324,43 @@ func (s3st *s3Storage) download(ctx context.Context, destination string, obj str
323324
return true, nil
324325
}
325326

327+
// download object using s5cmd
328+
func (s3st *s3Storage) downloadS5cmd(ctx context.Context, destination string, obj string, mappings []archive.IDMapping) (found bool, err error) {
329+
tempFile, err := os.CreateTemp("", "temporal-s3-file")
330+
if err != nil {
331+
return true, xerrors.Errorf("creating temporal file: %s", err.Error())
332+
}
333+
tempFile.Close()
334+
335+
args := []string{
336+
"--numworkers", "20",
337+
"cp", "--part-size", "25",
338+
destination,
339+
tempFile.Name(),
340+
}
341+
cmd := exec.Command("s5cmd", args...)
342+
out, err := cmd.CombinedOutput()
343+
if err != nil {
344+
log.WithError(err).WithField("out", string(out)).Error("unexpected error downloading file")
345+
return true, xerrors.Errorf("unexpected error downloading file")
346+
}
347+
348+
tempFile, err = os.Open(tempFile.Name())
349+
if err != nil {
350+
return true, xerrors.Errorf("unexpected error opening downloaded file")
351+
}
352+
353+
defer os.Remove(tempFile.Name())
354+
defer tempFile.Close()
355+
356+
err = archive.ExtractTarbal(ctx, tempFile, destination, archive.WithUIDMapping(mappings), archive.WithGIDMapping(mappings))
357+
if err != nil {
358+
return true, xerrors.Errorf("tar %s: %s", destination, err.Error())
359+
}
360+
361+
return true, nil
362+
}
363+
326364
// EnsureExists implements DirectAccess
327365
func (*s3Storage) EnsureExists(ctx context.Context) error {
328366
return nil

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)