Merge branch 'development_cryptpad' into development_nile_installers

* development_cryptpad:
  feat(cryptpad): Refactor installer configuration logic
  feat(cryptpad): Refactor installer for dynamic configuration
This commit is contained in:
2025-11-25 18:39:27 +01:00
7 changed files with 87 additions and 36 deletions

View File

@@ -31,6 +31,16 @@ installer.install()!
## Usage
### Running the Installer
You can run the installer directly from the command line using the example script:
```bash
./examples/installers/k8s/cryptpad.vsh
```
This will install CryptPad with the default settings. To customize the installation, you can edit the `cryptpad.vsh` file.
### Create an Instance
```v

View File

@@ -60,7 +60,7 @@ fn install() ! {
// 4. Apply the YAML files using kubernetes client
console.print_info('Applying Gateway YAML file to the cluster...')
res1 := k8s.apply_yaml('/tmp/tfgw-cryptpad.yaml')!
res1 := k8s.apply_yaml(installer.tfgw_cryptpad_path)!
if !res1.success {
return error('Failed to apply tfgw-cryptpad.yaml: ${res1.stderr}')
}
@@ -72,7 +72,7 @@ fn install() ! {
// 6. Apply Cryptpad YAML
console.print_info('Applying Cryptpad YAML file to the cluster...')
res2 := k8s.apply_yaml('/tmp/cryptpad.yaml')!
res2 := k8s.apply_yaml(installer.cryptpad_path)!
if !res2.success {
return error('Failed to apply cryptpad.yaml: ${res2.stderr}')
}

View File

@@ -156,8 +156,8 @@ pub fn play(mut plbook PlayBook) ! {
// load from disk and make sure is properly intialized
pub fn (mut self CryptpadServer) reload() ! {
switch(self.name)
self = obj_init(self)!
set(self)!
}
@[params]

View File

@@ -15,6 +15,7 @@ pub mut:
hostname string // The CryptPad hostname
backends string // The backends for the TFGW
namespace string // The namespace for the CryptPad deployment
config_js string // Generated config.js content
}
@[heap]
@@ -23,8 +24,9 @@ pub mut:
name string = 'cryptpad'
hostname string
namespace string
cryptpad_path string = '/tmp/cryptpad.yaml'
tfgw_cryptpad_path string = '/tmp/tfgw-cryptpad.yaml'
cryptpad_path string = '/tmp/cryptpad/cryptpad.yaml'
tfgw_cryptpad_path string = '/tmp/cryptpad/tfgw-cryptpad.yaml'
config_js_path string = '/tmp/cryptpad/config.js'
kube_client kubernetes.KubeClient @[skip]
}
@@ -32,12 +34,26 @@ pub mut:
fn obj_init(mycfg_ CryptpadServer) !CryptpadServer {
mut mycfg := mycfg_
if mycfg.name == '' {
mycfg.name = 'cryptpad'
}
// Replace the dashes, dots, and underscores with nothing
mycfg.name = mycfg.name.replace('_', '')
mycfg.name = mycfg.name.replace('-', '')
mycfg.name = mycfg.name.replace('.', '')
if mycfg.namespace == '' {
mycfg.namespace = mycfg.name
mycfg.namespace = '${mycfg.name}-cryptpad-namespace'
}
if mycfg.namespace.contains('_') || mycfg.namespace.contains('.') {
console.print_stderr('namespace cannot contain _, was: ${mycfg.namespace}, use dashes instead.')
return error('namespace cannot contain _, was: ${mycfg.namespace}')
}
if mycfg.hostname == '' {
mycfg.hostname = mycfg.name
mycfg.hostname = '${mycfg.name}cryptpad'
}
mycfg.kube_client = kubernetes.get(create: true)!
@@ -57,20 +73,40 @@ fn configure() ! {
backends_str_builder.writeln(' - "http://[${ip}]:80"')
}
config_values := ConfigValues{
// Create config_values for template generation
mut config_values := ConfigValues{
hostname: installer.hostname
backends: backends_str_builder.str()
namespace: installer.namespace
config_js: ''
}
console.print_info('Generating YAML files from templates...')
temp := $tmpl('./templates/tfgw-cryptpad.yaml')
mut temp_path := pathlib.get_file(path: installer.tfgw_cryptpad_path, create: true)!
temp_path.write(temp)!
// Generate config.js
config_js_raw := $tmpl('./templates/config.js')
temp2 := $tmpl('./templates/cryptpad.yaml')
mut temp_path2 := pathlib.get_file(path: installer.cryptpad_path, create: true)!
temp_path2.write(temp2)!
// Indent the configs for proper YAML formatting (4 spaces for ConfigMap data)
config_js_lines := config_js_raw.split('\n')
mut config_js_indented := strings.new_builder(config_js_raw.len + 100)
for line in config_js_lines {
if line.len > 0 {
config_js_indented.writeln(' ${line}')
}
}
// Update config_values with the generated and indented configs
config_values.config_js = config_js_indented.str()
// Ensure the output directory exists
_ := pathlib.get_dir(path: '/tmp/cryptpad', create: true)!
console.print_info('Generating YAML files from templates...')
tfgw_yaml := $tmpl('./templates/tfgw-cryptpad.yaml')
mut tfgw_path := pathlib.get_file(path: installer.tfgw_cryptpad_path, create: true)!
tfgw_path.write(tfgw_yaml)!
cryptpad_yaml := $tmpl('./templates/cryptpad.yaml')
mut cryptpad_path := pathlib.get_file(path: installer.cryptpad_path, create: true)!
cryptpad_path.write(cryptpad_yaml)!
console.print_info('YAML files generated successfully.')
}

View File

@@ -0,0 +1,16 @@
module.exports = {
httpUnsafeOrigin: 'https://@{config_values.hostname}.gent01.grid.tf',
httpSafeOrigin: 'https://@{config_values.hostname}sb.gent01.grid.tf',
httpAddress: '0.0.0.0',
httpPort: 80,
websocketPort: 3003,
websocketPath: '/cryptpad_websocket',
blockPath: './block',
blobPath: './blob',
dataPath: './data',
filePath: './datastore',
logToStdout: true,
logLevel: 'info',
};

View File

@@ -10,22 +10,7 @@ metadata:
namespace: @{config_values.namespace}
data:
config.js: |
module.exports = {
httpUnsafeOrigin: 'https://@{config_values.hostname}.gent01.grid.tf',
httpSafeOrigin: 'https://@{config_values.hostname}sb.gent01.grid.tf',
httpAddress: '0.0.0.0',
httpPort: 80,
websocketPort: 3003,
websocketPath: '/cryptpad_websocket',
blockPath: './block',
blobPath: './blob',
dataPath: './data',
filePath: './datastore',
logToStdout: true,
logLevel: 'info',
};
@{config_values.config_js}
---
apiVersion: apps/v1
kind: Deployment