Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Commit

Permalink
Move Tye to .NET 6 (#1215)
Browse files Browse the repository at this point in the history
* Switch to .NET 6 runtimes.

* 1st pass at moving core project target frameworks.

* 2nd pass of nullable updates.

* Use .NET 6 SDK base image for Docker proxies.

* Move test projects to .NET 6.

* Fix formatting.

* Try running tests on MacOS 11 (Big Sur).

* Try disabling HTTPS on watch tests.

* Revert HTTPS changes and just disable E2E tests for now.

* Update docs references to .NET Core.
  • Loading branch information
philliphoff authored Nov 16, 2021
1 parent 995c669 commit 1c8577f
Show file tree
Hide file tree
Showing 66 changed files with 120 additions and 93 deletions.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ stages:
- job: OSX_10_14
displayName: 'OSX'
pool:
vmImage: macOS-10.14
vmImage: macOS-11
variables:
- name: _SignType
value: none
Expand Down
2 changes: 1 addition & 1 deletion docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

A: Three main ways:

- Tye is optimized for .NET Core - we have built-in knowledge of how .NET projects work, which we use to power most experiences.
- Tye is optimized for .NET - we have built-in knowledge of how .NET projects work, which we use to power most experiences.
- Tye's development features are oriented towards *local development* (avoid running in a container unless necessary).
- Tye aims to solve problems along the whole spectrum of development to CI/CD based deployment.

Expand Down
2 changes: 1 addition & 1 deletion docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tye is a tool that makes developing, testing, and deploying microservices and di

## Installing Tye

1. Install [.NET Core 3.1](<http://dot.net>).
1. Install [.NET 6](<https://dot.net>).
1. Install tye via the following command:

```text
Expand Down
8 changes: 4 additions & 4 deletions docs/recipes/githubactions_aks.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ env:
ACR_RESOURCE_URI: myregistry.azurecr.io
```

Next, ensure that the version of .NET Core and tye are installed.
Next, ensure that Tye and its dependent .NET runtime are installed.

```yaml
- name: 🧰 Setup .NET Core
- name: 🧰 Setup .NET
uses: actions/setup-dotnet@v1.5.0
with:
dotnet-version: 3.1.300
dotnet-version: 6.0.100
- name: 🛠 Install Tye tools
run: |
dotnet tool install -g Microsoft.Tye --version "0.2.0-alpha.20258.3"
dotnet tool install -g Microsoft.Tye --version "0.10.0-alpha.21420.1"
```

Using the name of the registry and the [Azure docker action](https://github.com/Azure/docker-login) to login to your registry. This step is needed prior to running the `deploy` command which will build and push the images to the registry.
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ These steps are sequentially executed for each project or service.

### Configure defaults for docker

Sets defaults for any projects that will create docker images. For example, for any ASP.NET Core projects, this step will set the container base image to `mcr.microsoft.com/dotnet/core/aspnet`. It will also select the image tag based on the .NET version specified (2.1, 3.1, etc.).
Sets defaults for any projects that will create docker images. For example, for any ASP.NET Core projects, this step will set the container base image to `mcr.microsoft.com/dotnet/core/aspnet`. It will also select the image tag based on the .NET version specified (2.1, 3.1, 5, 6, etc.).

This is also where Tye requires a container registry to properly set the image name. If running `tye deploy` (no interactive), tye requires a registry to be defined in `tye.yaml`. If running interactively (`tye deploy -i`), tye will prompt the user for one if not specified in `tye.yaml`.

Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"dotnet": "6.0.100",
"runtimes": {
"dotnet": [
"3.1.14"
"6.0.0"
],
"aspnetcore": [
"3.1.14"
"6.0.0"
]
}
},
Expand Down
3 changes: 2 additions & 1 deletion src/Microsoft.Tye.Core/ConfigFileFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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.Diagnostics.CodeAnalysis;
using System.IO;

namespace Microsoft.Tye
Expand All @@ -10,7 +11,7 @@ public class ConfigFileFinder
{
private static readonly string[] FileFormats = { "tye.yaml", "tye.yml", "docker-compose.yaml", "docker-compose.yml", "*.csproj", "*.fsproj", "*.sln" };

public static bool TryFindSupportedFile(string directoryPath, out string? filePath, out string? errorMessage, string[]? fileFormats = null)
public static bool TryFindSupportedFile(string directoryPath, [NotNullWhen(true)] out string? filePath, [MaybeNullWhen(true)] out string? errorMessage, string[]? fileFormats = null)
{
fileFormats ??= FileFormats;
foreach (var format in fileFormats)
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Tye.Core/ConfigModel/ConfigApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void Validate()
foreach (var probe in probes)
{
context = new ValidationContext(probe.Probe!);
if (!Validator.TryValidateObject(probe.Probe, context, results, validateAllProperties: true))
if (!Validator.TryValidateObject(probe.Probe!, context, results, validateAllProperties: true))
{
throw new TyeYamlException(
$"Probe '{probe.Name}' in service '{service.Name}' validation failed." + Environment.NewLine +
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Tye.Core/Microsoft.Tye.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>Tye</RootNamespace>
<AssemblyName>Microsoft.Tye.Core</AssemblyName>
<PackageId>Microsoft.Tye.Core</PackageId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Description>Diagnostics collector and exporter for .NET Core applications.</Description>
<AssemblyName>Microsoft.Tye.Hosting.Diagnostics</AssemblyName>
<PackageId>Microsoft.Tye.Hosting.Diagnostics</PackageId>
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Tye.Hosting/DockerRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ service.Description.RunInfo is IngressRunInfo ||

// Inject a proxy per non-container service. This allows the container to use normal host names within the
// container network to talk to services on the host
var proxyContainer = new DockerRunInfo($"mcr.microsoft.com/dotnet/core/sdk:3.1", "dotnet Microsoft.Tye.Proxy.dll")
var proxyContainer = new DockerRunInfo($"mcr.microsoft.com/dotnet/sdk:6.0", "dotnet Microsoft.Tye.Proxy.dll")
{
WorkingDirectory = "/app",
NetworkAlias = service.Description.Name,
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Tye.Hosting/HttpProxyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public async Task StartAsync(Application application)
}
var uri = new UriBuilder(uris[next].Uri)
{
Path = rule.PreservePath ? $"{context.Request.Path}" : (string)context.Request.RouteValues["path"] ?? "/",
Path = rule.PreservePath ? $"{context.Request.Path}" : (string?)context.Request.RouteValues["path"] ?? "/",
Query = context.Request.QueryString.Value
};
Expand Down
12 changes: 10 additions & 2 deletions src/Microsoft.Tye.Hosting/Infrastructure/ProxyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,14 @@ public static HttpRequestMessage CreateProxyHttpRequest(this HttpContext context

// Append request forwarding headers
requestMessage.Headers.TryAddWithoutValidation("Via", $"{context.Request.Protocol} Tye");
requestMessage.Headers.TryAddWithoutValidation("X-Forwarded-For", context.Connection.RemoteIpAddress.ToString());
requestMessage.Headers.TryAddWithoutValidation("X-Forwarded-Proto", request.Scheme);
requestMessage.Headers.TryAddWithoutValidation("X-Forwarded-Host", request.Host.ToUriComponent());

if (context.Connection.RemoteIpAddress != null)
{
requestMessage.Headers.TryAddWithoutValidation("X-Forwarded-For", context.Connection.RemoteIpAddress.ToString());
}

requestMessage.Headers.Host = uri.Authority;
requestMessage.RequestUri = uri;
requestMessage.Method = new HttpMethod(request.Method);
Expand Down Expand Up @@ -129,10 +133,14 @@ public static async Task<bool> AcceptProxyWebSocketRequest(this HttpContext cont
}

AppendHeaderValue(client.Options, context.Request.Headers, "Via", context.Request.Protocol);
AppendHeaderValue(client.Options, context.Request.Headers, "X-Forwarded-For", context.Connection.RemoteIpAddress.ToString());
AppendHeaderValue(client.Options, context.Request.Headers, "X-Forwarded-Proto", context.Request.Scheme);
AppendHeaderValue(client.Options, context.Request.Headers, "X-Forwarded-Host", context.Request.Host.ToUriComponent());

if (context.Connection.RemoteIpAddress != null)
{
AppendHeaderValue(client.Options, context.Request.Headers, "X-Forwarded-For", context.Connection.RemoteIpAddress.ToString());
}

try
{
await client.ConnectAsync(destinationUri, context.RequestAborted);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,25 @@ public ServiceLogger(string categoryName, Subject<string> logs)
_logs = logs;
}

public IDisposable? BeginScope<TState>(TState state)
public IDisposable BeginScope<TState>(TState state)
{
return null;
return null!;
}

public bool IsEnabled(LogLevel logLevel)
{
return true;
}

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception, string>? formatter)
{
_logs.OnNext($"[{logLevel}]: {formatter(state, exception)}");

if (exception != null)
{
if (formatter != null)
{
_logs.OnNext($"[{logLevel}]: {formatter(state, exception)}");
}

_logs.OnNext(exception.ToString());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Tye.Hosting/Microsoft.Tye.Hosting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Description>Orchestration host APIs.</Description>
<AssemblyName>Microsoft.Tye.Hosting</AssemblyName>
<PackageId>Microsoft.Tye.Hosting</PackageId>
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Tye.Hosting/ProxyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public Task StartAsync(Application application)
return;
}
using var _ = cts.Token.Register(() => notificationFeature.RequestClose());
using var _ = cts.Token.Register(() => notificationFeature?.RequestClose());
NetworkStream? targetStream = null;
Expand Down Expand Up @@ -132,10 +132,10 @@ public Task StartAsync(Application application)
_logger.LogDebug("Proxying traffic to {ServiceName} {ExternalPort}:{InternalPort}", service.Description.Name, binding.Port, ports[next]);
// external -> internal
var reading = Task.Run(() => connection.Transport.Input.CopyToAsync(targetStream, notificationFeature.ConnectionClosedRequested));
var reading = Task.Run(() => connection.Transport.Input.CopyToAsync(targetStream, notificationFeature?.ConnectionClosedRequested ?? default));
// internal -> external
var writing = Task.Run(() => targetStream.CopyToAsync(connection.Transport.Output, notificationFeature.ConnectionClosedRequested));
var writing = Task.Run(() => targetStream.CopyToAsync(connection.Transport.Output, notificationFeature?.ConnectionClosedRequested ?? default));
await Task.WhenAll(reading, writing);
}
Expand All @@ -149,7 +149,7 @@ public Task StartAsync(Application application)
}
catch (OperationCanceledException ex)
{
if (!notificationFeature.ConnectionClosedRequested.IsCancellationRequested)
if (notificationFeature is null || !notificationFeature.ConnectionClosedRequested.IsCancellationRequested)
{
_logger.LogDebug(0, ex, "Proxy error for service {ServiceName}", service.Description.Name);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Tye.Hosting/TransformProjectsIntoContainers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ private async Task TransformProjectToContainer(Service service, ProjectRunInfo p
// This is .NET specific
var userSecretStore = GetUserSecretsPathFromSecrets();

Directory.CreateDirectory(userSecretStore);

if (!string.IsNullOrEmpty(userSecretStore))
{
Directory.CreateDirectory(userSecretStore);

// Map the user secrets on this drive to user secrets
dockerRunInfo.VolumeMappings.Add(new DockerVolume(source: userSecretStore, name: null, target: "/root/.microsoft/usersecrets", readOnly: true));
}
Expand Down
21 changes: 15 additions & 6 deletions src/Microsoft.Tye.Hosting/TyeHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,18 @@ public async Task<IHost> StartAsync()

await app.StartAsync();

_addresses = DashboardWebApplication.Services.GetRequiredService<IServer>().Features.Get<IServerAddressesFeature>().Addresses;
_addresses = DashboardWebApplication.Services.GetRequiredService<IServer>().Features.Get<IServerAddressesFeature>()?.Addresses;

_logger.LogInformation("Dashboard running on {Address}", _addresses.First());
var dashboardAddress = _addresses?.FirstOrDefault();

if (dashboardAddress != null)
{
_logger.LogInformation("Dashboard running on {Address}", dashboardAddress);
}
else
{
_logger.LogWarning("Dashboard is not running");
}

try
{
Expand All @@ -117,9 +126,9 @@ public async Task<IHost> StartAsync()
_lifetime.StopApplication();
}

if (_options.Dashboard)
if (dashboardAddress != null && _options.Dashboard)
{
OpenDashboard(_addresses.First());
OpenDashboard(dashboardAddress);
}

return app;
Expand Down Expand Up @@ -333,7 +342,7 @@ private async Task StopAsync()
}
catch (Exception ex)
{
_logger.LogError(ex, "Error while shutting down");
_logger?.LogError(ex, "Error while shutting down");
}
finally
{
Expand Down Expand Up @@ -375,7 +384,7 @@ private void OpenDashboard(string url)
}
catch (Exception ex)
{
_logger.LogError(ex, "Error launching dashboard.");
_logger?.LogError(ex, "Error launching dashboard.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Tye.Proxy/Microsoft.Tye.Proxy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Tye.Proxy/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Program
static async Task Main(string[] args)
{
var serviceName = Environment.GetEnvironmentVariable("APP_INSTANCE");
var containerHost = Environment.GetEnvironmentVariable("CONTAINER_HOST");
var containerHost = Environment.GetEnvironmentVariable("CONTAINER_HOST") ?? throw new ArgumentNullException("CONTAINER_HOST was not specified.");

using var host = new HostBuilder()
.ConfigureLogging(logging =>
Expand Down Expand Up @@ -88,10 +88,10 @@ static async Task Main(string[] args)
logger.LogDebug("Proxying traffic to {ServiceName} {Port}:{ExternalPort}", serviceName, mapping.Port, mapping.ExternalPort);
// external -> internal
var reading = Task.Run(() => connection.Transport.Input.CopyToAsync(targetStream, notificationFeature.ConnectionClosedRequested));
var reading = Task.Run(() => connection.Transport.Input.CopyToAsync(targetStream, notificationFeature?.ConnectionClosedRequested ?? default));
// internal -> external
var writing = Task.Run(() => targetStream.CopyToAsync(connection.Transport.Output, notificationFeature.ConnectionClosedRequested));
var writing = Task.Run(() => targetStream.CopyToAsync(connection.Transport.Output, notificationFeature?.ConnectionClosedRequested ?? default));
await Task.WhenAll(reading, writing);
}
Expand All @@ -105,7 +105,7 @@ static async Task Main(string[] args)
}
catch (OperationCanceledException ex)
{
if (!notificationFeature.ConnectionClosedRequested.IsCancellationRequested)
if (notificationFeature is null || !notificationFeature.ConnectionClosedRequested.IsCancellationRequested)
{
logger.LogDebug(0, ex, "Proxy error for service {ServiceName}", serviceName);
}
Expand Down
14 changes: 10 additions & 4 deletions src/shared/KubectlDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@ public static Task<bool> IsKubectlConnectedToClusterAsync(OutputContext output)
{
continue;
}
var major = int.Parse(element.Value.GetProperty("major").GetString());
var minor = int.Parse(element.Value.GetProperty("minor").GetString().Trim('+'));
var version = new Version(major, minor);
return version;
var majorString = element.Value.GetProperty("major").GetString();
var minorString = element.Value.GetProperty("minor").GetString();

if (majorString != null && minorString != null)
{
var major = int.Parse(majorString);
var minor = int.Parse(minorString.Trim('+'));
var version = new Version(major, minor);
return version;
}
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion src/tye-diag-agent/tye-diag-agent.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>Microsoft.Tye</RootNamespace>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/tye/InitHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static (string, string) CreateTyeFileContent(FileInfo? path, bool force)
throw new CommandException(errorMessage!);
}

path = new FileInfo(filePath);
path = new FileInfo(filePath!);
}

var template = @"
Expand Down
2 changes: 1 addition & 1 deletion src/tye/tye.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>Microsoft.Tye</RootNamespace>
<AssemblyName>tye</AssemblyName>
<PackageId>Microsoft.Tye</PackageId>
Expand Down
Loading

0 comments on commit 1c8577f

Please sign in to comment.