MCPcopy Create free account
hub / github.com/Scalingo/cli / uploadArchivePath

Function uploadArchivePath

deployments/deploy.go:77–105  ·  view source on GitHub ↗
(ctx context.Context, client *scalingo.Client, archivePath string)

Source from the content-addressed store, hash-verified

75}
76
77func uploadArchivePath(ctx context.Context, client *scalingo.Client, archivePath string) (string, error) {
78 archiveFd, err := os.OpenFile(archivePath, os.O_RDONLY, 0640)
79 if err != nil {
80 return "", errors.Wrapf(ctx, err, "open archive: %v", archivePath)
81 }
82 defer archiveFd.Close()
83
84 stat, err := archiveFd.Stat()
85 if err != nil {
86 return "", errors.Wrapf(ctx, err, "stat archive: %v", archivePath)
87 }
88
89 sources, err := client.SourcesCreate(ctx)
90 if err != nil {
91 return "", errors.Wrapf(ctx, err, "create source to upload archive")
92 }
93
94 res, err := uploadArchive(ctx, sources.UploadURL, archiveFd, stat.Size())
95 if err != nil {
96 return "", errors.Wrapf(ctx, err, "fail to upload archive: %v", archivePath)
97 }
98 defer res.Body.Close()
99 if res.StatusCode != http.StatusOK {
100 body, _ := io.ReadAll(res.Body)
101 return "", errors.Newf(ctx, "wrong status code after upload %s, body: %s", res.Status, string(body))
102 }
103
104 return sources.DownloadURL, nil
105}
106
107func uploadArchive(ctx context.Context, uploadURL string, archiveReader io.Reader, archiveSize int64) (*http.Response, error) {
108 scalingoio.Status("Uploading archive…")

Callers 1

DeployFunction · 0.85

Calls 1

uploadArchiveFunction · 0.85

Tested by

no test coverage detected