Skip to content

Commit

Permalink
Some nuget upgrades; removed all constants from Kubernetes deployment…
Browse files Browse the repository at this point in the history
… files
  • Loading branch information
ScottArbeit committed Nov 4, 2023
1 parent ba2ef67 commit 62297a0
Show file tree
Hide file tree
Showing 17 changed files with 134 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/CosmosSerializer/CosmosJsonSerializer.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
Expand All @@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Core" Version="1.35.0" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.35.4" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.36.0" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<PropertyGroup>
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<!--<RuntimeIdentifier>linux-x64</RuntimeIdentifier>-->
<PublishProfile>DefaultContainer</PublishProfile>
<OtherFlags>$(OtherFlags) --test:GraphBasedChecking</OtherFlags>
</PropertyGroup>
</Project>
33 changes: 33 additions & 0 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

# Using the SDK image as the base instead of the aspnet image lets us run a shell for debugging.
#FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 5000
EXPOSE 5001

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["Grace.Server/Grace.Server.fsproj", "./Grace.Server/"]
COPY ["Grace.Actors/Grace.Actors.fsproj", "./Grace.Actors/"]
COPY ["Grace.Shared/Grace.Shared.fsproj", "./Grace.Shared/"]
COPY ["CosmosSerializer/CosmosJsonSerializer.csproj", "./CosmosSerializer/"]
RUN dotnet restore "Grace.Server/Grace.Server.fsproj"
COPY . .
WORKDIR "/src/Grace.Server"
#RUN dotnet build "Grace.Server.fsproj" -c Debug -o /app/build

FROM build AS publish
RUN dotnet publish "Grace.Server.fsproj" -c Debug -o /app/publish /p:UseAppHost=false

# Set environment variables to configure ASP.NET Core to use the certificate
#ENV ASPNETCORE_URLS="https://+;http://+"
ENV ASPNETCORE_HTTPS_PORT=5001
ENV ASPNETCORE_HTTP_PORT=5000
ENV DOTNET_GENERATE_ASPNET_CERTIFICATE=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Grace.Server.dll"]
23 changes: 23 additions & 0 deletions src/Get-KubernetesSecret.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
param (
[Parameter(Mandatory=$true)]
[string]$SecretName,

[Parameter(Mandatory=$false)]
[switch]$CreateCommand
)

# Get the secret from Kubernetes
$encodedSecret = kubectl get secret $SecretName -o jsonpath="{.data}"

# Decode the secret
$deserialized = $encodedSecret | ConvertFrom-Json

$decodedSecret = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($deserialized.$SecretName))

# Display the secret
$decodedSecret

# Create a command to set the secret
if ($CreateCommand) {
"kubectl create secret generic $SecretName --from-literal=$SecretName=""$decodedSecret"""
}
2 changes: 1 addition & 1 deletion src/Grace.Actors/Grace.Actors.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<PackageReference Include="Dapr.Actors" Version="1.12.0" />
<PackageReference Include="Dapr.Client" Version="1.12.0" />
<PackageReference Include="FSharpPlus" Version="1.5.0" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.35.4" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.36.0" />
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
<PackageReference Include="NodaTime" Version="3.1.9" />
<PackageReference Include="NodaTime.Serialization.SystemTextJson" Version="1.1.2" />
Expand Down
2 changes: 1 addition & 1 deletion src/Grace.CLI/Grace.CLI.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.7.0-alpha.1" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.7.0-alpha.1" />
<PackageReference Include="OpenTelemetry.Exporter.Zipkin" Version="1.7.0-alpha.1" />
<PackageReference Include="Polly" Version="8.0.0" />
<PackageReference Include="Polly" Version="8.1.0" />
<PackageReference Include="Spectre.Console" Version="0.47.0" />
<PackageReference Include="Spectre.Console.ImageSharp" Version="0.47.0" />
<PackageReference Include="Spectre.Console.Json" Version="0.47.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/Grace.SDK/Grace.SDK.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.19.0-beta.1" />
<PackageReference Include="Dapr.Client" Version="1.12.0" />
<PackageReference Include="Polly" Version="8.0.0" />
<PackageReference Include="Polly" Version="8.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/Grace.Server.Tests/Grace.Server.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="FsUnit" Version="5.4.0" />
<PackageReference Include="FsUnit" Version="5.5.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0-rc.2.23480.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.8.0">
<PackageReference Include="NUnit.Analyzers" Version="3.9.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
23 changes: 16 additions & 7 deletions src/Grace.Server/ApplicationContext.Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ open System.Linq
open System.Threading.Tasks
open System.Net.Http
open System
open System.Net.Sockets

