Skip to content
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
5 changes: 1 addition & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf

[*.yml]
indent_size = 2

[*.yaml]
[*.{yml,yaml,json,tf,md}]
indent_size = 2

[*.{cs,vb}]
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ and this project adheres to [Semantic Versioning v2.0.0](https://semver.org/spec
- Fix encoding
- Merge plan and plan-destroy terraform pipelines
- Configure HPA for services
- Fix the error Unable to unprotect the message.State.
1 change: 1 addition & 0 deletions build/configure-aks-cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ stages:
rabbitMqPassword: $(library-rabbitmq-password)
cloudflareApiKey: $(cloudflare-api-key)
cloudflareZone: $(cloudflare-zone-name)
redisPassword: $(library-redis-password)
transformTargetFiles: |
secrets/connection-secrets.yaml
18 changes: 18 additions & 0 deletions build/templates/configure-cluster-stages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ parameters:
displayName: 'Zone name of DNS in cloudflare (e.g razumovsky.me)'
type: string

- name: redisPassword
displayName: 'Password for Redis HELM release.'
type: string

stages:
- stage: 'Configure_AKS_${{ parameters.environment }}'
displayName: 'Configure_AKS_${{ parameters.environment }}'
Expand Down Expand Up @@ -130,6 +134,20 @@ stages:
pwsh: true
workingDirectory: ${{ parameters.workingDirectory }}

- task: PowerShell@2
displayName: 'Deploy Redis'
inputs:
targetType: 'inline'
script: |
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm upgrade --install event-redis bitnami/redis `
--namespace ${{ parameters.namespace }} `
--set auth.enabled=true `
--set auth.password="${{ parameters.redisPassword }}"
pwsh: true
workingDirectory: ${{ parameters.workingDirectory }}

- task: PowerShell@2
displayName: 'Wait for deployments'
inputs:
Expand Down
14 changes: 13 additions & 1 deletion kubernetes/auth-deployment-cluster-ip/auth-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ spec:
selector:
matchLabels:
app: event-triangle-auth-api
replicas: 1
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
Expand Down Expand Up @@ -46,5 +46,17 @@ spec:
name: connection-creds
key: AuthDatabaseConnectionString

- name: RedisUrl
valueFrom:
secretKeyRef:
name: connection-creds
key: RedisUrl

- name: RedisPassword
valueFrom:
secretKeyRef:
name: connection-creds
key: RedisPassword

- name: ASPNETCORE_ENVIRONMENT
value: "Docker"
2 changes: 1 addition & 1 deletion kubernetes/auth-deployment-cluster-ip/hpa.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: autoscaling/v2
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: event-triangle-auth-hpa
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/consumer-deployment-cluster-ip/hpa.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: autoscaling/v2
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: event-triangle-consumer-hpa
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/helm-install-grafana-prometheus/Example.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
kubectl create namespace monitoring
helm install prometheus prometheus-community/kube-prometheus-stack -n monitoring --set grafana.service.type=ClusterIP --set prometheus.service.type=ClusterIP
Expand Down
20 changes: 20 additions & 0 deletions kubernetes/helm-install-redis/Commands.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update

# Simple install command
helm upgrade --install event-redis bitnami/redis --namespace event-triangle

# Set password as a parameter
helm upgrade --install event-redis bitnami/redis `
--namespace event-triangle `
--set auth.enabled=true `
--set auth.password="MySecureRedisPassword"

# Get the base64 encoded password from the Kubernetes secret
$encodedPassword = kubectl get secret --namespace event-triangle event-redis -o jsonpath="{.data.redis-password}"

# Decode the base64 string
$decodedPassword = [System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($encodedPassword))

# Set the decoded password into the variable
$REDIS_PASSWORD = $decodedPassword
4 changes: 3 additions & 1 deletion kubernetes/secrets/connection-secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ stringData: # takes plain text secrets
POSTGRES_PASSWORD: "{{POSTGRES_PASSWORD}}"
POSTGRES_DB: "{{POSTGRES_DB}}"
RabbitMqUsername: "{{library-rabbitmq-user}}"
RabbitMqPassword: "{{library-rabbitmq-password}}"
RabbitMqPassword: "{{library-rabbitmq-password}}"
RedisUrl: "{{library-redis-url}}"
RedisPassword: "{{library-redis-password}}"
2 changes: 1 addition & 1 deletion kubernetes/sender-deployment-cluster-ip/hpa.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: autoscaling/v2
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: event-triangle-sender-hpa
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ public static class AppSettingsConstants
public const string AzureAdSelection = "AzureAd";

public const string ReverseProxySelection = "ReverseProxy";

public const string AdSecretKey = "EVENT_TRIANGLE_AD_CLIENT_SECRET";

public const string DevFrontendUrl = "DevFrontendUrl";

public const string AllowedOrigins = "AllowedOrigins";

public const string GrpcChannelAddresses = "GrpcChannelAddresses";
}

