Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update samples #340

Merged
merged 8 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@cloudfoundry_scaffold
Feature: Steeltoe Configuration
In order to show you how to use Steeltoe with IConfiguration
You can run the configuration sample

@net8.0
@linux
Scenario: Steeltoe Configuration (net8.0/linux)
When you run: dotnet build
And you run in the background: cf push -f manifest.yml
And you wait until CloudFoundry app configuration-providers-sample is started
When you get https://configuration-providers-sample/Home/ExternalConfigurationData
Then you should see "Property bar = spam"
When you get https://configuration-providers-sample/Home/ConfigServerSettings
Then you should see "spring:cloud:config:name = foo"
When you get https://configuration-providers-sample/Home/CloudFoundry
Then you should see "vcap:application:application_name = configuration-providers-sample"
When you get https://configuration-providers-sample/Home/PlaceholderValues
Then you should see "ResolvedFromJsonInformation"

@net8.0
@windows
Scenario: Steeltoe Configuration (net8.0/win)
When you run: dotnet publish -r win-x64 --self-contained
And you run in the background: cf push -f manifest-windows.yml -p bin/Release/net8.0/win-x64/publish
And you wait until CloudFoundry app configuration-providers-sample is started
When you get https://configuration-providers-sample/Home/ExternalConfigurationData
Then you should see "Property bar = spam"
When you get https://configuration-providers-sample/Home/ConfigServerSettings
Then you should see "spring:cloud:config:name = foo"
When you get https://configuration-providers-sample/Home/CloudFoundry
Then you should see "vcap:application:application_name = configuration-providers-sample"
When you get https://configuration-providers-sample/Home/PlaceholderValues
Then you should see "ResolvedFromJsonInformation"
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@
using Microsoft.Extensions.Options;
using Steeltoe.Configuration.CloudFoundry;
using Steeltoe.Configuration.ConfigServer;
using Steeltoe.Samples.Configuration.Models;
using Steeltoe.Samples.ConfigurationProviders.Models;

namespace Steeltoe.Samples.Configuration.Controllers;
namespace Steeltoe.Samples.ConfigurationProviders.Controllers;

