Skip to content

Commit

Permalink
upgrading to 5.0 sdk and runtime issue #130
Browse files Browse the repository at this point in the history
  • Loading branch information
kdcllc committed Aug 17, 2020
1 parent 1c8e536 commit 86765e3
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 83 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# 2. docker cp bet.nuget.build:/app/nugets ${PWD}/packages
#------------------------------------------------------------------------------------------------------------------------

FROM kdcllc/dotnet-sdk:3.1-buster as builder
FROM kdcllc/dotnet-sdk:5.0-focal as builder

RUN apt-get -y update &&\
apt-get -y install git &&\
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.vscode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ version: '3'
services:
# this is for the entire solution
bet.vscode:
image: kdcllc/dotnet-sdk-vscode:3.1-bionic
image: kdcllc/dotnet-sdk-vscode:5.0-focal
# Azure Key Vault Authentication global tool
# dotnet tool install --global appauthentication --version 1.2.2
# dotnet tool install --global appauthentication
# run this tool first then check the configuration
# docker-compose -f ./docker-compose.vscode.yml config
environment:
Expand Down
18 changes: 0 additions & 18 deletions k8s/README.md

This file was deleted.

25 changes: 0 additions & 25 deletions k8s/azurefile-betazurefile-pv.yaml

This file was deleted.

11 changes: 0 additions & 11 deletions k8s/azurefile-betazurefile-pvc.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions src/Bet.AspNetCore.Sample/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ ARG RUNTESTS=false
ARG VERBOSE=false
ARG PROJECT_PATH=/src/Bet.AspNetCore.Sample/Bet.AspNetCore.Sample.csproj

FROM kdcllc/dotnet-sdk:3.1-alpine as builder
FROM kdcllc/dotnet-sdk:5.0-alpine as builder
RUN dotnet publish "./src/Bet.AspNetCore.Sample/Bet.AspNetCore.Sample.csproj" -r linux-musl-x64 -o out --self-contained true /p:PublishTrimmed=true

FROM mcr.microsoft.com/dotnet/core/runtime-deps:3.1-alpine AS runtime
FROM mcr.microsoft.com/dotnet/core/runtime-deps:5.0-alpine AS runtime
WORKDIR /app

COPY --from=builder /app/out ./
Expand Down
3 changes: 3 additions & 0 deletions src/Bet.AspNetCore.Sample/k8s/betweb/templates/betweb-pv.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# create secret with
# kubectl create secret generic betshare-secret --from-literal=azurestorageaccountname=betstorage --from-literal=azurestorageaccountkey={key}

apiVersion: v1
kind: PersistentVolume
metadata:
Expand Down
35 changes: 18 additions & 17 deletions src/Bet.Extensions.AzureVault/AzureVaultKeyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;

using Bet.AspNetCore.Options;
using Bet.Extensions;
using Bet.Extensions.AzureVault;

