コード例 #1
0
        private static void ResolveVolumes(Dictionary <object, object> s, ComposeServiceDefinition composeServiceDefinition)
        {
            if (!s.ContainsKey("volumes"))
            {
                return;
            }

            foreach (var volume in (List <object>)s["volumes"])
            {
                switch (volume)
                {
                case string vSting:
                {
                    var shortServiceVolumeDefinition = new ShortServiceVolumeDefinition
                    {
                        Entry = vSting
                    };
                    composeServiceDefinition.Volumes.Add(shortServiceVolumeDefinition);
                    break;
                }

                case Dictionary <object, object> vDictionary:
                {
                    var longServiceVolumeDefinition = new LongServiceVolumeDefinition();

                    var bindType = (string)vDictionary["type"];
                    Enum.TryParse(bindType, true, out VolumeType b);

                    longServiceVolumeDefinition.Type   = b;
                    longServiceVolumeDefinition.Source = (string)vDictionary["source"];
                    longServiceVolumeDefinition.Target = (string)vDictionary["target"];

                    composeServiceDefinition.Volumes.Add(longServiceVolumeDefinition);
                    break;
                }
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///   Creates a new volume at the service level.
        /// </summary>
        /// <param name="containerPath">The path inside container.</param>
        /// <param name="hostPath">Either host path or name of the volume.</param>
        /// <param name="isReadonly">If volume is readonly or not. Default false.</param>
        /// <param name="options">If any options, even are name and odd ar it's corresponding value.</param>
        /// <returns>Itself for fluent access.</returns>
        public ComposeServiceBuilder Volume(TemplateString containerPath, TemplateString hostPath,
                                            bool isReadonly = false, params string[] options)
        {
            var volume = new LongServiceVolumeDefinition
            {
                Source     = $"{hostPath.Rendered.EscapePath()}",
                Target     = $"{containerPath.Rendered.EscapePath()}",
                IsReadOnly = isReadonly
            };

            _config.Volumes.Add(volume);

            if (null == options || 0 == options.Length)
            {
                return(this);
            }

            for (var i = 0; i < options.Length; i++)
            {
                volume.Options.Add(options[i], options[i + 1]);
            }

            return(this);
        }