2121#include " ../overlaybd/lsmt/file.h"
2222#include " ../overlaybd/zfile/zfile.h"
2323#include " ../overlaybd/tar/tar_file.h"
24- #include " ../overlaybd/registryfs/registryfs.h"
25- #include " ../image_service.h"
2624#include < errno.h>
2725#include < fcntl.h>
2826#include < inttypes.h>
29- #include < memory>
3027#include < string>
3128#include < stdio.h>
3229#include < stdlib.h>
3330#include < sys/stat.h>
3431#include < sys/types.h>
3532#include < unistd.h>
3633#include " CLI11.hpp"
34+ #include " comm_func.h"
35+ #include " ../overlaybd/registryfs/registryfs.h"
36+
3737
3838using namespace std ;
3939using namespace LSMT ;
4040using namespace photon ::fs;
4141
42+ string commit_msg;
43+ string uuid, parent_uuid;
44+ std::string algorithm;
45+ int block_size = -1 ;
46+ std::string data_file_path, index_file_path, commit_file_path, remote_mapping_file;
47+ bool compress_zfile = false ;
48+ bool build_turboOCI = false ;
49+ bool build_fastoci = false ;
50+ bool tar = false , rm_old = false , seal = false , commit_sealed = false ;
51+ bool verbose = false ;
52+ int compress_threads = 1 ;
53+ std::string upload_url, cred_file_path, tls_key_path, tls_cert_path;
54+ ssize_t upload_bs = 262144 ;
55+
4256
4357IFile *open_file (IFileSystem *fs, const char *fn, int flags, mode_t mode = 0 ) {
4458 auto file = fs->open (fn, flags, mode);
@@ -50,19 +64,6 @@ IFile *open_file(IFileSystem *fs, const char *fn, int flags, mode_t mode = 0) {
5064}
5165
5266int main (int argc, char **argv) {
53- string commit_msg;
54- string uuid, parent_uuid;
55- std::string algorithm;
56- int block_size = -1 ;
57- std::string data_file_path, index_file_path, commit_file_path, remote_mapping_file;
58- bool compress_zfile = false ;
59- bool build_turboOCI = false ;
60- bool build_fastoci = false ;
61- bool tar = false , rm_old = false , seal = false , commit_sealed = false ;
62- bool verbose = false ;
63- int compress_threads = 1 ;
64- std::string upload_url, cred_file_path;
65- ssize_t upload_bs = 262144 ;
6667
6768 CLI::App app{" this is overlaybd-commit" };
6869 app.add_option (" -m" , commit_msg, " add some custom message if needed" );
@@ -87,10 +88,18 @@ int main(int argc, char **argv) {
8788 app.add_option (" --upload" , upload_url, " registry upload url" );
8889 app.add_option (" --upload_bs" , upload_bs, " block size for upload, in KB" );
8990 app.add_option (" --cred_file_path" , cred_file_path, " cred file path for registryfs" )->type_name (" FILEPATH" )->check (CLI::ExistingFile);
91+ app.add_option (" --tls_key_path" , tls_key_path, " TLSKeyPairPath for private Registry" )->type_name (" FILEPATH" )->check (CLI::ExistingFile);
92+ app.add_option (" --tls_cert_path" , tls_cert_path, " TLSCertPath for private Registry" )->type_name (" FILEPATH" )->check (CLI::ExistingFile);
93+
94+
9095
9196 CLI11_PARSE (app, argc, argv);
9297 build_turboOCI = build_turboOCI || build_fastoci;
9398 set_log_output_level (verbose ? 0 : 1 );
99+ if (tar && (upload_url.empty () == false )){
100+ fprintf (stderr, " unsupport option with '-t' and '--upload' at the same time." );
101+ exit (-1 );
102+ }
94103 photon::init (photon::INIT_EVENT_DEFAULT, photon::INIT_IO_DEFAULT);
95104 DEFER ({photon::fini ();});
96105
@@ -164,21 +173,10 @@ int main(int argc, char **argv) {
164173 zfile_args->overwrite_header = true ;
165174
166175 if (!upload_url.empty ()) {
167- zfile_args->overwrite_header = false ;
168- LOG_INFO (" upload to `" , upload_url);
169- std::string username, password;
170- if (load_cred_from_file (cred_file_path, upload_url, username, password) < 0 ) {
171- fprintf (stderr, " failed to read upload cred file\n " );
172- exit (-1 );
173- }
174- upload_builder = new_registry_uploader (out, upload_url, username, password, 2UL *60 *1000 *1000 , upload_bs*1024 );
175- if (upload_builder == nullptr ) {
176- fprintf (stderr, " failed to init upload\n " );
177- exit (-1 );
178- }
176+ LOG_INFO (" enable upload. URL: `, upload_bs: `, tls_key_path: `, tls_cert_path: `" , upload_url, upload_bs, tls_key_path, tls_cert_path);
177+ upload_builder = create_uploader (zfile_args, out, upload_url, cred_file_path, 2 , upload_bs, tls_key_path, tls_cert_path);
179178 out = upload_builder;
180179 }
181-
182180 zfile_builder = ZFile::new_zfile_builder (out, zfile_args, false );
183181 out = zfile_builder;
184182 } else {
@@ -213,12 +211,12 @@ int main(int argc, char **argv) {
213211 if (zfile_args) {
214212 delete zfile_args;
215213 }
216-
217- if (upload_builder != nullptr && upload_builder-> fsync () < 0 ) {
218- fprintf (stderr, " failed to commit or upload" );
219- return - 1 ;
220- }
221-
214+ string digest = " " ;
215+ if (upload_builder != nullptr && registry_uploader_fini (upload_builder, digest) != 0 ){
216+ fprintf (stderr, " failed to commit or upload\n " );
217+ exit (- 1 ) ;
218+ };
219+ fprintf (stderr, " %s \n " , digest. c_str ());
222220 delete upload_builder;
223221 delete fout;
224222 delete fin;
0 commit comments