|
|
@ -4,11 +4,12 @@ |
|
|
|
|
|
|
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
|
|
|
using System.IO; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
using System.Threading; |
|
|
using System.Threading; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
using Microsoft.Tye.Hosting.Model; |
|
|
|
|
|
using Microsoft.Extensions.Logging; |
|
|
using Microsoft.Extensions.Logging; |
|
|
|
|
|
using Microsoft.Tye.Hosting.Model; |
|
|
|
|
|
|
|
|
namespace Microsoft.Tye.Hosting |
|
|
namespace Microsoft.Tye.Hosting |
|
|
{ |
|
|
{ |
|
|
@ -71,6 +72,15 @@ namespace Microsoft.Tye.Hosting |
|
|
var volumes = ""; |
|
|
var volumes = ""; |
|
|
var workingDirectory = docker.WorkingDirectory != null ? $"-w {docker.WorkingDirectory}" : ""; |
|
|
var workingDirectory = docker.WorkingDirectory != null ? $"-w {docker.WorkingDirectory}" : ""; |
|
|
|
|
|
|
|
|
|
|
|
// This is .NET specific
|
|
|
|
|
|
var userSecretStore = GetUserSecretsPathFromSecrets(); |
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(userSecretStore)) |
|
|
|
|
|
{ |
|
|
|
|
|
// Map the user secrets on this drive to user secrets
|
|
|
|
|
|
docker.VolumeMappings[userSecretStore] = "/root/.microsoft/usersecrets:ro"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var dockerInfo = new DockerInformation(new Task[service.Description.Replicas]); |
|
|
var dockerInfo = new DockerInformation(new Task[service.Description.Replicas]); |
|
|
|
|
|
|
|
|
async Task RunDockerContainer(IEnumerable<(int Port, int? InternalPort, int BindingPort, string? Protocol)> ports) |
|
|
async Task RunDockerContainer(IEnumerable<(int Port, int? InternalPort, int BindingPort, string? Protocol)> ports) |
|
|
@ -260,21 +270,29 @@ namespace Microsoft.Tye.Hosting |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static async Task<bool> DetectDockerInstalled() |
|
|
private static string? GetUserSecretsPathFromSecrets() |
|
|
{ |
|
|
{ |
|
|
// Detect Docker installation
|
|
|
// This is the logic used to determine the user secrets path
|
|
|
try |
|
|
// See https://github.com/dotnet/extensions/blob/64140f90157fec1bfd8aeafdffe8f30308ccdf41/src/Configuration/Config.UserSecrets/src/PathHelper.cs#L27
|
|
|
{ |
|
|
const string userSecretsFallbackDir = "DOTNET_USER_SECRETS_FALLBACK_DIR"; |
|
|
await ProcessUtil.RunAsync("docker", "version", throwOnError: false); |
|
|
|
|
|
return true; |
|
|
// For backwards compat, this checks env vars first before using Env.GetFolderPath
|
|
|
} |
|
|
var appData = Environment.GetEnvironmentVariable("APPDATA"); |
|
|
catch (Exception) |
|
|
var root = appData // On Windows it goes to %APPDATA%\Microsoft\UserSecrets\
|
|
|
|
|
|
?? Environment.GetEnvironmentVariable("HOME") // On Mac/Linux it goes to ~/.microsoft/usersecrets/
|
|
|
|
|
|
?? Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) |
|
|
|
|
|
?? Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) |
|
|
|
|
|
?? Environment.GetEnvironmentVariable(userSecretsFallbackDir); // this fallback is an escape hatch if everything else fails
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(root)) |
|
|
{ |
|
|
{ |
|
|
// Unfortunately, process throws
|
|
|
return null; |
|
|
return false; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return !string.IsNullOrEmpty(appData) |
|
|
|
|
|
? Path.Combine(root, "Microsoft", "UserSecrets") |
|
|
|
|
|
: Path.Combine(root, ".microsoft", "usersecrets"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private class DockerInformation |
|
|
private class DockerInformation |
|
|
{ |
|
|
{ |
|
|
|