Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload the package zip in chunks for GHA #1043

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cd70f77
Upload the package zip in chunks for GHA.
quyykk Apr 28, 2023
7fa81d1
Merge remote-tracking branch 'origin/main' into HEAD
BillyONeal Apr 28, 2023
df0a632
Merge remote-tracking branch 'upstream/main' into gha-upload-fixes
quyykk May 14, 2023
db160c1
Fix merge conflicts.
quyykk May 14, 2023
5f343b1
Address review comments
quyykk May 14, 2023
905209b
Fix formatting
quyykk May 14, 2023
77e5c79
Merge remote-tracking branch 'upstream/main' into gha-upload-fixes
quyykk Aug 30, 2023
68f9a6b
Merge remote-tracking branch 'upstream/main' into gha-upload-fixes
quyykk Aug 30, 2023
41d09b3
Pass the data through stdin instead of spliting the archive on disk.
quyykk Aug 30, 2023
d025512
Fix warning.
quyykk Aug 30, 2023
126232c
Fix formatting.
quyykk Aug 30, 2023
18868f1
Send the correct range in the HTTP request.
quyykk Aug 30, 2023
a1bf8c6
Merge remote-tracking branch 'upstream/main' into gha-upload-fixes
quyykk Sep 7, 2023
e6bf304
Some small cleanups.
quyykk Sep 7, 2023
6faa588
Merge remote-tracking branch 'upstream/main' into gha-upload-fixes
quyykk Sep 8, 2023
8b15edd
Address review comments.
quyykk Sep 9, 2023
1150fed
Format :/
quyykk Sep 9, 2023
dbed226
Update src/vcpkg/base/downloads.cpp
quyykk Sep 9, 2023
ef45cb8
More fixes.
quyykk Sep 9, 2023
e8bd3a0
Merge remote-tracking branch 'upstream/main' into gha-upload-fixes
quyykk Sep 14, 2023
a29b364
Merge remote-tracking branch 'upstream/main' into gha-upload-fixes
quyykk Oct 8, 2023
6e27717
Merge remote-tracking branch 'upstream/main' into gha-upload-fixes
quyykk Nov 11, 2023
710d38f
Merge remote-tracking branch 'upstream/main' into gha-upload-fixes
quyykk Nov 19, 2023
78b6bf3
Merge remote-tracking branch 'upstream/main' into gha-upload-fixes
quyykk Mar 11, 2024
2568af0
Format fixes.
quyykk Mar 11, 2024
d397db3
Apply suggestions from code review. Thanks!
quyykk Mar 12, 2024
608a72b
Format fixes.
quyykk Mar 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/vcpkg/archives.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ namespace vcpkg
const Path& archive_path);

std::vector<ExpectedL<Unit>> decompress_in_parallel(View<Command> jobs);

// Split an archive into chunks.
ExpectedL<Unit> split_archive(Filesystem& fs, const Path& path, int64_t file_size, int64_t chunk_size);
}
9 changes: 7 additions & 2 deletions include/vcpkg/base/downloads.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ namespace vcpkg
StringView url,
const std::vector<std::string>& secrets,
View<std::string> headers,
const Path& file,
StringView request = "PUT");
const Path& file);
ExpectedL<int> patch_file_in_pieces(Filesystem& fs,
StringView url,
View<std::string> headers,
const Path& file,
int64_t file_size,
unsigned int chunk_size = 450 * 1024 * 1024);
std::vector<int> url_heads(View<std::string> urls, View<std::string> headers, View<std::string> secrets);

struct DownloadManagerConfig
Expand Down
17 changes: 17 additions & 0 deletions src/vcpkg/archives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,21 @@ namespace vcpkg

return filtered_results;
}