public sealed class HomeController(
IOptionsSnapshot<ExternalConfiguration> configServerDataSnapshot, IOptionsSnapshot<ConfigServerClientOptions> configServerClientOptions,
IOptionsSnapshot<PlaceholderValues> placeholderValues, IOptions<CloudFoundryApplicationOptions> appOptions,
IOptions<CloudFoundryServicesOptions> serviceOptions, IConfiguration configuration) : Controller
{
private readonly ExternalConfiguration _dataSnapshot = configServerDataSnapshot.Value;

private readonly ConfigServerClientOptions _configServerClientOptions = configServerClientOptions.Value;

private readonly PlaceholderValues _placeholderResolverValues = placeholderValues.Value;

private readonly ExternalConfiguration _dataSnapshot = configServerDataSnapshot.Value;
private readonly ConfigServerClientOptions _configServerClientOptions = configServerClientOptions.Value;
private readonly PlaceholderValues _placeholderResolverValues = placeholderValues.Value;
private readonly CloudFoundryApplicationOptions _applicationOptions = appOptions.Value;
private readonly CloudFoundryServicesOptions _serviceOptions = serviceOptions.Value;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<SteeltoeVersion>4.0.*-*</SteeltoeVersion>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Steeltoe.Configuration.CloudFoundry;

namespace Steeltoe.Samples.Configuration.Models;
namespace Steeltoe.Samples.ConfigurationProviders.Models;

public sealed class CloudFoundryViewModel(CloudFoundryApplicationOptions applicationOptions, CloudFoundryServicesOptions servicesOptions)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Steeltoe.Samples.ConfigurationProviders.Models;

public class ErrorViewModel
{
public string? RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Steeltoe.Samples.Configuration.Models;
namespace Steeltoe.Samples.ConfigurationProviders.Models;

/// <summary>
/// This object contains the configuration values provided by a configuration service. The source of these values is here:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Steeltoe.Samples.Configuration.Models;
namespace Steeltoe.Samples.ConfigurationProviders.Models;

public sealed class ExternalConfigurationInfo
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Steeltoe.Samples.Configuration.Models;
namespace Steeltoe.Samples.ConfigurationProviders.Models;

public sealed class PlaceholderValues
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,31 @@
using Steeltoe.Configuration.Placeholder;
using Steeltoe.Configuration.RandomValue;
using Steeltoe.Management.Endpoint;
using Steeltoe.Samples.Configuration.Models;
using Steeltoe.Samples.ConfigurationProviders.Models;

// Steeltoe: Log to the console until the app has fully started.
var bootstrapLoggerFactory = BootstrapLoggerFactory.CreateConsole(loggingBuilder =>
{
loggingBuilder.AddConfiguration(new ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string, string?>
{
["LogLevel:Steeltoe.Configuration"] = "Trace"
}).Build());
});

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();

// Steeltoe: Add Configuration providers.
builder.Configuration.AddRandomValueSource(BootstrapLoggerFactory.Default);
builder.Configuration.AddRandomValueSource(bootstrapLoggerFactory);
builder.Configuration.AddKubernetesServiceBindings();
builder.Configuration.AddCloudFoundry(null, BootstrapLoggerFactory.Default);
builder.Configuration.AddPlaceholderResolver(BootstrapLoggerFactory.Default);
builder.AddConfigServer(BootstrapLoggerFactory.Default);
builder.Configuration.AddCloudFoundry(null, bootstrapLoggerFactory);
builder.Configuration.AddPlaceholderResolver(bootstrapLoggerFactory);
builder.AddConfigServer(bootstrapLoggerFactory);

// Steeltoe: Upgrade the created bootstrap loggers from settings in the service container.
builder.Services.UpgradeBootstrapLoggerFactory(bootstrapLoggerFactory);

// Steeltoe: Add actuator endpoints.
builder.AddAllActuators();
Expand Down Expand Up @@ -49,8 +61,6 @@

app.UseAuthorization();

app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");

app.Run();
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Steeltoe.Common.Logging" Version="$(SteeltoeVersion)" />
<PackageReference Include="Steeltoe.Configuration.CloudFoundry" Version="$(SteeltoeVersion)" />
<PackageReference Include="Steeltoe.Configuration.ConfigServer" Version="$(SteeltoeVersion)" />
<PackageReference Include="Steeltoe.Configuration.Kubernetes.ServiceBinding" Version="$(SteeltoeVersion)" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@using Steeltoe.Common
@using Steeltoe.Configuration.CloudFoundry
@model CloudFoundryViewModel
@model Steeltoe.Samples.ConfigurationProviders.Models.CloudFoundryViewModel
@{
ViewData["Title"] = "CloudFoundry Configuration data from VCAP_APPLICATION & VCAP_SERVICES";
ViewData["Title"] = "Cloud Foundry Configuration data from VCAP_APPLICATION and VCAP_SERVICES";
}

<h2>@ViewData["Title"]</h2>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model ExternalConfiguration;
@model Steeltoe.Samples.ConfigurationProviders.Models.ExternalConfiguration;
@{
ViewData["Title"] = "Configuration Data";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model PlaceholderValues
@model Steeltoe.Samples.ConfigurationProviders.Models.PlaceholderValues
@{
ViewData["Title"] = "Placeholder Values";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model ErrorViewModel
@model Steeltoe.Samples.ConfigurationProviders.Models.ErrorViewModel
@{
ViewData["Title"] = "Error";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
<title>@ViewData["Title"] - Steeltoe Configuration Sample</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/Steeltoe.Samples.Configuration.styles.css" asp-append-version="true" />
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Steeltoe.Samples.Configuration</a>
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Steeltoe.Samples.ConfigurationProviders</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
Expand All @@ -38,7 +37,7 @@

<footer class="border-top footer text-muted">
<div class="container">
&copy; @DateTime.Now.Year - Steeltoe.Samples.Configuration - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
&copy; 2024 - Steeltoe.Samples.ConfigurationProviders - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</div>
</footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@using Steeltoe.Samples.ConfigurationProviders;
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"Spring": {
"Cloud": {
"Config": {
"Name": "foo"
"Name": "foo",
"PollingInterval": "00:00:05"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: "services.apps.tanzu.vmware.com/v1alpha1"
kind: ResourceClaim
metadata:
name: my-config
name: sample-config-service
namespace: apps
spec:
ref:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
apiVersion: carto.run/v1alpha1
kind: Workload
metadata:
name: steeltoe-configuration-sample
name: configuration-providers-sample
labels:
apps.tanzu.vmware.com/workload-type: web
app.kubernetes.io/part-of: steeltoe-samples
tanzu.app.live.view: "true"
tanzu.app.live.view.application.flavours: steeltoe
tanzu.app.live.view.application.name: steeltoe-configuration-sample
tanzu.app.live.view.application.name: configuration-providers-sample
spec:
build:
env:
Expand All @@ -32,10 +32,10 @@ spec:
ref:
apiVersion: services.apps.tanzu.vmware.com/v1alpha1
kind: ResourceClaim
name: my-config
name: sample-config-service
source:
git:
url: https://github.com/SteeltoeOSS/Samples
subPath: Configuration/src/Steeltoe.Samples.Configuration
subPath: Configuration/src/ConfigurationProviders
ref:
branch: config
branch: latest
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
---
applications:
- name: steeltoe-configuration-sample
- name: configuration-providers-sample
buildpacks:
- binary_buildpack
memory: 128M
random-route: true
stack: windows
command: cmd /c .\Steeltoe.Samples.Configuration --urls=http://0.0.0.0:%PORT%
command: cmd /c .\Steeltoe.Samples.ConfigurationProviders --urls=http://0.0.0.0:%PORT%
env:
# ASPNETCORE_ENVIRONMENT value is lower-cased here to match the files in the config repository at:
# https://github.com/spring-cloud-samples/config-repo
ASPNETCORE_ENVIRONMENT: development
DOTNET_CLI_TELEMETRY_OPTOUT: "true"
DOTNET_NOLOGO: "true"
services:
- myConfigServer
- sampleConfigServer
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
applications:
- name: steeltoe-configuration-sample
- name: configuration-providers-sample
buildpacks:
- dotnet_core_buildpack
memory: 128M
Expand All @@ -13,4 +13,4 @@ applications:
DOTNET_CLI_TELEMETRY_OPTOUT: "true"
DOTNET_NOLOGO: "true"
services:
- myConfigServer
- sampleConfigServer
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ def setup(context):
"""
cf = cloudfoundry.CloudFoundry(context)
# remove previous app
app = 'steeltoe-configuration-sample'
app = 'configuration-providers-sample'
cf.delete_app(app)
# create service
service = 'p.config-server'
plan = 'standard'
instance = 'myConfigServer'
instance = 'sampleConfigServer'
args = ['-c', './config-server.json']
cf.create_service(service, plan, instance, args)
2 changes: 1 addition & 1 deletion Configuration/src/Steeltoe.Samples.Configuration.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
..\..\CommonTasks.md = ..\..\CommonTasks.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.Samples.Configuration", "Steeltoe.Samples.Configuration\Steeltoe.Samples.Configuration.csproj", "{82489734-D845-44FA-9EAB-1ED0A7013E51}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.Samples.ConfigurationProviders", "ConfigurationProviders\Steeltoe.Samples.ConfigurationProviders.csproj", "{82489734-D845-44FA-9EAB-1ED0A7013E51}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading