Shayne Boyer
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with
71 additions and
8 deletions
-
src/Microsoft.Tye.Core/ApplicationFactory.cs
-
src/Microsoft.Tye.Core/DockerfileGenerator.cs
-
src/Microsoft.Tye.Core/ProjectReader.cs
-
src/Microsoft.Tye.Hosting/Model/ProjectRunInfo.cs
-
src/Microsoft.Tye.Hosting/TransformProjectsIntoContainers.cs
-
test/E2ETest/TyeRunTests.cs
-
test/E2ETest/testassets/projects/frontend-backend/backend/backend-baseimage.csproj
|
|
|
@ -96,12 +96,12 @@ namespace Microsoft.Tye |
|
|
|
} |
|
|
|
project.Replicas = configService.Replicas ?? 1; |
|
|
|
|
|
|
|
await ProjectReader.ReadProjectDetailsAsync(output, project); |
|
|
|
|
|
|
|
// We don't apply more container defaults here because we might need
|
|
|
|
// to prompt for the registry name.
|
|
|
|
project.ContainerInfo = new ContainerInfo() { UseMultiphaseDockerfile = false, }; |
|
|
|
|
|
|
|
await ProjectReader.ReadProjectDetailsAsync(output, project); |
|
|
|
|
|
|
|
// Do k8s by default.
|
|
|
|
project.ManifestInfo = new KubernetesManifestInfo(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -92,21 +92,21 @@ namespace Microsoft.Tye |
|
|
|
throw new ArgumentNullException(nameof(container)); |
|
|
|
} |
|
|
|
|
|
|
|
if (container.BaseImageName == null && project.IsAspNet) |
|
|
|
if (string.IsNullOrEmpty(container.BaseImageName) && project.IsAspNet) |
|
|
|
{ |
|
|
|
container.BaseImageName = "mcr.microsoft.com/dotnet/core/aspnet"; |
|
|
|
} |
|
|
|
else if (container.BaseImageName == null) |
|
|
|
else if (string.IsNullOrEmpty(container.BaseImageName)) |
|
|
|
{ |
|
|
|
container.BaseImageName = "mcr.microsoft.com/dotnet/core/runtime"; |
|
|
|
} |
|
|
|
|
|
|
|
if (container.BaseImageTag == null && project.TargetFrameworkName == "netcoreapp") |
|
|
|
if (string.IsNullOrEmpty(container.BaseImageTag) && project.TargetFrameworkName == "netcoreapp") |
|
|
|
{ |
|
|
|
container.BaseImageTag = project.TargetFrameworkVersion; |
|
|
|
} |
|
|
|
|
|
|
|
if (container.BaseImageTag == null) |
|
|
|
if (string.IsNullOrEmpty(container.BaseImageTag)) |
|
|
|
{ |
|
|
|
throw new CommandException($"Unsupported TFM {project.TargetFramework}."); |
|
|
|
} |
|
|
|
|
|
|
|
@ -268,6 +268,13 @@ namespace Microsoft.Tye |
|
|
|
project.Frameworks.AddRange(sharedFrameworks.Select(s => new Framework(s))); |
|
|
|
output.WriteDebugLine($"Found shared frameworks: {string.Join(", ", sharedFrameworks)}"); |
|
|
|
|
|
|
|
// determine container base image
|
|
|
|
if (project.ContainerInfo != null) |
|
|
|
{ |
|
|
|
project.ContainerInfo.BaseImageName = projectInstance.GetPropertyValue("ContainerBaseImage"); |
|
|
|
project.ContainerInfo.BaseImageTag = projectInstance.GetPropertyValue("ContainerBaseTag"); |
|
|
|
} |
|
|
|
|
|
|
|
bool PropertyIsTrue(string property) |
|
|
|
{ |
|
|
|
return projectInstance.GetPropertyValue(property) is string s && !string.IsNullOrEmpty(s) && bool.Parse(s); |
|
|
|
|
|
|
|
@ -24,6 +24,8 @@ namespace Microsoft.Tye.Hosting.Model |
|
|
|
RunCommand = project.RunCommand; |
|
|
|
RunArguments = project.RunArguments; |
|
|
|
PublishOutputPath = project.PublishDir; |
|
|
|
ContainerBaseImage = project.ContainerInfo?.BaseImageName; |
|
|
|
ContainerBaseTag = project.ContainerInfo?.BaseImageTag; |
|
|
|
IsAspNet = project.IsAspNet; |
|
|
|
} |
|
|
|
|
|
|
|
@ -47,6 +49,9 @@ namespace Microsoft.Tye.Hosting.Model |
|
|
|
public string RunCommand { get; } |
|
|
|
public string RunArguments { get; } |
|
|
|
|
|
|
|
public string? ContainerBaseTag { get; } |
|
|
|
public string? ContainerBaseImage { get; } |
|
|
|
|
|
|
|
// This exists for running projects as containers
|
|
|
|
public List<DockerVolume> VolumeMappings { get; } = new List<DockerVolume>(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -125,9 +125,19 @@ namespace Microsoft.Tye.Hosting |
|
|
|
|
|
|
|
private static string DetermineContainerImage(ProjectRunInfo project) |
|
|
|
{ |
|
|
|
var baseImage = project.IsAspNet ? "mcr.microsoft.com/dotnet/core/aspnet" : "mcr.microsoft.com/dotnet/core/runtime"; |
|
|
|
string baseImage; |
|
|
|
if (!string.IsNullOrEmpty(project.ContainerBaseImage)) |
|
|
|
{ |
|
|
|
baseImage = project.ContainerBaseImage; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
baseImage = project.IsAspNet ? "mcr.microsoft.com/dotnet/core/aspnet" : "mcr.microsoft.com/dotnet/core/runtime"; |
|
|
|
} |
|
|
|
|
|
|
|
var baseImageTag = !string.IsNullOrEmpty(project.ContainerBaseTag) ? project.ContainerBaseTag : project.TargetFrameworkVersion; |
|
|
|
|
|
|
|
return $"{baseImage}:{project.TargetFrameworkVersion}"; |
|
|
|
return $"{baseImage}:{baseImageTag}"; |
|
|
|
} |
|
|
|
|
|
|
|
public Task StopAsync(Application application) |
|
|
|
|
|
|
|
@ -246,6 +246,30 @@ namespace E2ETest |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task DockerBaseImageAndTagTest() |
|
|
|
{ |
|
|
|
using var projectDirectory = CopyTestProjectDirectory(Path.Combine("frontend-backend", "backend")); |
|
|
|
|
|
|
|
var projectFile = new FileInfo(Path.Combine(projectDirectory.DirectoryPath, "backend-baseimage.csproj")); |
|
|
|
|
|
|
|
var outputContext = new OutputContext(_sink, Verbosity.Debug); |
|
|
|
var application = await ApplicationFactory.CreateAsync(outputContext, projectFile); |
|
|
|
|
|
|
|
// Transform the backend into a docker image for testing
|
|
|
|
var project = (ProjectServiceBuilder)application.Services.First(s => s.Name == "backend-baseimage"); |
|
|
|
|
|
|
|
// check ContainerInfo values
|
|
|
|
Assert.True(string.Equals(project.ContainerInfo!.BaseImageName, "mcr.microsoft.com/dotnet/core/sdk")); |
|
|
|
Assert.True(string.Equals(project.ContainerInfo!.BaseImageTag, "3.1-buster")); |
|
|
|
|
|
|
|
// check projectInfo values
|
|
|
|
var projectRunInfo = new ProjectRunInfo(project); |
|
|
|
|
|
|
|
Assert.True(string.Equals(projectRunInfo!.ContainerBaseImage, project.ContainerInfo.BaseImageName)); |
|
|
|
Assert.True(string.Equals(projectRunInfo!.ContainerBaseTag, project.ContainerInfo.BaseImageTag)); |
|
|
|
} |
|
|
|
|
|
|
|
[ConditionalFact] |
|
|
|
[SkipIfDockerNotRunning] |
|
|
|
public async Task DockerNamedVolumeTest() |
|
|
|
|
|
|
|
@ -0,0 +1,17 @@ |
|
|
|
<Project Sdk="Microsoft.NET.Sdk.Web"> |
|
|
|
|
|
|
|
<PropertyGroup> |
|
|
|
<TargetFramework>netcoreapp3.1</TargetFramework> |
|
|
|
<RootNamespace>Backend</RootNamespace> |
|
|
|
</PropertyGroup> |
|
|
|
|
|
|
|
<PropertyGroup> |
|
|
|
<ContainerBaseImage>mcr.microsoft.com/dotnet/core/sdk</ContainerBaseImage> |
|
|
|
<ContainerBaseTag>3.1-buster</ContainerBaseTag> |
|
|
|
</PropertyGroup> |
|
|
|
|
|
|
|
<ItemGroup> |
|
|
|
<ProjectReference Include="$(TyeLibrariesPath)\Microsoft.Tye.Extensions.Configuration\Microsoft.Tye.Extensions.Configuration.csproj" /> |
|
|
|
</ItemGroup> |
|
|
|
|
|
|
|
</Project> |