Skip to content

Commit

Permalink
tenant creation auto generate k8s yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabi-02 committed Jan 19, 2024
1 parent ef95457 commit c189f8f
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 8 deletions.
42 changes: 42 additions & 0 deletions tenant/frontend-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend-%tenant%-deployment
spec:
replicas: 1
selector:
matchLabels:
app: frontend-%tenant%
template:
metadata:
labels:
app: frontend-%tenant%
spec:
containers:
- name: frontend-%tenant%
image: rtwcr1.azurecr.io/frontend
ports:
- containerPort: 3000
envFrom:
- secretRef:
name: all_credentials
env:
- name: VITE_TENANT
value: %tenant%
- name: VITE_TENANT_CLIENT_ID
value: %applicationId%
- name: VITE_TENANT_BACKGROUNDCOLOR
value: "%backgroundColor%"
---
apiVersion: v1
kind: Service
metadata:
name: frontend-%tenant%
spec:
type: ClusterIP
ports:
- name: http
port: %port%
targetPort: 3000
selector:
app: frontend-%tenant%
53 changes: 51 additions & 2 deletions fusionauth/package-lock.json → tenant/package-lock.json

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

7 changes: 4 additions & 3 deletions fusionauth/package.json → tenant/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"name": "fusionauth",
"name": "tenant",
"version": "1.0.0",
"description": "",
"main": "fa-tenant-creation.js",
"main": "tenant-creation.js",
"scripts": {
"start": "node fa-tenant-creation.js"
"start": "node tenant-creation.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"@fusionauth/node-client": "^1.48.0",
"prompt-sync": "^4.2.0",
"uuid": "^9.0.1"
}
}
22 changes: 19 additions & 3 deletions fusionauth/fa-tenant-creation.js → tenant/tenant-creation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const uuid = require('uuid');
const { FusionAuthClient } = require('@fusionauth/node-client');
const prompt = require('prompt-sync')();
const fs = require('fs');

const appUrl = 'http://localhost';
const client = new FusionAuthClient('33052c8a-c283-4e96-9d2a-eb1215c69f8f-not-for-prod', 'http://localhost:9011');
Expand Down Expand Up @@ -68,13 +70,27 @@ async function create(tenantName) {
}
}

function createK8sFrontendYaml(tenant, applicationId, port, backgroundColor) {
let frontendYaml = fs.readFileSync('./frontend-template.yaml', 'utf8');
const replacements = { "%tenant%": tenant, "%applicationId%": applicationId, "%port%": port, "%backgroundColor%": backgroundColor };
let frontendTenantYaml = frontendYaml.replace(/%\w+%/g, function(all) {
return replacements[all] || all;
});
// TODO: deployement typo
fs.writeFileSync(`../deployement/k8s/frontend-${tenant}.yaml`, frontendTenantYaml);
}

async function main() {
const tenantName = "adac";
const {tenantId, applicationId, clientSecret} = await create(tenantName);
console.log(`Created tenant ${tenantName}`);
const tenant = prompt("Tenant name (key): ");
const port = prompt("Port: ");
const backgroundColor = "#" + prompt("Background-Color: #");
const {tenantId, applicationId, clientSecret} = await create(tenant);
console.log(`Created tenant ${tenant}`);
console.log(`- Tenant ID: ${tenantId}`);
console.log(`- Application ID: ${applicationId}`);
console.log(`- Client Secret: ${clientSecret}`);
console.log();
createK8sFrontendYaml(tenant, applicationId, port, backgroundColor);
}

main();

0 comments on commit c189f8f

Please sign in to comment.