public const string RedisUrl = "RedisUrl";

public const string RedisPassword = "RedisPassword";
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="8.0.13" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="8.0.13" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="8.0.7" />
<PackageReference Include="StackExchange.Redis" Version="2.8.24" />
<PackageReference Include="Yarp.ReverseProxy" Version="2.1.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
using EventTriangleAPI.Authorization.Persistence;
using EventTriangleAPI.Authorization.Presentation.DependencyInjection;
using EventTriangleAPI.Shared.DTO.Models;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
using StackExchange.Redis;

var builder = WebApplication.CreateBuilder(args);

Expand Down Expand Up @@ -55,6 +57,34 @@

builder.Logging.AddFilter("Grpc", LogLevel.Debug);

// redis configs start

var redisUrl = builder.Configuration[AppSettingsConstants.RedisUrl];

if (string.IsNullOrEmpty(redisUrl))
{
throw new ArgumentNullException(nameof(redisUrl));
}

var redisPassword = builder.Configuration[AppSettingsConstants.RedisPassword];

if (string.IsNullOrEmpty(redisPassword))
{
throw new ArgumentNullException(nameof(redisPassword));
}

var redis = ConnectionMultiplexer.Connect(new ConfigurationOptions
{
EndPoints = { redisUrl },
Password = redisPassword,
AbortOnConnectFail = false
});

builder.Services.AddDataProtection()
.PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys");

// redis configs end

var app = builder.Build();

app.UseSwagger();
Expand Down Expand Up @@ -91,4 +121,4 @@
app.Map(SpaRouting.Tickets, config => config.UseSpa(spa => spa.Options.SourcePath = "/wwwroot"));
app.Map(SpaRouting.Users, config => config.UseSpa(spa => spa.Options.SourcePath = "/wwwroot"));

app.Run();
app.Run();
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
}
},
"AllowedHosts": "*",
"AllowedOrigins": ["http://localhost:4200", "http://localhost:7000"],
"AllowedOrigins": [
"http://localhost:4200",
"http://localhost:7000"
],
"DatabaseConnectionString": "Server=db;User Id=postgres;Password=postgres;Database=AuthorizationDb;",
"DevFrontendUrl": "http://localhost:4200",
"RedisUrl": "event-redis-master.event-triangle.svc.cluster.local",
"RedisPassword": "",
"AzureAd": {
"Authority": "https://login.microsoftonline.com/b40a105f-0643-4922-8e60-10fc1abf9c4b/v2.0/",
"Instance": "https://login.microsoftonline.com",
Expand All @@ -24,7 +29,7 @@
"GrpcChannelAddresses": "http://event-triangle-sender-service:81",
"ReverseProxy": {
"Routes": {
"route1" : {
"route1": {
"ClusterId": "cluster1",
"Match": {
"Path": "/sender/{**catch-all}"
Expand All @@ -35,7 +40,7 @@
}
]
},
"route2" : {
"route2": {
"ClusterId": "cluster2",
"Match": {
"Path": "/consumer/{**catch-all}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
}
},
"AllowedHosts": "*",
"AllowedOrigins": ["http://localhost:4200", "https://localhost:7000"],
"AllowedOrigins": [
"http://localhost:4200",
"https://localhost:7000"
],
"DatabaseConnectionString": "Server=localhost;User Id=postgres;Password=postgres;Database=AuthorizationDb;",
"DevFrontendUrl": "http://localhost:4200",
"RedisUrl": "event-redis-master.event-triangle.svc.cluster.local",
"RedisPassword": "",
"AzureAd": {
"Authority": "https://login.microsoftonline.com/b40a105f-0643-4922-8e60-10fc1abf9c4b/v2.0/",
"Instance": "https://login.microsoftonline.com",
Expand All @@ -24,7 +29,7 @@
"GrpcChannelAddresses": "https://localhost:7002",
"ReverseProxy": {
"Routes": {
"route1" : {
"route1": {
"ClusterId": "cluster1",
"Match": {
"Path": "/sender/{**catch-all}"
Expand All @@ -35,7 +40,7 @@
}
]
},
"route2" : {
"route2": {
"ClusterId": "cluster2",
"Match": {
"Path": "/consumer/{**catch-all}"
Expand Down Expand Up @@ -64,4 +69,4 @@
}
}
}
}
}
54 changes: 27 additions & 27 deletions terraform/.terraform.lock.hcl

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

2 changes: 1 addition & 1 deletion terraform/.tflint.hcl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
plugin "terraform" {
plugin "terraform" {
enabled = true
preset = "recommended"
}
Expand Down