public static async Task CreateImageAsync() { SystemPath root = imageLocation.GetRoot().ToPath(); SystemPath fileA = Files.CreateFile(root.Resolve("fileA.txt")); SystemPath fileB = Files.CreateFile(root.Resolve("fileB.txt")); SystemPath fileC = Files.CreateFile(root.Resolve("fileC.txt")); SystemPath subdir = Files.CreateDirectory(root.Resolve("dir")); SystemPath subsubdir = Files.CreateDirectory(subdir.Resolve("subdir")); Files.CreateFile(subdir.Resolve("fileD.txt")); Files.CreateFile(subsubdir.Resolve("fileE.txt")); imageTar = new FileInfo(Path.Combine(imageLocation.GetRoot().FullName, "image.tar")); Containerizer containerizer = Containerizer.To(TarImage.Named("fibdotnet-core/reproducible").SaveTo(imageTar.ToPath())); await FibContainerBuilder.FromScratch() .SetEntrypoint("echo", "Hello World") .AddLayer(ImmutableArray.Create(fileA), AbsoluteUnixPath.Get("/app")) // layer with out-of-order files .AddLayer(ImmutableArray.Create(fileC, fileB), "/app") .AddLayer( LayerConfiguration.CreateBuilder() .AddEntryRecursive(subdir, AbsoluteUnixPath.Get("/app")) .Build()) .ContainerizeAsync(containerizer).ConfigureAwait(false); }
public async Task TestFromFileAsync() { SystemPath fileA = Paths.Get(TestResources.GetResource("core/fileA").ToURI()); string expected = Encoding.UTF8.GetString(Files.ReadAllBytes(fileA)); await VerifyBlobWriteToAsync(expected, Blobs.From(fileA)).ConfigureAwait(false); }
public static void AppendText(SaveLocation saveLocation, string relativePath, string content) { var path = SystemPath.Combine(_saveLocations[saveLocation], relativePath).AbsolutePath; Directory.CreateDirectory(Path.GetDirectoryName(path)); File.AppendAllText(path, content); }
public void Test_fromJson() { // Loads the JSON string. SystemPath jsonFile = Paths.Get(TestResources.GetResource("core/json/dockerconfig.json").ToURI()); // Deserializes into a docker config JSON object. DockerConfig dockerConfig = new DockerConfig(JsonTemplateMapper.ReadJsonFromFile <DockerConfigTemplate>(jsonFile)); Assert.AreEqual("some:auth", DecodeBase64(dockerConfig.GetAuthFor("some registry"))); Assert.AreEqual( "some:other:auth", DecodeBase64(dockerConfig.GetAuthFor("some other registry"))); Assert.AreEqual("token", DecodeBase64(dockerConfig.GetAuthFor("registry"))); Assert.AreEqual("token", DecodeBase64(dockerConfig.GetAuthFor("https://registry"))); Assert.IsNull(dockerConfig.GetAuthFor("just registry")); Assert.AreEqual( Paths.Get("docker-credential-some credential store"), dockerConfig.GetCredentialHelperFor("some registry").GetCredentialHelper()); Assert.AreEqual( Paths.Get("docker-credential-some credential store"), dockerConfig.GetCredentialHelperFor("some other registry").GetCredentialHelper()); Assert.AreEqual( Paths.Get("docker-credential-some credential store"), dockerConfig.GetCredentialHelperFor("just registry").GetCredentialHelper()); Assert.AreEqual( Paths.Get("docker-credential-some credential store"), dockerConfig.GetCredentialHelperFor("with.protocol").GetCredentialHelper()); Assert.AreEqual( Paths.Get("docker-credential-another credential helper"), dockerConfig.GetCredentialHelperFor("another registry").GetCredentialHelper()); Assert.IsNull(dockerConfig.GetCredentialHelperFor("unknonwn registry")); }
/** * Writes a compressed layer {@link Blob}. * * <p>The {@code compressedLayerBlob} is written to the layer directory under the layers directory * corresponding to the layer blob. * * @param compressedLayerBlob the compressed layer {@link Blob} to write out * @return the {@link CachedLayer} representing the written entry * @throws IOException if an I/O exception occurs */ public async Task <CachedLayer> WriteCompressedAsync(IBlob compressedLayerBlob) { compressedLayerBlob = compressedLayerBlob ?? throw new ArgumentNullException(nameof(compressedLayerBlob)); // Creates the layers directory if it doesn't exist. Files.CreateDirectories(cacheStorageFiles.GetLayersDirectory()); // Creates the temporary directory. Files.CreateDirectories(cacheStorageFiles.GetTemporaryDirectory()); using (TemporaryDirectory temporaryDirectory = new TemporaryDirectory(cacheStorageFiles.GetTemporaryDirectory())) { SystemPath temporaryLayerDirectory = temporaryDirectory.GetDirectory(); // Writes the layer file to the temporary directory. WrittenLayer writtenLayer = await WriteCompressedLayerBlobToDirectoryAsync(compressedLayerBlob, temporaryLayerDirectory).ConfigureAwait(false); // Moves the temporary directory to the final location. temporaryDirectory.MoveIfDoesNotExist(cacheStorageFiles.GetLayerDirectory(writtenLayer.LayerDigest)); // Updates cachedLayer with the blob information. SystemPath layerFile = cacheStorageFiles.GetLayerFile(writtenLayer.LayerDigest, writtenLayer.LayerDiffId); return(CachedLayer.CreateBuilder() .SetLayerDigest(writtenLayer.LayerDigest) .SetLayerDiffId(writtenLayer.LayerDiffId) .SetLayerSize(writtenLayer.LayerSize) .SetLayerBlob(Blobs.From(layerFile)) .Build()); } }
public async Task TestBuild_timestampNonDefaultAsync() { SystemPath file = CreateFile(temporaryFolder.GetRoot().ToPath(), "fileA", "some content", 54321); IBlob blob = new ReproducibleLayerBuilder( ImmutableArray.Create( new LayerEntry( file, AbsoluteUnixPath.Get("/fileA"), FilePermissions.DefaultFilePermissions, Instant.FromUnixTimeSeconds(123)))) .Build(); SystemPath tarFile = temporaryFolder.NewFile().ToPath(); using (Stream @out = new BufferedStream(Files.NewOutputStream(tarFile))) { await blob.WriteToAsync(@out).ConfigureAwait(false); } // Reads the file back. using (TarInputStream @in = new TarInputStream(Files.NewInputStream(tarFile))) { Assert.AreEqual( (Instant.FromUnixTimeSeconds(0) + Duration.FromSeconds(123)).ToDateTimeUtc(), @in.GetNextEntry().TarHeader.ModTime); } }
public void TestSelect_invalidLayerDigest() { CacheStorageFiles cacheStorageFiles = new CacheStorageFiles(temporaryFolder.NewFolder().ToPath()); CacheStorageReader cacheStorageReader = new CacheStorageReader(cacheStorageFiles); DescriptorDigest selector = layerDigest1; SystemPath selectorFile = cacheStorageFiles.GetSelectorFile(selector); Files.CreateDirectories(selectorFile.GetParent()); Files.Write(selectorFile, Encoding.UTF8.GetBytes("not a valid layer digest")); try { cacheStorageReader.Select(selector); Assert.Fail("Should have thrown CacheCorruptedException"); } catch (CacheCorruptedException ex) { Assert.That( ex.Message, Does.StartWith( "Expected valid layer digest as contents of selector file `" + selectorFile + "` for selector `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa`, but got: not a valid layer digest")); } }
private string GetEmailBody(string templateName, RouteValueDictionary routeValues) { routeValues["controller"] = "EmailTemplates"; routeValues["action"] = templateName; var baseUri = new Uri(SystemPath.BaseUri()); var relativeUri = RouteTable.Routes.GetVirtualPath(new FakeRequestContext(), routeValues).VirtualPath; var address = new Uri(baseUri, relativeUri); try { using (var webClient = new WebClient()) return(webClient.DownloadString(address)); } catch (WebException ex) { if (!(ex.Response is HttpWebResponse)) { return("<p>{0}</p><pre>{1}</pre>".F(address, HttpUtility.HtmlEncode(ex.ToString()))); } using (TextReader reader = new StreamReader(ex.Response.As <HttpWebResponse>().GetResponseStream())) return(reader.ReadToEnd()); } catch (Exception ex) { return("<p>{0}</p><pre>{1}</pre>".F(address, HttpUtility.HtmlEncode(ex.ToString()))); } }
/** * Retrieves the {@link CachedLayer} for the layer with digest {@code layerDigest}. * * @param layerDigest the layer digest * @return the {@link CachedLayer} referenced by the layer digest, if found * @throws CacheCorruptedException if the cache was found to be corrupted * @throws IOException if an I/O exception occurs */ public Maybe <CachedLayer> Retrieve(DescriptorDigest layerDigest) { layerDigest = layerDigest ?? throw new ArgumentNullException(nameof(layerDigest)); SystemPath layerDirectory = cacheStorageFiles.GetLayerDirectory(layerDigest); if (!Files.Exists(layerDirectory)) { return(Maybe.Empty <CachedLayer>()); } CachedLayer.Builder cachedLayerBuilder = CachedLayer.CreateBuilder().SetLayerDigest(layerDigest); foreach (SystemPath fileInLayerDirectory in Files.List(layerDirectory)) { if (CacheStorageFiles.IsLayerFile(fileInLayerDirectory)) { if (cachedLayerBuilder.HasLayerBlob()) { throw new CacheCorruptedException( cacheStorageFiles.GetCacheDirectory(), "Multiple layer files found for layer with digest " + layerDigest.GetHash() + " in directory: " + layerDirectory); } cachedLayerBuilder .SetLayerBlob(Blobs.From(fileInLayerDirectory)) .SetLayerDiffId(cacheStorageFiles.GetDiffId(fileInLayerDirectory)) .SetLayerSize(Files.Size(fileInLayerDirectory)); } } return(Maybe.Of(cachedLayerBuilder.Build())); }
/** * Adds an entry to the layer. Only adds the single source file to the exact path in the * container file system. * * <p>For example, {@code addEntry(Paths.get("myfile"), * AbsoluteUnixPath.get("/path/in/container"))} adds a file {@code myfile} to the container file * system at {@code /path/in/container}. * * <p>For example, {@code addEntry(Paths.get("mydirectory"), * AbsoluteUnixPath.get("/path/in/container"))} adds a directory {@code mydirectory/} to the * container file system at {@code /path/in/container/}. This does <b>not</b> add the contents * of {@code mydirectory}. * * @param sourceFile the source file to add to the layer * @param pathInContainer the path in the container file system corresponding to the {@code * sourceFile} * @return this */ public Builder AddEntry(SystemPath sourceFile, AbsoluteUnixPath pathInContainer) { return(AddEntry( sourceFile, pathInContainer, DefaultFilePermissionsProvider(sourceFile, pathInContainer))); }
private async Task <FibContainer> BuildImageAsync( ImageReference baseImage, Containerizer containerizer, IList <string> additionalTags) { FibContainerBuilder containerBuilder = FibContainerBuilder.From(baseImage) .SetEntrypoint(new[] { "java", "-cp", "/app/resources:/app/classes:/app/libs/*", "HelloWorld" }) .SetProgramArguments(new List <string> { "An argument." }) .SetEnvironment(ImmutableDic.Of("env1", "envvalue1", "env2", "envvalue2")) .SetExposedPorts(Port.Parse(new[] { "1000", "2000-2002/tcp", "3000/udp" })) .SetLabels(ImmutableDic.Of("key1", "value1", "key2", "value2")) .SetLayers(fakeLayerConfigurations); SystemPath cacheDirectory = temporaryFolder.NewFolder().ToPath(); containerizer .SetBaseImageLayersCache(cacheDirectory) .SetApplicationLayersCache(cacheDirectory) .SetAllowInsecureRegistries(true) .SetToolName("fib-integration-test") .AddEventHandler <ProgressEvent>(progressChecker.progressEventHandler.Accept); foreach (string i in additionalTags) { containerizer.WithAdditionalTag(i); } return(await containerBuilder.ContainerizeAsync(containerizer).ConfigureAwait(false)); }
/** * Writes an uncompressed {@code layerBlob} to the {@code layerDirectory}. * * @param uncompressedLayerBlob the uncompressed layer {@link Blob} * @param layerDirectory the directory for the layer * @return a {@link WrittenLayer} with the written layer information * @throws IOException if an I/O exception occurs */ private async Task <WrittenLayer> WriteUncompressedLayerBlobToDirectoryAsync( IBlob uncompressedLayerBlob, SystemPath layerDirectory) { using (TemporaryFile temporaryLayerFile = CacheStorageFiles.GetTemporaryLayerFile(layerDirectory)) { DescriptorDigest layerDiffId; BlobDescriptor blobDescriptor; // Writes the layer with GZIP compression. The original bytes are captured as the layer's // diff ID and the bytes outputted from the GZIP compression are captured as the layer's // content descriptor. using (CountingDigestOutputStream compressedDigestOutputStream = new CountingDigestOutputStream( Files.NewOutputStream(temporaryLayerFile.Path))) { using (GZipStream compressorStream = new GZipStream(compressedDigestOutputStream, CompressionMode.Compress, true)) { BlobDescriptor descriptor = await uncompressedLayerBlob.WriteToAsync(compressorStream).ConfigureAwait(false); layerDiffId = descriptor.GetDigest(); } // The GZIPOutputStream must be closed in order to write out the remaining compressed data. blobDescriptor = compressedDigestOutputStream.ComputeDigest(); } DescriptorDigest layerDigest = blobDescriptor.GetDigest(); long layerSize = blobDescriptor.GetSize(); // Renames the temporary layer file to the correct filename. SystemPath layerFile = layerDirectory.Resolve(cacheStorageFiles.GetLayerFilename(layerDiffId)); temporaryLayerFile.MoveIfDoesNotExist(layerFile); return(new WrittenLayer(layerDigest, layerDiffId, layerSize)); } }
/// <summary> /// 根据系统实例返回菜单列表。 /// </summary> /// <param name="systemInstance">系统实例。</param> /// <returns>菜单列表。</returns> public static PowerItemCollection GetPowerSetting(SystemInstance systemInstance) { string key = "Power_"; if (systemInstance.SystemType == SystemType.Custom) { key += systemInstance.SystemId.ToString("d", System.Globalization.NumberFormatInfo.InvariantInfo); } else { key += systemInstance.SystemType.ToString(); } if (cacheSystemInstances[key] == null) { string path = SystemPath.GetPowerConfigPath(systemInstance); if (System.IO.File.Exists(path)) { PowerItemCollection list = Kenfor.KStar.Utility.Serialize.XmlSerializer.GetDeserializeObjectFromFile(path, typeof(PowerItemCollection)) as PowerItemCollection; cacheSystemInstances.Add(key, list, CacheItemPriority.Normal, null, new Microsoft.Practices.EnterpriseLibrary.Caching.Expirations.FileDependency(path)); } } return(cacheSystemInstances[key] as PowerItemCollection); }
public void ShouldCopyFileToDirectory() { SystemPath file1 = tempRoot.CreateEmptyFile("File1"); new SystemIoFileSystem().Copy(file1.ToString(), tempSubRoot.ToString()); Assert.IsTrue(tempSubRoot.Combine("File1").Exists()); }
private void CreateTempFiles(SystemPath path, string[] filenames) { foreach (string filename in filenames) { path.CreateEmptyFile(filename); } }
public void TestAddEntryRecursive_defaults() { SystemPath testDirectory = TestResources.GetResource("core/layer"); SystemPath testFile = TestResources.GetResource("core/fileA"); ILayerConfiguration layerConfiguration = LayerConfiguration.CreateBuilder() .AddEntryRecursive(testDirectory, AbsoluteUnixPath.Get("/app/layer/")) .AddEntryRecursive(testFile, AbsoluteUnixPath.Get("/app/fileA")) .Build(); ImmutableHashSet <LayerEntry> expectedLayerEntries = ImmutableHashSet.Create( DefaultLayerEntry(testDirectory, AbsoluteUnixPath.Get("/app/layer/")), DefaultLayerEntry(testDirectory.Resolve("a"), AbsoluteUnixPath.Get("/app/layer/a/")), DefaultLayerEntry( testDirectory.Resolve("a/b"), AbsoluteUnixPath.Get("/app/layer/a/b/")), DefaultLayerEntry( testDirectory.Resolve("a/b/bar"), AbsoluteUnixPath.Get("/app/layer/a/b/bar/")), DefaultLayerEntry(testDirectory.Resolve("c/"), AbsoluteUnixPath.Get("/app/layer/c")), DefaultLayerEntry( testDirectory.Resolve("c/cat/"), AbsoluteUnixPath.Get("/app/layer/c/cat")), DefaultLayerEntry(testDirectory.Resolve("foo"), AbsoluteUnixPath.Get("/app/layer/foo")), DefaultLayerEntry(testFile, AbsoluteUnixPath.Get("/app/fileA"))); CollectionAssert.AreEquivalent( expectedLayerEntries, ImmutableHashSet.CreateRange(layerConfiguration.LayerEntries)); }
/** * Adds a {@link TarArchiveEntry} if its extraction path does not exist yet. Also adds all of * the parent directories on the extraction path, if the parent does not exist. Parent will have * modified time to set to {@link LayerConfiguration#DEFAULT_MODIFIED_TIME}. * * @param tarArchiveEntry the {@link TarArchiveEntry} */ public void Add(TarEntry tarArchiveEntry) { if (names.Contains(tarArchiveEntry.Name)) { return; } // Adds all directories along extraction paths to explicitly set permissions for those // directories. SystemPath namePath = Paths.Get(tarArchiveEntry.Name); if (namePath.GetParent() != namePath.GetRoot()) { TarEntry dir = TarEntry.CreateTarEntry(namePath.GetParent().ToString().Replace(Path.DirectorySeparatorChar, '/')); dir.Name += "/"; dir.ModTime = DateTimeOffset.FromUnixTimeMilliseconds(LayerConfiguration.DefaultModifiedTime.ToUnixTimeMilliseconds()).DateTime; dir.TarHeader.Mode &= ~(int)PosixFilePermissions.All; dir.TarHeader.Mode |= (int)( PosixFilePermissions.OwnerAll | PosixFilePermissions.GroupReadExecute | PosixFilePermissions.OthersReadExecute); dir.TarHeader.TypeFlag = TarHeader.LF_DIR; Add(dir); } entries.Add(tarArchiveEntry); names.Add(tarArchiveEntry.Name); }
/** * Adds an entry to the layer. If the source file is a directory, the directory and its contents * will be added recursively. * * @param sourceFile the source file to add to the layer recursively * @param pathInContainer the path in the container file system corresponding to the {@code * sourceFile} * @param filePermissionProvider a provider that takes a source path and destination path on the * container and returns the file permissions that should be set for that path * @param lastModifiedTimeProvider a provider that takes a source path and destination path on * the container and returns the file modification time that should be set for that path * @return this * @throws IOException if an exception occurred when recursively listing the directory */ public Builder AddEntryRecursive( SystemPath sourceFile, AbsoluteUnixPath pathInContainer, Func <SystemPath, AbsoluteUnixPath, FilePermissions> filePermissionProvider, Func <SystemPath, AbsoluteUnixPath, Instant> lastModifiedTimeProvider) { FilePermissions permissions = filePermissionProvider?.Invoke(sourceFile, pathInContainer); Instant modifiedTime = lastModifiedTimeProvider(sourceFile, pathInContainer); AddEntry(sourceFile, pathInContainer, permissions, modifiedTime); if (!Files.IsDirectory(sourceFile)) { return(this); } IEnumerable <SystemPath> files = Files.List(sourceFile); { foreach (SystemPath file in files.ToList()) { AddEntryRecursive( file, pathInContainer.Resolve(file.GetFileName()), filePermissionProvider, lastModifiedTimeProvider); } } return(this); }
public void ReadEmptyFile() { SystemPath filename = tempDir.CreateEmptyFile("ReadEmptyFile.log"); ServerLogFileReader reader = new ServerLogFileReader(filename.ToString(), 10); Assert.AreEqual("", reader.Read(), "Error reading empty log file"); }
public void TestReadJsonWithLock() { SystemPath jsonFile = Paths.Get(TestResources.GetResource("core/json/basic.json").ToURI()); // Deserializes into a metadata JSON object. TestJson testJson = JsonTemplateMapper.ReadJsonFromFileWithLock <TestJson>(jsonFile); Assert.AreEqual(testJson.Number, 54); Assert.AreEqual(testJson.Text, "crepecake"); Assert.AreEqual( testJson.Digest, DescriptorDigest.FromDigest( "sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad")); Assert.IsInstanceOf <TestJson.InnerObjectClass>(testJson.InnerObject); Assert.AreEqual(testJson.InnerObject.Number, 23); Assert.AreEqual( testJson.InnerObject.Texts, new[] { "first text", "second text" }); Assert.AreEqual(testJson.InnerObject.Digests, new[] { DescriptorDigest.FromDigest("sha256:91e0cae00b86c289b33fee303a807ae72dd9f0315c16b74e6ab0cdbe9d996c10"), DescriptorDigest.FromHash("4945ba5011739b0b98c4a41afe224e417f47c7c99b2ce76830999c9a0861b236") }); // ignore testJson.list }
public void TestReadListOfJson() { SystemPath jsonFile = Paths.Get(TestResources.GetResource("core/json/basic_list.json").ToURI()); string jsonString = Encoding.UTF8.GetString(Files.ReadAllBytes(jsonFile)); IList <TestJson> listofJsons = JsonTemplateMapper.ReadListOfJson <TestJson>(jsonString); TestJson json1 = listofJsons[0]; TestJson json2 = listofJsons[1]; DescriptorDigest digest1 = DescriptorDigest.FromDigest( "sha256:91e0cae00b86c289b33fee303a807ae72dd9f0315c16b74e6ab0cdbe9d996c10"); DescriptorDigest digest2 = DescriptorDigest.FromDigest( "sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad"); Assert.AreEqual(1, json1.Number); Assert.AreEqual(2, json2.Number); Assert.AreEqual("text1", json1.Text); Assert.AreEqual("text2", json2.Text); Assert.AreEqual(digest1, json1.Digest); Assert.AreEqual(digest2, json2.Digest); Assert.AreEqual(10, json1.InnerObject.Number); Assert.AreEqual(20, json2.InnerObject.Number); Assert.AreEqual(2, json1.List.Count); Assert.IsTrue(json2.List.Count == 0); }
public async Task SetUpAsync() { SystemPath directory = temporaryFolder.NewFolder().ToPath(); Files.CreateDirectory(directory.Resolve("source")); Files.CreateFile(directory.Resolve("source/file")); Files.CreateDirectories(directory.Resolve("another/source")); Files.CreateFile(directory.Resolve("another/source/file")); layerBlob1 = Blobs.From("layerBlob1"); layerDigest1 = await DigestOfAsync(Compress(layerBlob1)).ConfigureAwait(false); layerDiffId1 = await DigestOfAsync(layerBlob1).ConfigureAwait(false); layerSize1 = await SizeOfAsync(Compress(layerBlob1)).ConfigureAwait(false); layerEntries1 = ImmutableArray.Create( DefaultLayerEntry( directory.Resolve("source/file"), AbsoluteUnixPath.Get("/extraction/path")), DefaultLayerEntry( directory.Resolve("another/source/file"), AbsoluteUnixPath.Get("/another/extraction/path"))); layerBlob2 = Blobs.From("layerBlob2"); layerDigest2 = await DigestOfAsync(Compress(layerBlob2)).ConfigureAwait(false); layerDiffId2 = await DigestOfAsync(layerBlob2).ConfigureAwait(false); layerSize2 = await SizeOfAsync(Compress(layerBlob2)).ConfigureAwait(false); layerEntries2 = ImmutableArray.Create <LayerEntry>(); }
/** * Retrieves the layer digest selected by the {@code selector}. * * @param selector the selector * @return the layer digest {@code selector} selects, if found * @throws CacheCorruptedException if the selector file contents was not a valid layer digest * @throws IOException if an I/O exception occurs */ public Maybe <DescriptorDigest> Select(DescriptorDigest selector) { selector = selector ?? throw new ArgumentNullException(nameof(selector)); SystemPath selectorFile = cacheStorageFiles.GetSelectorFile(selector); if (!Files.Exists(selectorFile)) { return(Maybe.Empty <DescriptorDigest>()); } string selectorFileContents = File.ReadAllText(selectorFile.ToFile().FullName, Encoding.UTF8); try { return(Maybe.Of(DescriptorDigest.FromHash(selectorFileContents))); } catch (DigestException) { throw new CacheCorruptedException( cacheStorageFiles.GetCacheDirectory(), "Expected valid layer digest as contents of selector file `" + selectorFile + "` for selector `" + selector.GetHash() + "`, but got: " + selectorFileContents); } }
public void TestToJson() { // Loads the expected JSON string. SystemPath jsonFile = Paths.Get(TestResources.GetResource("core/json/containerconfig.json").ToURI()); string expectedJson = Encoding.UTF8.GetString(Files.ReadAllBytes(jsonFile)); // Creates the JSON object to serialize. ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate { Created = "1970-01-01T00:00:20Z", Architecture = "wasm", Os = "js" }; containerConfigJson.SetContainerEnvironment(new[] { "VAR1=VAL1", "VAR2=VAL2" }); containerConfigJson.SetContainerEntrypoint(new[] { "some", "entrypoint", "command" }); containerConfigJson.SetContainerCmd(new[] { "arg1", "arg2" }); containerConfigJson.SetContainerHealthCheckTest(new[] { "CMD-SHELL", "/checkhealth" }); containerConfigJson.SetContainerHealthCheckInterval(3000000000L); containerConfigJson.SetContainerHealthCheckTimeout(1000000000L); containerConfigJson.SetContainerHealthCheckStartPeriod(2000000000L); containerConfigJson.SetContainerHealthCheckRetries(3); containerConfigJson.SetContainerExposedPorts( new Dictionary <string, IDictionary <object, object> > { ["1000/tcp"] = ImmutableDictionary.Create <object, object>(), ["2000/tcp"] = ImmutableDictionary.Create <object, object>(), ["3000/udp"] = ImmutableDictionary.Create <object, object>() }.ToImmutableSortedDictionary()); containerConfigJson.SetContainerLabels(ImmutableDic.Of("key1", "value1", "key2", "value2")); containerConfigJson.SetContainerVolumes( ImmutableDic.Of <string, IDictionary <object, object> >( "/var/job-result-data", ImmutableDictionary.Create <object, object>(), "/var/log/my-app-logs", ImmutableDictionary.Create <object, object>())); containerConfigJson.SetContainerWorkingDir("/some/workspace"); containerConfigJson.SetContainerUser("tomcat"); containerConfigJson.AddLayerDiffId( DescriptorDigest.FromDigest( "sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad")); containerConfigJson.AddHistoryEntry( HistoryEntry.CreateBuilder() .SetCreationTimestamp(Instant.FromUnixTimeSeconds(0)) .SetAuthor("Bazel") .SetCreatedBy("bazel build ...") .SetEmptyLayer(true) .Build()); containerConfigJson.AddHistoryEntry( HistoryEntry.CreateBuilder() .SetCreationTimestamp(Instant.FromUnixTimeSeconds(20)) .SetAuthor("Fib") .SetCreatedBy("fib") .Build()); // Serializes the JSON object. Assert.AreEqual(expectedJson, JsonTemplateMapper.ToUtf8String(containerConfigJson)); }
public void ReadSingleLineFromLogFile() { string content = @"SampleLine"; SystemPath filename = tempDir.CreateTextFile("ReadSingleLineFromLogFile.log", content); ServerLogFileReader reader = new ServerLogFileReader(filename.ToString(), 10); Assert.AreEqual(content, reader.Read()); }
/** * Adds an entry to the layer. If the source file is a directory, the directory and its contents * will be added recursively. * * @param sourceFile the source file to add to the layer recursively * @param pathInContainer the path in the container file system corresponding to the {@code * sourceFile} * @param filePermissionProvider a provider that takes a source path and destination path on the * container and returns the file permissions that should be set for that path * @return this * @throws IOException if an exception occurred when recursively listing the directory */ public Builder AddEntryRecursive( SystemPath sourceFile, AbsoluteUnixPath pathInContainer, Func <SystemPath, AbsoluteUnixPath, FilePermissions> filePermissionProvider) { return(AddEntryRecursive( sourceFile, pathInContainer, filePermissionProvider, DefaultModifiedTimeProvider)); }
public CacheCorruptedException(SystemPath cacheDirectory, string message, Exception cause) : base( $"{message}. " + $"You may need to clear the cache by deleting the '{cacheDirectory}' directory " + $"(if this is a bug, please file an issue at {ProjectInfo.GitHubNewIssueUrl})", cause) { }
/** * Deserializes a JSON file via a JSON object template. * * @param <T> child type of {@link JsonTemplate} * @param jsonFile a file containing a JSON string * @param templateClass the template to deserialize the string to * @return the template filled with the values parsed from {@code jsonFile} * @throws IOException if an error occurred during reading the file or parsing the JSON */ public static T ReadJsonFromFile <T>(SystemPath jsonFile) { jsonFile = jsonFile ?? throw new ArgumentNullException(nameof(jsonFile)); using (StreamReader reader = jsonFile.ToFile().OpenText()) { return(JsonConvert.DeserializeObject <T>(reader.ReadToEnd())); } }
public void ShouldAllowOverwrites() { SystemPath sourceFile = tempRoot.CreateEmptyFile("File1"); SystemPath targetFile = tempSubRoot.CreateEmptyFile("File2"); new SystemIoFileSystem().Copy(sourceFile.ToString(), targetFile.ToString()); Assert.IsTrue(targetFile.Exists()); }
private static LayerEntry DefaultLayerEntry(SystemPath source, AbsoluteUnixPath destination) { return(new LayerEntry( source, destination, LayerConfiguration.DefaultFilePermissionsProvider(source, destination), LayerConfiguration.DefaultModifiedTime)); }