I am trying to create some packages from Build Artifacts using .NETCore LAMBDA function, facing some problems due to storage constraint LAMBDA temp storage is just 512 MB. My Artifacts(Zip file size is 300MB) structure is
./scripts.bat
./scripts2.yml
./Env/Svr1/somefile.txt
./Env/Svr1/somefolder/somefile.txt
./Env/Svr1/somefolder/someotherfolder/somefile.txt
Task is to copy scripts.bat and scripts2.yml to ./Env/Svr1/ and zip the contents of the Svr1(excluding other folders in ./Env/Svr2/..etc) as ./Svr1.zip at root level without unzip the whole zip as the storage is constraint.
var tempPath = @"/tmp/";
using (var file = File.OpenRead(tempPath+ "MyZipFile.zip"))
{
using (var zipFile = new ZipArchive(file, ZipArchiveMode.Read, true))
{
var ymlConfigs = zipFile.Entries.Select(f => f.Name).Where(en => en.EndsWith(".yml"));
var batFiles = zipFile.Entries.Select(f => f.Name).Where(en => en.EndsWith(".bat"));
var svr1Folder = zipFile.Entries.Select(folder => folder.FullName).Where(name => name.StartsWith("Env/Svr1"));
//add yml files to package
foreach (var ymlfile in ymlConfigs)
{
svr1Folder.Concat(new[] { ymlfile });
}
//add bat files to package
foreach (var batfile in batFiles)
{
svr1Folder.Concat(new[] { batfile });
}
//create zip package
var newZip = ZipFile.Open(tempPath + "Svr1", ZipArchiveMode.Update);
foreach (var item in svr1Folder)
{
newZip.CreateEntryFromFile(item, Path.GetFileName(item), CompressionLevel.Optimal);
//Error Could not find a part of the path as its looking for Item in Debug folder ..\bin\Debug\netcoreapp3.1\Env\Svr1\somefile.txt where as my item is in ./tmp/MyZipFile.zip
}
}
}