regressed lab-tool to 0.10-dev to make it again
This commit is contained in:
parent
646c8bbc20
commit
2fdf7e4b0c
31 changed files with 732 additions and 635 deletions
0
packages/lab-tool/deploy/default.scm
Normal file
0
packages/lab-tool/deploy/default.scm
Normal file
70
packages/lab-tool/deploy/executor.scm
Normal file
70
packages/lab-tool/deploy/executor.scm
Normal file
|
@ -0,0 +1,70 @@
|
|||
;; deploy/executor.scm - Impure execution layer
|
||||
|
||||
(define-module (deploy executor)
|
||||
#:use-module (ice-9 format)
|
||||
#:use-module (ice-9 popen)
|
||||
#:use-module (ice-9 textual-ports)
|
||||
#:use-module (srfi srfi-1)
|
||||
#:use-module (core config)
|
||||
#:export (execute-command
|
||||
execute-ssh-command
|
||||
execute-deploy-commands
|
||||
run-with-timeout))
|
||||
|
||||
;; Execute a single command locally
|
||||
(define (execute-command cmd)
|
||||
"Execute a command locally and return (exit-code . output)"
|
||||
(let* ((port (open-input-pipe cmd))
|
||||
(output (get-string-all port))
|
||||
(exit-code (close-pipe port)))
|
||||
(cons exit-code output)))
|
||||
|
||||
;; Execute a command over SSH
|
||||
(define (execute-ssh-command ssh-config cmd)
|
||||
"Execute a command over SSH using centralized SSH key configuration"
|
||||
(let* ((hostname (assoc-ref ssh-config 'hostname))
|
||||
(user (assoc-ref ssh-config 'user))
|
||||
(ssh-key (get-ssh-key))
|
||||
(ssh-cmd (format #f "ssh -i ~a -o BatchMode=yes ~a@~a '~a'"
|
||||
ssh-key user hostname cmd)))
|
||||
(execute-command ssh-cmd)))
|
||||
|
||||
;; Execute deployment commands in sequence
|
||||
(define (execute-deploy-commands deploy-plan)
|
||||
"Execute deployment commands from a deployment plan"
|
||||
(let ((rsync-cmd (assoc-ref deploy-plan 'rsync))
|
||||
(rebuild-cmd (assoc-ref deploy-plan 'rebuild))
|
||||
(ssh-config (assoc-ref deploy-plan 'ssh-config)))
|
||||
|
||||
(display "Starting deployment...\n")
|
||||
|
||||
;; Step 1: Rsync flake to remote
|
||||
(display "Step 1: Syncing flake to remote host...\n")
|
||||
(display (format #f "Running: ~a\n" rsync-cmd))
|
||||
(let ((rsync-result (execute-command rsync-cmd)))
|
||||
(if (= (car rsync-result) 0)
|
||||
(begin
|
||||
(display "Rsync completed successfully\n")
|
||||
|
||||
;; Step 2: Run nixos-rebuild on remote
|
||||
(display "Step 2: Running nixos-rebuild on remote host...\n")
|
||||
(display (format #f "Running: ~a\n" rebuild-cmd))
|
||||
(let ((rebuild-result (execute-ssh-command ssh-config rebuild-cmd)))
|
||||
(if (= (car rebuild-result) 0)
|
||||
(begin
|
||||
(display "Deployment completed successfully!\n")
|
||||
(display (cdr rebuild-result))
|
||||
#t)
|
||||
(begin
|
||||
(display "nixos-rebuild failed:\n")
|
||||
(display (cdr rebuild-result))
|
||||
#f))))
|
||||
(begin
|
||||
(display "Rsync failed:\n")
|
||||
(display (cdr rsync-result))
|
||||
#f)))))
|
||||
|
||||
;; Run command with timeout (placeholder for future implementation)
|
||||
(define (run-with-timeout cmd timeout)
|
||||
"Run command with timeout - simplified version"
|
||||
(execute-command cmd))
|
71
packages/lab-tool/deploy/ssh-strategy.scm
Normal file
71
packages/lab-tool/deploy/ssh-strategy.scm
Normal file
|
@ -0,0 +1,71 @@
|
|||
;; deploy/ssh-strategy.scm - Pure SSH deployment strategy
|
||||
|
||||
(define-module (deploy ssh-strategy)
|
||||
#:use-module (ice-9 format)
|
||||
#:use-module (srfi srfi-1)
|
||||
#:use-module (core config)
|
||||
#:use-module (core commands)
|
||||
#:export (build-ssh-deploy-commands
|
||||
build-rsync-command
|
||||
build-nixos-rebuild-command
|
||||
build-ssh-key-check-command
|
||||
get-deploy-options))
|
||||
|
||||
;; Pure function to get deploy options with defaults
|
||||
(define (get-deploy-options options)
|
||||
"Extract deployment options with sensible defaults"
|
||||
`((dry-run . ,(or (assoc-ref options 'dry-run) #f))
|
||||
(boot . ,(or (assoc-ref options 'boot) #f))
|
||||
(test . ,(or (assoc-ref options 'test) #f))
|
||||
(switch . ,(or (assoc-ref options 'switch) #f))
|
||||
(timeout . ,(or (assoc-ref options 'timeout) 300))))
|
||||
|
||||
;; Pure function to build SSH key check command
|
||||
(define (build-ssh-key-check-command host-config)
|
||||
"Build SSH key check command to verify connectivity"
|
||||
(let ((hostname (assoc-ref host-config 'hostname))
|
||||
(user (assoc-ref host-config 'user))
|
||||
(ssh-key (get-ssh-key)))
|
||||
(format #f "ssh -i ~a -o BatchMode=yes -o ConnectTimeout=5 ~a@~a 'echo \"SSH key check successful\"'"
|
||||
ssh-key user hostname)))
|
||||
|
||||
;; Pure function to build rsync command
|
||||
(define (build-rsync-command flake-path host-config)
|
||||
"Build rsync command to sync flake to remote host using /tmp"
|
||||
(let ((hostname (assoc-ref host-config 'hostname))
|
||||
(user (assoc-ref host-config 'user))
|
||||
(ssh-key (get-ssh-key)))
|
||||
(format #f "rsync -av --delete -e 'ssh -i ~a -o BatchMode=yes' ~a/ ~a@~a:/tmp/flake/"
|
||||
ssh-key flake-path user hostname)))
|
||||
|
||||
;; Pure function to build nixos-rebuild command
|
||||
(define (build-nixos-rebuild-command hostname options)
|
||||
"Build nixos-rebuild command for remote execution using /tmp/flake"
|
||||
(let ((mode (cond
|
||||
((assoc-ref options 'dry-run) "dry-run")
|
||||
((assoc-ref options 'boot) "boot")
|
||||
((assoc-ref options 'test) "test")
|
||||
((assoc-ref options 'switch) "switch")
|
||||
(else "switch"))))
|
||||
(format #f "sudo nixos-rebuild ~a --flake /tmp/flake#~a" mode hostname)))
|
||||
|
||||
;; Pure function to build complete SSH deployment commands
|
||||
(define (build-ssh-deploy-commands host-name options)
|
||||
"Build all commands needed for SSH deployment strategy"
|
||||
(let* ((host-config (get-host-config host-name))
|
||||
(flake-path (get-flake-path))
|
||||
(deploy-opts (get-deploy-options options)))
|
||||
(if host-config
|
||||
(let* ((hostname (assoc-ref host-config 'hostname))
|
||||
(user (get-config-value '(ssh-user) "sma"))
|
||||
(ssh-config `((hostname . ,hostname)
|
||||
(user . ,user)))
|
||||
(ssh-check-cmd (build-ssh-key-check-command ssh-config))
|
||||
(rsync-cmd (build-rsync-command flake-path ssh-config))
|
||||
(rebuild-cmd (build-nixos-rebuild-command hostname deploy-opts)))
|
||||
`((ssh-check . ,ssh-check-cmd)
|
||||
(rsync . ,rsync-cmd)
|
||||
(rebuild . ,rebuild-cmd)
|
||||
(ssh-config . ,ssh-config)
|
||||
(options . ,deploy-opts)))
|
||||
#f)))
|
Loading…
Add table
Add a link
Reference in a new issue