using Microsoft.Azure.KeyVault;
Expand All @@ -21,13 +22,6 @@ namespace Microsoft.Extensions.Configuration
/// </summary>
public static class AzureVaultKeyBuilder
{
internal static readonly Dictionary<string, string> Enviroments = new Dictionary<string, string>
{
{ "Development", "dev" },
{ "Staging", "qa" },
{ "Production", "prod" }
};

/// <summary>
/// Adds Azure Key Vault with VS.NET authentication in the Development and MSI in production.
/// If MSI authentication fails it falls back to Client Id and Secret pair if specified in the configuration.
Expand All @@ -38,23 +32,26 @@ public static class AzureVaultKeyBuilder
/// <param name="usePrefix">The prefix like dev,qa,prod.</param>
/// <param name="tokenAuthRetry">The default value for the retry is 2.</param>
/// <param name="sectionName">The name of the Azure Key Vault Configuration Section. The default is 'AzureVault'.</param>
/// <param name="reloadInterval"></param>
/// <param name="reloadInterval">The reload interval for the Azure Key Vault.</param>
/// <param name="enviroments">The conversion for HostEnvironment:Prefix. The default is null.</param>
/// <returns></returns>
public static IConfigurationRoot AddAzureKeyVault(
this IConfigurationBuilder builder,
string hostingEnviromentName,
bool usePrefix = true,
int tokenAuthRetry = 2,
string sectionName = "AzureVault",
TimeSpan? reloadInterval = null)
TimeSpan? reloadInterval = null,
Environments? enviroments = null)
{
var config = builder.Build();
var options = config.Bind<AzureVaultOptions>(sectionName);
enviroments ??= new Environments();

var prefix = string.Empty;
if (usePrefix)
{
Enviroments.TryGetValue(hostingEnviromentName, out prefix);
enviroments.TryGetValue(hostingEnviromentName, out prefix);
}

if (!string.IsNullOrWhiteSpace(options?.BaseUrl))
Expand All @@ -75,7 +72,7 @@ public static IConfigurationRoot AddAzureKeyVault(
builder.AddAzureKeyVault(new AzureKeyVaultConfigurationOptions(options?.BaseUrl)
{
Client = keyVaultClient,
Manager = new PrefixExcludingKeyVaultSecretManager(),
Manager = new PrefixExcludingKeyVaultSecretManager(enviroments),
ReloadInterval = reloadInterval
});

Expand All @@ -100,7 +97,7 @@ public static IConfigurationRoot AddAzureKeyVault(

return builder.Build();
}
catch (Exception)
catch (Exception ex)
{
var list = builder.Sources.ToList();
var found = list.Where(x => x.GetType().FullName.Contains("AzureKeyVaultConfigurationSource"));
Expand All @@ -122,7 +119,7 @@ public static IConfigurationRoot AddAzureKeyVault(
// load values that are not specific to the environment.
builder.AddAzureKeyVault(new AzureKeyVaultConfigurationOptions(options?.BaseUrl, options?.ClientId, secret)
{
Manager = new PrefixExcludingKeyVaultSecretManager(),
Manager = new PrefixExcludingKeyVaultSecretManager(enviroments),
ReloadInterval = reloadInterval
});

Expand Down Expand Up @@ -154,21 +151,25 @@ public static IConfigurationRoot AddAzureKeyVault(
/// <param name="keyVaultEndpoints">The default Azure Key Vaults values separated by ';'.</param>
/// <param name="usePrefix">The default is true. It adds prefixed values from the vault.</param>
/// <param name="hostingEnviromentName">The hosting environment that is matched to 'dev, stage or prod'.</param>
/// <param name="reloadInterval"></param>
/// <param name="reloadInterval">The reload interval for the Azure Key Vault.</param>
/// <param name="enviroments">The conversion for HostEnvironment:Prefix. The default is null.</param>
/// <returns></returns>
public static IConfigurationRoot AddAzureKeyVaults(
this IConfigurationBuilder builder,
string keyVaultEndpoints,
bool usePrefix = true,
string? hostingEnviromentName = null,
TimeSpan? reloadInterval = null)
TimeSpan? reloadInterval = null,
Environments? enviroments = null)
{
if (!string.IsNullOrEmpty(keyVaultEndpoints))
{
enviroments ??= new Environments();

var prefix = string.Empty;
if (usePrefix && hostingEnviromentName != null)
{
Enviroments.TryGetValue(hostingEnviromentName, out prefix);
enviroments.TryGetValue(hostingEnviromentName, out prefix);
}

var azureServiceTokenProvider = new AzureServiceTokenProvider();
Expand All @@ -181,7 +182,7 @@ public static IConfigurationRoot AddAzureKeyVaults(
builder.AddAzureKeyVault(new AzureKeyVaultConfigurationOptions(splitEndpoint)
{
Client = keyVaultClient,
Manager = new PrefixExcludingKeyVaultSecretManager(),
Manager = new PrefixExcludingKeyVaultSecretManager(enviroments),
ReloadInterval = reloadInterval
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ namespace Bet.Extensions.AzureVault
/// </summary>
public class PrefixExcludingKeyVaultSecretManager : IKeyVaultSecretManager
{
private readonly Environments _envronments;

public PrefixExcludingKeyVaultSecretManager(Environments envronments)
{
_envronments = envronments;
}

public bool Load(SecretItem secret)
{
// Load a vault secret when its secret name starts with the
Expand All @@ -21,7 +28,7 @@ public bool Load(SecretItem secret)
{
var env = secretName.Substring(0, envIndex);

return !AzureVaultKeyBuilder.Enviroments.ContainsValue(env);
return !_envronments.ContainsValue(env);
}

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/Bet.Hosting.Sample/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ ARG RUNTESTS=false
ARG VERBOSE=false
ARG PROJECT_PATH=/src/Bet.Hosting.Sample/Bet.Hosting.Sample.csproj

FROM kdcllc/dotnet-sdk:3.1-alpine as builder
FROM kdcllc/dotnet-sdk:5.0-alpine as builder
RUN dotnet publish "./src/Bet.Hosting.Sample/Bet.Hosting.Sample.csproj" -r linux-musl-x64 -o out --self-contained true /p:PublishTrimmed=true

# https://hub.docker.com/_/microsoft-dotnet-core-aspnet/
FROM mcr.microsoft.com/dotnet/core/runtime-deps:3.1-alpine AS runtime
FROM mcr.microsoft.com/dotnet/core/runtime-deps:5.0-alpine AS runtime
WORKDIR /app

COPY --from=builder /app/out ./
Expand Down
4 changes: 2 additions & 2 deletions src/Bet.K8s.Web.Sample/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ ARG RUNTESTS=false
ARG VERBOSE=false
ARG PROJECT_PATH=/src/Bet.K8s.Web.Sample/Bet.K8s.Web.Sample.csproj

FROM kdcllc/dotnet-sdk:3.1-alpine as builder
FROM kdcllc/dotnet-sdk:5.0-alpine as builder
RUN dotnet publish "./src/Bet.K8s.Web.Sample/Bet.K8s.Web.Sample.csproj" -r linux-musl-x64 -o out --self-contained true /p:PublishTrimmed=true


FROM mcr.microsoft.com/dotnet/core/runtime-deps:3.1-alpine AS runtime
FROM mcr.microsoft.com/dotnet/core/runtime-deps:5.0-alpine AS runtime
WORKDIR /app

COPY --from=builder /app/out ./
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# create secret with
# kubectl create secret generic betshare-secret --from-literal=azurestorageaccountname=betstorage --from-literal=azurestorageaccountkey={key}

apiVersion: v1
kind: PersistentVolume
metadata:
Expand Down
4 changes: 2 additions & 2 deletions src/LetsEncryptWeb/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
# PUBLISH: docker push kdcllc/bet:letsencrypt
#

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
FROM mcr.microsoft.com/dotnet/core/aspnet:5.0-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
FROM mcr.microsoft.com/dotnet/core/sdk:5.0-buster AS build
WORKDIR /src
COPY ["Directory.Build.targets", "Directory.Build.targets"]
COPY ["Directory.Build.props", "Directory.Build.props"]
Expand Down

0 comments on commit 86765e3

Please sign in to comment.