module ApplicationContext =

Expand All @@ -39,7 +40,7 @@ module ApplicationContext =
/// </summary>
/// <param name="config">The configuration to set.</param>
let setConfiguration (config: IConfiguration) =
logToConsole $"In setConfiguration at {getCurrentInstantExtended}. isNull(config): {isNull(config)}."
logToConsole $"In setConfiguration: isNull(config): {isNull(config)}."
configuration <- config
//configuration.AsEnumerable() |> Seq.iter (fun kvp -> logToConsole $"{kvp.Key}: {kvp.Value}")

Expand Down Expand Up @@ -67,6 +68,7 @@ module ApplicationContext =
let daprClient = DaprClientBuilder().UseJsonSerializationOptions(Constants.JsonSerializerOptions).UseHttpEndpoint(daprHttpEndpoint).UseGrpcEndpoint(daprGrpcEndpoint).Build()

let mutable sharedKeyCredential: StorageSharedKeyCredential = null
let mutable grpcPortListener: TcpListener = null

let defaultObjectStorageProvider = ObjectStorageProvider.AzureBlobStorage

Expand All @@ -78,15 +80,22 @@ module ApplicationContext =
let mutable gRPCPort: int = 50001
let grpcPortString = Environment.GetEnvironmentVariable(Constants.EnvironmentVariables.DaprGrpcPort)
Int32.TryParse(grpcPortString, &gRPCPort) |> ignore
let mutable counter = 0
while not <| isReady do
do! Task.Delay(TimeSpan.FromSeconds(1.0))
do! Task.Delay(TimeSpan.FromSeconds(2.0))
logToConsole $"Checking if gRPC port {gRPCPort} is ready."
let tcpListeners = Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners()
//for t in tcpListeners do
// logToConsole $"{t.Address}:{t.Port} {t.AddressFamily}"
if tcpListeners.Length > 0 then logToConsole "Active TCP listeners:"
for t in tcpListeners do
logToConsole $"{t.Address}:{t.Port} {t.AddressFamily}."
if tcpListeners.Any(fun tcpListener -> tcpListener.Port = gRPCPort) then
logToConsole $"gRPC port is ready."
isReady <- true
else
counter <- counter + 1
if counter > 1800 then
logToConsole $"gRPC port is not ready after {counter} seconds. Exiting."
Environment.Exit(1)

let storageKey = Environment.GetEnvironmentVariable(Constants.EnvironmentVariables.AzureStorageKey)
sharedKeyCredential <- StorageSharedKeyCredential(DefaultObjectStorageAccount, storageKey)
Expand All @@ -97,9 +106,9 @@ module ApplicationContext =