ExpectedL<Unit> split_archive(Filesystem& fs, const Path& path, int64_t file_size, int64_t chunk_size)
{
auto file = fs.open_for_read(path, VCPKG_LINE_INFO);

std::vector<unsigned char> buffer(chunk_size);
quyykk marked this conversation as resolved.
Show resolved Hide resolved
for (int64_t begin = 0, i = 0; begin < file_size; begin += chunk_size, ++i)
{
auto bytes_read = file.read(buffer.data(), sizeof(unsigned char), chunk_size);
if (!bytes_read) break;

auto chunk_file = fs.open_for_write(path + std::to_string(i), VCPKG_LINE_INFO);
quyykk marked this conversation as resolved.
Show resolved Hide resolved
chunk_file.write(buffer.data(), sizeof(unsigned char), bytes_read);
}

return {Unit{}};
}
}
48 changes: 45 additions & 3 deletions src/vcpkg/base/downloads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <vcpkg/base/system.proxy.h>
#include <vcpkg/base/util.h>

#include <vcpkg/archives.h>

namespace vcpkg
{
static std::string replace_secrets(std::string input, View<std::string> secrets)
Expand Down Expand Up @@ -520,8 +522,7 @@ namespace vcpkg
StringView url,
const std::vector<std::string>& secrets,
View<std::string> headers,
const Path& file,
StringView request)
const Path& file)
{
static constexpr StringLiteral guid_marker = "9a1db05f-a65d-419b-aa72-037fb4d0672e";

Expand Down Expand Up @@ -550,7 +551,7 @@ namespace vcpkg
}

Command cmd;
cmd.string_arg("curl").string_arg("-X").string_arg(request);
cmd.string_arg("curl").string_arg("-X").string_arg("PUT");
for (auto&& header : headers)
{
cmd.string_arg("-H").string_arg(header);
Expand Down Expand Up @@ -579,6 +580,47 @@ namespace vcpkg
return res;
}

ExpectedL<int> patch_file_in_pieces(Filesystem& fs,
StringView url,
View<std::string> headers,
const Path& file,
int64_t file_size,
unsigned int chunk_size)
{
Command base_cmd;
base_cmd.string_arg("curl").string_arg("-X").string_arg("PATCH");
for (auto&& header : headers)
{
base_cmd.string_arg("-H").string_arg(header);
}
base_cmd.string_arg(url);

split_archive(fs, file, file_size, chunk_size);
quyykk marked this conversation as resolved.
Show resolved Hide resolved

int counter = 0;
for (int64_t i = 0; i < file_size; i += chunk_size, ++counter)
{
const int64_t end = std::min(i + chunk_size, file_size) - 1;
const std::string range = std::to_string(i) + "-" + std::to_string(end);

auto cmd = base_cmd;
cmd.string_arg("-H").string_arg("Content-Range: bytes " + range + "/" + std::to_string(file_size));
cmd.string_arg("-T").string_arg(file + std::to_string(counter));

auto res = cmd_execute_and_capture_output(cmd);
quyykk marked this conversation as resolved.
Show resolved Hide resolved
if (auto pres = res.get())
{
if (pres->exit_code == 0) continue;

Debug::print(pres->output, '\n');
quyykk marked this conversation as resolved.
Show resolved Hide resolved
return msg::format_error(
msgCurlFailedToPut, msg::exit_code = pres->exit_code, msg::url = url.to_string());
}
}

return 0;
}

#if defined(_WIN32)
enum class WinHttpTrialResult
{
Expand Down
8 changes: 2 additions & 6 deletions src/vcpkg/binarycaching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,13 +1130,9 @@ namespace
if (auto cacheId = reserve_cache_entry(abi, cache_size))
{
std::vector<std::string> headers{
m_token_header,
m_accept_header.to_string(),
"Content-Type: application/octet-stream",
"Content-Range: bytes 0-" + std::to_string(cache_size) + "/*",
};
m_token_header, m_accept_header.to_string(), "Content-Type: application/octet-stream"};
auto url = m_write_url + "/" + std::to_string(*cacheId.get());
if (put_file(fs, url, {}, headers, tmp_archive_path, "PATCH"))
if (patch_file_in_pieces(fs, url, headers, tmp_archive_path, cache_size))
{
Json::Object commit;
commit.insert("size", std::to_string(cache_size));
Expand Down