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

switch to new Cheetah.OpenSearch+Kafka packages #41

Closed
wants to merge 7 commits into from
Closed
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
16 changes: 6 additions & 10 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# [Choice] .NET version: 6.0-bullseye-slim, 6.0-jammy, 6.0-focal
FROM mcr.microsoft.com/devcontainers/dotnet:1-6.0-jammy
FROM mcr.microsoft.com/devcontainers/dotnet:1-8.0-bookworm

ENV DOCKER_BUILDKIT=1
ENV DOCKER_DEFAULT_PLATFORM=linux/amd64
Expand All @@ -8,16 +8,12 @@ ENV DOCKER_DEFAULT_PLATFORM=linux/amd64
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends git curl exa

# Install Docker to use in docker-in-docker
RUN apt-get update && apt-get install -y curl \
&& rm -rf /var/lib/apt/lists/* \
&& curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh
# Add user "admin" to the Docker group
#&& usermod -a -G docker admin
ADD https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/bash/docker /etc/bash_completion.d/docker.sh

USER vscode
#USER vscode
ARG GITHUB_ACTOR
ARG GITHUB_TOKEN

RUN dotnet nuget add source https://nuget.pkg.github.com/trifork/index.json -n trifork-github -u $GITHUB_ACTOR -p $GITHUB_TOKEN --store-password-in-clear-text

# Install dotnet outdated
RUN dotnet tool update --global dotnet-outdated-tool
ENV PATH="$PATH:/root/.dotnet/tools"
24 changes: 7 additions & 17 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,29 @@
},
"containerEnv": {
"GITHUB_ACTOR": "${localEnv:GITHUB_ACTOR}",
"GITHUB_TOKEN": "${localEnv:GITHUB_TOKEN}"
"GITHUB_TOKEN": "${localEnv:GITHUB_TOKEN}",
"DOTNET_ROLL_FORWARD": "LatestMajor",
"DOTNET_HOST_PATH": "/usr/share/dotnet/dotnet"
},
"runArgs": [
// Network where OpenSearch is running
"--network=cheetah-infrastructure"
],
"initializeCommand": "docker network create cheetah-infrastructure || true",
"customizations": {
"vscode": {
"extensions": [
// Recommended extensions - GitHub
"GitHub.vscode-pull-request-github",
"GitHub.copilot",
// Recommended extensions - Collaboration
"eamodio.gitlens",
"EditorConfig.EditorConfig",
"MS-vsliveshare.vsliveshare-pack",
"streetsidesoftware.code-spell-checker",
"redhat.vscode-yaml",
// Recommended extensions - .NET
"Fudge.auto-using",
"jongrant.csharpsortusings",
"kreativ-software.csharpextensions",
// Recommended extensions - Markdown
"bierner.github-markdown-preview",
"DavidAnson.vscode-markdownlint",
"docsmsft.docs-linting",
"yzhang.markdown-all-in-one",
// Required extensions
"ms-dotnettools.csharp",
"VisualStudioExptTeam.vscodeintellicode",
"aliasadidev.nugetpackagemanagergui"
]
"aliasadidev.nugetpackagemanagergui",
"ms-dotnettools.csdevkit"
],
}
},
"features": {
Expand All @@ -63,5 +53,5 @@
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root"
"remoteUser": "root"
}
14 changes: 14 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"dotnetAcquisitionExtension.installTimeoutValue": 500,
"dotnet.dotnetPath": "/usr/share/dotnet",
"dotnetAcquisitionExtension.existingDotnetPath": [
{
"extensionId": "msazurermtools.azurerm-vscode-tools",
"path": "/usr/share/dotnet/dotnet"
},
{
"extensionId": "visualstudiotoolsforunity.vstuc",
"path": "/usr/share/dotnet/dotnet"
}
]
}
4 changes: 2 additions & 2 deletions src/Cheetah.WebApi.Test/Cheetah.WebApi.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.4" />
<PackageReference Include="xunit" Version="2.6.5" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
15 changes: 8 additions & 7 deletions src/Cheetah.WebApi/Cheetah.WebApi.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<LangVersion>10</LangVersion>
<LangVersion>Latest</LangVersion>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<DocumentationFile>Cheetah.WebApi.xml</DocumentationFile>
<UserSecretsId>bb3fdc17-ede2-42c1-82cf-eae032a2caa5</UserSecretsId>
Expand All @@ -15,21 +15,22 @@
</Target>

<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="6.0.5" />
<PackageReference Include="Cheetah.WebApi.Shared" Version="1.7.0" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="8.0.0" />
<PackageReference Include="Cheetah.OpenSearch" Version="0.1.0" />
<PackageReference Include="Cheetah.Kafka" Version="0.1.0" />
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.25" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="5.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="OpenSearch.Client" Version="1.6.0" />
<PackageReference Include="OpenSearch.Client.JsonNetSerializer" Version="1.6.0" />
<PackageReference Include="prometheus-net" Version="8.2.1" />
<PackageReference Include="prometheus-net.AspNetCore" Version="8.2.1" />
<PackageReference Include="prometheus-net.AspNetCore.HealthChecks" Version="8.2.1" />
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
5 changes: 5 additions & 0 deletions src/Cheetah.WebApi/Cheetah.WebApi.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions src/Cheetah.WebApi/Core/Config/OpenSearchConfig.cs

This file was deleted.

14 changes: 0 additions & 14 deletions src/Cheetah.WebApi/Core/Config/Priorities.cs

This file was deleted.

18 changes: 10 additions & 8 deletions src/Cheetah.WebApi/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build

ARG GITHUB_ACTOR
ARG GITHUB_TOKEN
Expand All @@ -14,9 +14,14 @@ WORKDIR /src
COPY "src/NuGet-CI.Config" "NuGet.config"
COPY "src/.config/" ".config/"
COPY ["src/Cheetah.WebApi/Cheetah.WebApi.csproj", "Cheetah.WebApi/"]

# This is only needed because swagger uses .NET 7
ENV DOTNET_ROLL_FORWARD=LatestMajor

RUN --mount=type=secret,id=GITHUB_TOKEN \
GITHUB_TOKEN="$(cat /run/secrets/GITHUB_TOKEN)" \
dotnet restore "Cheetah.WebApi/Cheetah.WebApi.csproj"

COPY src .
WORKDIR "/src/Cheetah.WebApi"
RUN dotnet build "Cheetah.WebApi.csproj" -c Release -o /app/build
Expand All @@ -25,14 +30,11 @@ FROM build AS publish
RUN dotnet publish "Cheetah.WebApi.csproj" -c Release -o /app/publish

FROM base AS final
# Create a new user with bash and a homedir
RUN useradd -r -u 1001 -m -s /bin/bash dotnetuser

# Set the user for subsequent commands
USER 1001

ENV COMPlus_EnableDiagnostics=0

WORKDIR /app
COPY --from=publish /app/publish .

# 64198
USER $APP_UID
ENTRYPOINT ["dotnet", "Cheetah.WebApi.dll"]
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using FluentValidation.AspNetCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Cheetah.WebApi.Shared.Infrastructure.ServiceProvider;
using Cheetah.WebApi.Core.Config;

namespace Cheetah.WebApi.Infrastructure.Installers
{

[InstallerPriority(Priorities.BeforeConfig)]
public class FluentValidationInstaller : IServiceCollectionInstaller
public static class FluentValidationInstaller
{
public void Install(IServiceCollection services, IHostEnvironment hostEnvironment)
public static void InstallFluentValidation(this IServiceCollection services)
{
services.AddFluentValidation(config =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Prometheus;
using Cheetah.WebApi.Shared.Infrastructure.ServiceProvider;
using Cheetah.WebApi.Core.Config;

namespace Cheetah.WebApi.Infrastructure.Installers
{
[InstallerPriority(Priorities.AfterConfig)]
public class HealthCheckInstaller : IServiceCollectionInstaller
public static class HealthCheckInstaller
{
public void Install(IServiceCollection services, IHostEnvironment hostEnvironment)
public static void InstallHealthChecks(this IServiceCollection services)
{
services.AddHealthChecks()
.ForwardToPrometheus();
Expand Down

This file was deleted.

29 changes: 29 additions & 0 deletions src/Cheetah.WebApi/Infrastructure/Installers/KafkaInstaller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.Extensions.DependencyInjection;
using Cheetah.WebApi.Core.Config;
using Confluent.Kafka;
using Cheetah.Kafka.Extensions;
using Microsoft.Extensions.Configuration;

namespace Cheetah.WebApi.Infrastructure.Installers
{
public static class KafkaInstaller
{
public static void InstallKafka(this IServiceCollection services, Microsoft.Extensions.Configuration.ConfigurationManager configuration)
{
var kafkaConsumerOptions = configuration.Get<KafkaConsumerConfig>();
services.AddCheetahKafka(configuration, options =>
{
options.ConfigureDefaultConsumer(config =>
{
config.AllowAutoCreateTopics = false;
config.GroupId = kafkaConsumerOptions.ConsumerName;
config.AutoOffsetReset = AutoOffsetReset.Latest;
config.EnableAutoCommit = true;
});
})
// todo: SetErrorHandler && SecurityProtocol
.WithConsumer<Ignore, string>()
.WithProducer<string, string>();
}
}
}
Loading