Skip to content

Commit 6f139c9

Browse files
committed
add rabbitmq user and fix the ferretdb database name
1 parent ea4b3f8 commit 6f139c9

19 files changed

Lines changed: 1531 additions & 2704 deletions

File tree

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ This is not meant to be the only way to do things. It's just a set of defaults t
4545
- [.NET SDK 10](https://dotnet.microsoft.com/download)
4646
- [Node.js LTS](https://nodejs.org/)
4747

48-
4948
## Quick start
5049

5150
Download the generator script from the [latest release](https://github.com/ftechmax/msa-templates/releases/latest) and run it. The script automatically installs the matching `MSA.Templates` NuGet package and downloads the matching Kubernetes manifests.
@@ -55,14 +54,14 @@ Download the generator script from the [latest release](https://github.com/ftech
5554
```sh
5655
curl -fsSLO https://github.com/ftechmax/msa-templates/releases/latest/download/generator.sh && \
5756
chmod +x generator.sh && \
58-
./generator.sh ~/git AwesomeApp rabbitmq-default-user
57+
./generator.sh ~/git AwesomeApp
5958
```
6059

6160
**PowerShell (Windows):**
6261

6362
```powershell
6463
Invoke-WebRequest -Uri https://github.com/ftechmax/msa-templates/releases/latest/download/generator.ps1 -OutFile generator.ps1 ; `
65-
.\generator.ps1 -DestinationFolder c:/git -ServiceName AwesomeApp -RabbitMqUserSecret rabbitmq-default-user
64+
.\generator.ps1 -DestinationFolder c:/git -ServiceName AwesomeApp
6665
```
6766

6867
> ⚠️ Security note: the commands above will run a script pulled from the net. Convenient? Absolutely. Auditable? Not unless you read it first.

generator.ps1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ param (
33
[string]$DestinationFolder = "C:/git",
44
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
55
[string]$ServiceName,
6-
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
7-
[string]$RabbitMqUserSecret,
86
[Parameter(Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
97
[string]$Namespace = "default"
108
)
@@ -22,6 +20,7 @@ if ($ServiceName -notmatch '^[A-Z][a-zA-Z0-9]+$') {
2220
# Prepare service name
2321
$kebabCaseServiceName = ($ServiceName -creplace '([A-Z]+)([A-Z][a-z])', '$1-$2' -creplace '([a-z0-9])([A-Z])', '$1-$2').toLower()
2422
$dotCaseServiceName = ($ServiceName -creplace '([A-Z]+)([A-Z][a-z])', '$1.$2' -creplace '([a-z0-9])([A-Z])', '$1.$2')
23+
$snakeCaseServiceName = $kebabCaseServiceName -replace '-', '_'
2524

2625
# Install matching template version
2726
$csproj = Join-Path (Join-Path $ScriptDir "src") "MSA.Templates.csproj"
@@ -84,8 +83,8 @@ Get-ChildItem -Path "$ProjectFolder/k8s" -Recurse | ForEach-Object {
8483
Write-Host "Patching $filePath"
8584

8685
(Get-Content -Path $filePath) `
87-
-creplace '{{RABBITMQ-SECRET-NAME}}', $RabbitMqUserSecret `
8886
-creplace '{{NAMESPACE}}', $Namespace `
87+
-creplace 'applicationname_snake', $snakeCaseServiceName `
8988
-creplace 'applicationname', $kebabCaseServiceName `
9089
-creplace 'ApplicationName', $dotCaseServiceName `
9190
| Set-Content -Path $filePath

generator.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ GENERATOR_VERSION="develop"
55
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
66
GITHUB_REPO="ftechmax/msa-templates"
77

8-
if [ "$#" -lt 3 ]; then
9-
echo "Usage: $0 <destination_folder> <service_name> <rabbitmq_user_secret> [namespace]" >&2
8+
if [ "$#" -lt 2 ]; then
9+
echo "Usage: $0 <destination_folder> <service_name> [namespace]" >&2
1010
exit 1
1111
fi
1212

1313
DESTINATION_FOLDER="$1"
1414
SERVICE_NAME="$2"
15-
RABBITMQ_USER_SECRET="$3"
16-
NAMESPACE="${4:-default}"
15+
NAMESPACE="${3:-default}"
1716

1817
# Validate service name is PascalCase
1918
if [[ ! "$SERVICE_NAME" =~ ^[A-Z][a-zA-Z0-9]+$ ]]; then
@@ -24,6 +23,7 @@ fi
2423
# Prepare service name
2524
KEBAB_CASE_SERVICE_NAME=$(printf '%s' "$SERVICE_NAME" | sed -E 's/([A-Z]+)([A-Z][a-z])/\1-\2/g' | sed -E 's/([a-z0-9])([A-Z])/\1-\2/g' | tr '[:upper:]' '[:lower:]')
2625
DOT_CASE_SERVICE_NAME=$(printf '%s' "$SERVICE_NAME" | sed -E 's/([A-Z]+)([A-Z][a-z])/\1.\2/g' | sed -E 's/([a-z0-9])([A-Z])/\1.\2/g')
26+
SNAKE_CASE_SERVICE_NAME=$(printf '%s' "$KEBAB_CASE_SERVICE_NAME" | tr '-' '_')
2727

2828
# Install matching template version
2929
CSPROJ="$SCRIPT_DIR/src/MSA.Templates.csproj"
@@ -82,8 +82,8 @@ cp -R "$K8S_SOURCE" "$PROJECT_FOLDER"
8282
find "$PROJECT_FOLDER/k8s" -type f -print0 | while IFS= read -r -d '' file_path; do
8383
echo "Patching $file_path"
8484
tmp_file="$file_path.tmp"
85-
sed -e "s/{{RABBITMQ-SECRET-NAME}}/$RABBITMQ_USER_SECRET/g" \
86-
-e "s/{{NAMESPACE}}/$NAMESPACE/g" \
85+
sed -e "s/{{NAMESPACE}}/$NAMESPACE/g" \
86+
-e "s/applicationname_snake/$SNAKE_CASE_SERVICE_NAME/g" \
8787
-e "s/applicationname/$KEBAB_CASE_SERVICE_NAME/g" \
8888
-e "s/ApplicationName/$DOT_CASE_SERVICE_NAME/g" \
8989
"$file_path" > "$tmp_file"

k8s/base/api/deployment.yaml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,16 @@ spec:
3838
containerPort: 8080
3939
env:
4040
- name: rabbitmq__host
41-
valueFrom:
42-
secretKeyRef:
43-
name: '{{RABBITMQ-SECRET-NAME}}'
44-
key: host
41+
value: rabbitmq.default.svc
4542
- name: rabbitmq__username
4643
valueFrom:
4744
secretKeyRef:
48-
name: '{{RABBITMQ-SECRET-NAME}}'
45+
name: applicationname-rabbitmq
4946
key: username
5047
- name: rabbitmq__password
5148
valueFrom:
5249
secretKeyRef:
53-
name: '{{RABBITMQ-SECRET-NAME}}'
50+
name: applicationname-rabbitmq
5451
key: password
5552
- name: valkey__connection-string
5653
value: 'applicationname-cache:6379'
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
apiVersion: k8s.ftechmax.net/v1alpha1
33
kind: FerretDbUser
44
metadata:
5-
name: applicationname-user
5+
name: applicationname-database
66
spec:
7-
database: applicationname
8-
secret: applicationname-user
7+
database: applicationname_snake
8+
secret: applicationname-database
99
roles:
1010
- readWrite
1111
- dbAdmin

k8s/base/kustomization.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ apiVersion: kustomize.config.k8s.io/v1beta1
33
kind: Kustomization
44
resources:
55
- ./sa.yaml
6+
- ./rabbitmq-user.yaml
7+
- ./database-user.yaml
68
- ./worker
79
- ./api
810
- ./web

k8s/base/rabbitmq-user.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
apiVersion: rabbitmq.com/v1beta1
3+
kind: Permission
4+
metadata:
5+
name: applicationname-rabbitmq
6+
spec:
7+
vhost: /
8+
userReference:
9+
name: applicationname-rabbitmq
10+
permissions:
11+
write: '.*'
12+
configure: '.*'
13+
read: '.*'
14+
rabbitmqClusterReference:
15+
name: rabbitmq
16+
namespace: default
17+
---
18+
apiVersion: rabbitmq.com/v1beta1
19+
kind: User
20+
metadata:
21+
name: applicationname-rabbitmq
22+
spec:
23+
rabbitmqClusterReference:
24+
name: rabbitmq
25+
namespace: default
26+
importCredentialsSecret:
27+
name: applicationname-rabbitmq

k8s/base/worker/deployment.yaml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,19 @@ spec:
3737
containerPort: 8080
3838
envFrom:
3939
- secretRef:
40-
name: applicationname-user
40+
name: applicationname-database
4141
env:
4242
- name: rabbitmq__host
43-
valueFrom:
44-
secretKeyRef:
45-
name: '{{RABBITMQ-SECRET-NAME}}'
46-
key: host
43+
value: rabbitmq.default.svc
4744
- name: rabbitmq__username
4845
valueFrom:
4946
secretKeyRef:
50-
name: '{{RABBITMQ-SECRET-NAME}}'
47+
name: applicationname-rabbitmq
5148
key: username
5249
- name: rabbitmq__password
5350
valueFrom:
5451
secretKeyRef:
55-
name: '{{RABBITMQ-SECRET-NAME}}'
52+
name: applicationname-rabbitmq
5653
key: password
5754
- name: mongodb__connection-string
5855
value: 'mongodb://$(database_username):$(database_password)@ferretdb.ferretdb-system.svc:27017/'

k8s/base/worker/kustomization.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
apiVersion: kustomize.config.k8s.io/v1beta1
33
kind: Kustomization
44
resources:
5-
- ./db-user.yaml
65
- ./deployment.yaml
7-
- ./service.yaml
6+
- ./service.yaml

k8s/overlays/development/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
apiVersion: kustomize.config.k8s.io/v1beta1
33
kind: Kustomization
4-
namespace: {{NAMESPACE}}
4+
namespace: '{{NAMESPACE}}'
55
resources:
66
- ./../../base
77
images:

0 commit comments

Comments
 (0)