From ed8be10af05ff9a8b4ab14c985c6c935260cfe9a Mon Sep 17 00:00:00 2001 From: Joel Low Date: Thu, 17 Aug 2023 09:49:41 +0800 Subject: [PATCH] Replace `unzip` with `bsdtar` There are situations where a Zip archive from Sourcegraph causes the directory to be improperly recreated within the container. Using libarchive-tools fixes this. --- docker/batch-change-volume-workspace/Dockerfile | 2 +- internal/batches/workspace/volume_workspace.go | 2 +- internal/batches/workspace/volume_workspace_test.go | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docker/batch-change-volume-workspace/Dockerfile b/docker/batch-change-volume-workspace/Dockerfile index 0dc4340f64..969181eeda 100644 --- a/docker/batch-change-volume-workspace/Dockerfile +++ b/docker/batch-change-volume-workspace/Dockerfile @@ -4,4 +4,4 @@ FROM alpine:3.15.0@sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300 -RUN apk add --update git unzip +RUN apk add --update git libarchive-tools diff --git a/internal/batches/workspace/volume_workspace.go b/internal/batches/workspace/volume_workspace.go index 5cc8222a2f..84423ec9c8 100644 --- a/internal/batches/workspace/volume_workspace.go +++ b/internal/batches/workspace/volume_workspace.go @@ -153,7 +153,7 @@ func (wc *dockerVolumeWorkspaceCreator) unzipRepoIntoVolume(ctx context.Context, opts, DockerVolumeWorkspaceImage, "sh", "-c", - fmt.Sprintf("unzip /tmp/zip; rm /work/%s", dummy), + fmt.Sprintf("bsdtar -xf /tmp/zip && rm /work/%s", dummy), ) if out, err := exec.CommandContext(ctx, "docker", opts...).CombinedOutput(); err != nil { diff --git a/internal/batches/workspace/volume_workspace_test.go b/internal/batches/workspace/volume_workspace_test.go index 559d22aa67..4c418acbfd 100644 --- a/internal/batches/workspace/volume_workspace_test.go +++ b/internal/batches/workspace/volume_workspace_test.go @@ -85,7 +85,7 @@ func TestVolumeWorkspaceCreator(t *testing.T) { "--user", "0:0", "--mount", "type=volume,source="+volumeID+",target=/work", DockerVolumeWorkspaceImage, - "sh", "-c", "unzip /tmp/zip; rm /work/*", + "sh", "-c", "bsdtar -xf /tmp/zip && rm /work/*", ), expect.NewGlob( expect.Success, @@ -122,7 +122,7 @@ func TestVolumeWorkspaceCreator(t *testing.T) { "--user", "0:0", "--mount", "type=volume,source="+volumeID+",target=/work", DockerVolumeWorkspaceImage, - "sh", "-c", "unzip /tmp/zip; rm /work/*", + "sh", "-c", "bsdtar -xf /tmp/zip && rm /work/*", ), expect.NewGlob( expect.Success, @@ -163,7 +163,7 @@ func TestVolumeWorkspaceCreator(t *testing.T) { "--user", "1:2", "--mount", "type=volume,source="+volumeID+",target=/work", DockerVolumeWorkspaceImage, - "sh", "-c", "unzip /tmp/zip; rm /work/*", + "sh", "-c", "bsdtar -xf /tmp/zip && rm /work/*", ), expect.NewGlob( expect.Success, @@ -242,7 +242,7 @@ func TestVolumeWorkspaceCreator(t *testing.T) { "--user", "0:0", "--mount", "type=volume,source="+volumeID+",target=/work", DockerVolumeWorkspaceImage, - "sh", "-c", "unzip /tmp/zip; rm /work/*", + "sh", "-c", "bsdtar -xf /tmp/zip && rm /work/*", ), expect.NewGlob( expect.Behaviour{ExitCode: 1}, @@ -284,7 +284,7 @@ func TestVolumeWorkspaceCreator(t *testing.T) { "--user", "0:0", "--mount", "type=volume,source="+volumeID+",target=/work", DockerVolumeWorkspaceImage, - "sh", "-c", "unzip /tmp/zip; rm /work/*", + "sh", "-c", "bsdtar -xf /tmp/zip && rm /work/*", ), }, steps: []batcheslib.Step{ @@ -318,7 +318,7 @@ func TestVolumeWorkspaceCreator(t *testing.T) { "--user", "0:0", "--mount", "type=volume,source="+volumeID+",target=/work", DockerVolumeWorkspaceImage, - "sh", "-c", "unzip /tmp/zip; rm /work/*", + "sh", "-c", "bsdtar -xf /tmp/zip && rm /work/*", ), expect.NewGlob( expect.Success,