internal/worker: remove local analysis binary copy
Since we figured out how to let docker read from a GCS bucket
(see previous CL), we don't need to support local files.
Change-Id: I4093f1651a4b7ccb5c25ff2c334cce7c43899556
Reviewed-on: https://go-review.googlesource.com/c/pkgsite-metrics/+/472178
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
diff --git a/internal/worker/analysis.go b/internal/worker/analysis.go
index e27b449..54648a7 100644
--- a/internal/worker/analysis.go
+++ b/internal/worker/analysis.go
@@ -7,8 +7,8 @@
import (
"context"
"encoding/json"
+ "errors"
"fmt"
- "io"
"net/http"
"os"
"os/exec"
@@ -141,37 +141,18 @@
// copyBinary copies a binary from srcPath to destPath.
// If binaryBucket is non-empty, it reads srcPath from that GCS bucket.
-// If binaryBucket is empty, it reads srcPath from the local filesystem.
-// This is for testing, since a local docker container doesn't have the
-// credentials to read from a non-public bucket.
-func copyBinary(ctx context.Context, destPath, srcPath, binaryBucket string) (err error) {
+// If binaryBucket is empty, return an error.
+func copyBinary(ctx context.Context, destPath, srcPath, binaryBucket string) error {
if binaryBucket == "" {
- // Assume srcPath is local.
- srcf, err := os.Open(srcPath)
- if err != nil {
- return err
- }
- defer srcf.Close()
- destf, err := os.OpenFile(destPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755)
- if err != nil {
- return err
- }
- defer func() {
- err1 := destf.Close()
- if err == nil {
- err = err1
- }
- }()
- _, err = io.Copy(destf, srcf)
- return err
+ return errors.New("missing binary bucket (define GO_ECOSYSTEM_BINARY_BUCKET)")
}
- // Copy the binary from the bucket.
c, err := storage.NewClient(ctx)
if err != nil {
return err
}
bucket := c.Bucket(binaryBucket)
- return copyFromGCS(ctx, bucket, path.Join(analysisBinariesBucketDir, srcPath), destPath, true)
+ bucketPath := path.Join(analysisBinariesBucketDir, srcPath)
+ return copyFromGCS(ctx, bucket, bucketPath, destPath, true)
}
// Run the binary on the module.