Browse Source
Added support for volume mapping docker containers (#156)
- This also works when you run projects as containers.
pull/158/head
David Fowler
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with
44 additions and
5 deletions
-
src/Microsoft.Tye.Hosting/DockerRunner.cs
-
src/Microsoft.Tye.Hosting/Model/ProjectRunInfo.cs
-
src/Microsoft.Tye.Hosting/TransformProjectsIntoContainers.cs
-
src/tye/ConfigModel/ConfigApplication.cs
-
src/tye/ConfigModel/ConfigService.cs
-
src/tye/ConfigModel/ConfigVolume.cs
-
src/tye/InitHost.cs
-
src/tye/tye.csproj
|
|
|
@ -129,7 +129,8 @@ namespace Microsoft.Tye.Hosting |
|
|
|
|
|
|
|
foreach (var pair in docker.VolumeMappings) |
|
|
|
{ |
|
|
|
volumes += $"-v {pair.Key}:{pair.Value} "; |
|
|
|
var sourcePath = Path.GetFullPath(Path.Combine(application.ContextDirectory, pair.Key.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar))); |
|
|
|
volumes += $"-v {sourcePath}:{pair.Value} "; |
|
|
|
} |
|
|
|
|
|
|
|
var command = $"run -d {workingDirectory} {volumes} {environmentArguments} {portString} --name {replica} --restart=unless-stopped {docker.Image} {docker.Args ?? ""}"; |
|
|
|
|
|
|
|
@ -2,6 +2,8 @@ |
|
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
|
|
namespace Microsoft.Tye.Hosting.Model |
|
|
|
{ |
|
|
|
public class ProjectRunInfo : RunInfo |
|
|
|
@ -16,5 +18,8 @@ namespace Microsoft.Tye.Hosting.Model |
|
|
|
public string? Args { get; } |
|
|
|
public bool Build { get; } |
|
|
|
public string Project { get; } |
|
|
|
|
|
|
|
// This exists for running projects as containers
|
|
|
|
public Dictionary<string, string> VolumeMappings { get; } = new Dictionary<string, string>(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -75,6 +75,12 @@ namespace Microsoft.Tye.Hosting |
|
|
|
}; |
|
|
|
dockerRunInfo.VolumeMappings[Path.GetDirectoryName(service.Status.ProjectFilePath)!] = "/app"; |
|
|
|
|
|
|
|
// Make volume mapping works when running as a container
|
|
|
|
foreach (var mapping in project.VolumeMappings) |
|
|
|
{ |
|
|
|
dockerRunInfo.VolumeMappings[mapping.Key] = mapping.Value; |
|
|
|
} |
|
|
|
|
|
|
|
// Change the project into a container info
|
|
|
|
serviceDescription.RunInfo = dockerRunInfo; |
|
|
|
} |
|
|
|
|
|
|
|
@ -34,7 +34,14 @@ namespace Microsoft.Tye.ConfigModel |
|
|
|
} |
|
|
|
else if (service.DockerImage is object) |
|
|
|
{ |
|
|
|
runInfo = new DockerRunInfo(service.DockerImage, service.Args); |
|
|
|
var dockerRunInfo = new DockerRunInfo(service.DockerImage, service.Args); |
|
|
|
|
|
|
|
foreach (var mapping in service.Volumes) |
|
|
|
{ |
|
|
|
dockerRunInfo.VolumeMappings[mapping.Source!] = mapping.Target!; |
|
|
|
} |
|
|
|
|
|
|
|
runInfo = dockerRunInfo; |
|
|
|
} |
|
|
|
else if (service.Executable is object) |
|
|
|
{ |
|
|
|
@ -42,7 +49,14 @@ namespace Microsoft.Tye.ConfigModel |
|
|
|
} |
|
|
|
else if (service.Project is object) |
|
|
|
{ |
|
|
|
runInfo = new ProjectRunInfo(service.Project, service.Args, service.Build ?? true); |
|
|
|
var projectInfo = new ProjectRunInfo(service.Project, service.Args, service.Build ?? true); |
|
|
|
|
|
|
|
foreach (var mapping in service.Volumes) |
|
|
|
{ |
|
|
|
projectInfo.VolumeMappings[mapping.Source!] = mapping.Target!; |
|
|
|
} |
|
|
|
|
|
|
|
runInfo = projectInfo; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
|
|
|
|
@ -21,7 +21,7 @@ namespace Microsoft.Tye.ConfigModel |
|
|
|
public string? Args { get; set; } |
|
|
|
public int? Replicas { get; set; } |
|
|
|
public List<ConfigServiceBinding> Bindings { get; set; } = new List<ConfigServiceBinding>(); |
|
|
|
|
|
|
|
public List<ConfigVolume> Volumes { get; set; } = new List<ConfigVolume>(); |
|
|
|
[YamlMember(Alias = "env")] |
|
|
|
public List<ConfigConfigurationSource> Configuration { get; set; } = new List<ConfigConfigurationSource>(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -0,0 +1,12 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Text; |
|
|
|
|
|
|
|
namespace Microsoft.Tye.ConfigModel |
|
|
|
{ |
|
|
|
public class ConfigVolume |
|
|
|
{ |
|
|
|
public string? Source { get; set; } |
|
|
|
public string? Target { get; set; } |
|
|
|
} |
|
|
|
} |
|
|
|
@ -75,6 +75,7 @@ services: |
|
|
|
{ |
|
|
|
service.Bindings = null!; |
|
|
|
service.Configuration = null!; |
|
|
|
service.Volumes = null!; |
|
|
|
service.Project = service.Project!.Substring(directory.FullName.Length).TrimStart('/'); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -3,7 +3,7 @@ |
|
|
|
<PropertyGroup> |
|
|
|
<OutputType>Exe</OutputType> |
|
|
|
<TargetFramework>netcoreapp3.1</TargetFramework> |
|
|
|
<RootNamespace>Tye</RootNamespace> |
|
|
|
<RootNamespace>Microsoft.Tye</RootNamespace> |
|
|
|
<AssemblyName>tye</AssemblyName> |
|
|
|
<PackageId>Microsoft.Tye</PackageId> |
|
|
|
<ToolCommandName>tye</ToolCommandName> |
|
|
|
|