// Get a reference to the CosmosDB database.
let cosmosClientOptions = CosmosClientOptions(
ApplicationName = Constants.GraceServerAppId,
EnableContentResponseOnWrite = false,
LimitToEndpoint = true,
ApplicationName = Constants.GraceServerAppId,
EnableContentResponseOnWrite = false,
LimitToEndpoint = true,
Serializer = new CosmosJsonSerializer(Constants.JsonSerializerOptions))
#if DEBUG
// The CosmosDB emulator uses a self-signed certificate, and, by default, HttpClient will refuse
Expand Down
25 changes: 16 additions & 9 deletions src/Grace.Server/Grace.Server.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,25 @@
<Description>The server module for Grace Version Control System.</Description>
<UserSecretsId>f1167a88-7f15-49c3-8ea1-30c2608081c9</UserSecretsId>
<ContainerBaseImage>mcr.microsoft.com/dotnet/aspnet:8.0</ContainerBaseImage>
<ContainerImageTag>latest</ContainerImageTag>
<ContainerImageTags>0.1;latest</ContainerImageTags>
<!--<ContainerRegistry>registry.hub.docker.com</ContainerRegistry>-->
<ContainerRepository>scottarbeit/grace-server</ContainerRepository>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<!--<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>-->
<DockerfileTag>scottarbeit/grace-server</DockerfileTag>
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
<WarningsAsErrors>FS0025</WarningsAsErrors>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<NoWarn>NETSDK1057</NoWarn>
<Platforms>AnyCPU;x64</Platforms>
<UseAppHost>true</UseAppHost>
<UseAppHost>false</UseAppHost>
<PackageProjectUrl>https://github.com/ScottArbeit/Grace</PackageProjectUrl>
</PropertyGroup>
<ItemGroup>
<ContainerPort Include="5000" Type="tcp"/>
<ContainerPort Include="5001" Type="tcp"/>
<ContainerPort Include="50001" Type="tcp"/>
<ContainerPort Include="57256" Type="tcp"/>
</ItemGroup>
<ItemGroup>
<Compile Include="CosmosSystemTextJsonSerializer.Server.fs" />
<Compile Include="ApplicationContext.Server.fs" />
Expand All @@ -43,6 +50,8 @@
<ProjectReference Include="..\Grace.Shared\Grace.Shared.fsproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Asp.Versioning.Mvc" Version="7.1.0" />
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="7.1.0" />
<PackageReference Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.0.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.19.0-beta.1" />
<PackageReference Include="Azure.Storage.Blobs.Batch" Version="12.16.0-beta.1" />
Expand All @@ -53,26 +62,24 @@
<PackageReference Include="Dapr.Actors" Version="1.12.0" />
<PackageReference Include="Dapr.Actors.AspNetCore" Version="1.12.0" />
<PackageReference Include="Dapr.Extensions.Configuration" Version="1.12.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="5.0.0" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.35.4" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.36.0" />
<!--<PackageReference Include="Microsoft.Extensions.ApiDescription.Server" Version="7.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>-->
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0-rc.2.23479.6" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0-rc.2.23479.6" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="8.0.0-rc.2.23479.6" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.9" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.10" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageReference Include="OpenTelemetry" Version="1.7.0-alpha.1" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.7.0-alpha.1" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.7.0-alpha.1" />
<PackageReference Include="OpenTelemetry.Exporter.Prometheus" Version="1.3.0-rc.2" />
<PackageReference Include="OpenTelemetry.Exporter.Zipkin" Version="1.7.0-alpha.1" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.7.0-alpha.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.5.1-beta.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.5.1-beta.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.6.0-beta.2" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.6.0-beta.2" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.5.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/Grace.Server/Program.Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module Program =
//.UseUrls("http://*:5000")
.UseKestrel(fun kestrelServerOptions ->
kestrelServerOptions.Listen(IPAddress.Any, 5000)
kestrelServerOptions.Listen(IPAddress.Loopback, 5001, (fun listenOptions -> listenOptions.UseHttps("/etc/certificates/gracedevcert.pfx", "GraceDevCert") |> ignore))
kestrelServerOptions.Listen(IPAddress.Any, 5001, (fun listenOptions -> listenOptions.UseHttps("/etc/certificates/gracedevcert.pfx", "GraceDevCert") |> ignore))
kestrelServerOptions.ConfigureEndpointDefaults(fun listenOptions -> listenOptions.Protocols <- HttpProtocols.Http1AndHttp2)
kestrelServerOptions.ConfigureHttpsDefaults(fun options ->
options.SslProtocols <- SslProtocols.Tls12 ||| SslProtocols.Tls13
Expand Down
38 changes: 27 additions & 11 deletions src/Grace.Server/Startup.Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.AspNetCore.Http
open Microsoft.AspNetCore.Mvc
open Microsoft.AspNetCore.Mvc.Versioning
open Asp.Versioning
open Asp.Versioning.ApiExplorer
open Microsoft.Extensions.DependencyInjection
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.Hosting.Internal
Expand All @@ -39,6 +40,7 @@ open System.IO
open Microsoft.Extensions.Configuration
open Grace.Shared.Converters
open Grace.Shared.Types
open Giraffe.ViewEngine.HtmlElements

module Application =
type FunctionThat_AddsOrUpdatesFile = DirectoryVersion -> FileVersion -> DirectoryVersion
Expand Down Expand Up @@ -289,20 +291,34 @@ module Application =
options.LogDirectory <- Path.Combine(Environment.GetEnvironmentVariable("TEMP"), "Grace.Server.Logs"))
.AddSingleton<ActorProxyOptions>(actorProxyOptions)
.AddSingleton<IActorProxyFactory>(actorProxyFactory)
.AddApiVersioning(fun config ->
config.DefaultApiVersion <- ApiVersion(DateTime(2023, 10, 1))
config.ApiVersionReader <- HeaderApiVersionReader(Constants.ServerApiVersionHeaderKey)
config.AssumeDefaultVersionWhenUnspecified <- true
)
.AddVersionedApiExplorer(fun config ->
config.DefaultApiVersion <- ApiVersion(DateTime(2023, 10, 1))
config.AssumeDefaultVersionWhenUnspecified <- true
config.ApiVersionParameterSource <- HeaderApiVersionReader(Constants.ServerApiVersionHeaderKey))
.AddDaprClient(fun daprClientBuilder ->
daprClientBuilder.UseJsonSerializationOptions(Constants.JsonSerializerOptions)
//.UseDaprApiToken(Environment.GetEnvironmentVariable("DAPR_API_TOKEN"))
.Build() |> ignore
.Build() // This builds the DaprClient.
|> ignore
)

let apiVersioningBuilder = services.AddApiVersioning(fun options ->
options.ReportApiVersions <- true
options.DefaultApiVersion <- new ApiVersion(1, 0)
options.AssumeDefaultVersionWhenUnspecified <- true
// Use whatever reader you want
options.ApiVersionReader <- ApiVersionReader.Combine(new UrlSegmentApiVersionReader(),
new HeaderApiVersionReader("x-api-version"),
new MediaTypeApiVersionReader("x-api-version"));
)

apiVersioningBuilder.AddApiExplorer(fun options ->
// add the versioned api explorer, which also adds IApiVersionDescriptionProvider service
// note: the specified format code will format the version as "'v'major[.minor][-status]"
options.GroupNameFormat <- "'v'VVV"
options.DefaultApiVersion <- ApiVersion(DateOnly(2023, 10, 1))
options.AssumeDefaultVersionWhenUnspecified <- true
options.ApiVersionParameterSource <- HeaderApiVersionReader(Constants.ServerApiVersionHeaderKey)

// note: this option is only necessary when versioning by url segment. the SubstitutionFormat
// can also be used to control the format of the API version in route templates
options.SubstituteApiVersionInUrl <- true) |> ignore

// Configures the Dapr Actor subsystem.
services.AddActors(fun options ->
Expand Down
2 changes: 1 addition & 1 deletion src/Grace.Shared/Grace.Shared.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</PackageReference>
<PackageReference Include="NodaTime" Version="3.1.9" />
<PackageReference Include="NodaTime.Serialization.SystemTextJson" Version="1.1.2" />
<PackageReference Include="Polly" Version="8.0.0" />
<PackageReference Include="Polly" Version="8.1.0" />
<PackageReference Include="Polly.Contrib.WaitAndRetry" Version="1.1.1" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions src/Grace.Shared/Resources/Text/en-US.fs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module en_US =
| GettingCurrentBranch -> "Getting the current branch from the server."
| GettingLatestVersion -> "Getting the latest version of the branch you're switching to."
| GraceConfigFileNotFound -> $"No {Constants.GraceConfigFileName} file found along current path. Please run `grace config write` if you'd like to create one."
| IndexFileNotFound -> "The Grace index file was not found. Please run grace maintenance update-index to re-create it."
| IndexFileNotFound -> "The Grace index file was not found. Please run `grace maintenance update-index` to re-create it."
| InitialPromotionMessage -> "Initial, empty promotion."
| InterprocessFileDeleted -> "Inter-process communication file deleted."
| InvalidBranchId -> "The provided BranchId is not a valid Guid."
Expand Down Expand Up @@ -76,7 +76,7 @@ module en_US =
| PromotionNotAvailableBecauseThereAreNoPromotableReferences -> "Promotion is not available because there are no commits or promotions in the current branch to promote to the parent branch."
| MessageIsRequired -> "A message is required for this reference."
| NotImplemented -> "This feature is not yet implemented."
| ObjectCacheFileNotFound -> "The Grace object cache file was not found. Please run grace maintenance scan to recreate it."
| ObjectCacheFileNotFound -> "The Grace object cache file was not found. Please run `grace maintenance scan` to recreate it."
| ObjectStorageException -> "An exception occurred when communicating with the object storage provider."
| OrganizationIdAlreadyExists -> "An Organization with the provided OrganizationId already exists."
| OrganizationNameAlreadyExists -> "An organization with the same name and owner already exists."
Expand Down
Loading

0 comments on commit 62297a0

Please sign in to comment.