You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.5KB

  1. #Requires -Version 5.1
  2. <#
  3. .SYNOPSIS
  4. Pulls the repo on the server, copies .env_prod as .env, then starts the container.
  5. .EXAMPLE
  6. .\docker-publish.ps1
  7. .\docker-publish.ps1 -SshKey "~/.ssh/id_rsa"
  8. #>
  9. param(
  10. [string]$SshKey = ""
  11. )
  12. Set-StrictMode -Version Latest
  13. $ErrorActionPreference = "Stop"
  14. # ---------------------------------------------------------------------------
  15. # Configuration
  16. # ---------------------------------------------------------------------------
  17. $SSH_HOST = "192.168.1.200"
  18. $SSH_USER = "root"
  19. $REPO_PATH = "/root/kanban"
  20. $REPO_URL = "https://onefortheroadgit.sytes.net/dcovington/KCI-PHP-KANBAN.git"
  21. # ---------------------------------------------------------------------------
  22. # Helpers
  23. # ---------------------------------------------------------------------------
  24. function Write-Step([string]$msg) {
  25. Write-Host "`n==> $msg" -ForegroundColor Cyan
  26. }
  27. function Get-BaseArgs {
  28. $a = @("-o", "StrictHostKeyChecking=accept-new")
  29. if ($SshKey -ne "") { $a += @("-i", $SshKey) }
  30. return $a
  31. }
  32. # Deploy whichever branch is currently checked out locally.
  33. $BRANCH = (git rev-parse --abbrev-ref HEAD).Trim()
  34. Write-Host "Branch: $BRANCH" -ForegroundColor Yellow
  35. # ---------------------------------------------------------------------------
  36. # Step 1 — clone or pull the repo (first password prompt)
  37. # ---------------------------------------------------------------------------
  38. Write-Step "Syncing repo on $SSH_USER@$SSH_HOST"
  39. $prepCmd = "set -e; "
  40. $prepCmd += "if [ -d '$REPO_PATH/.git' ]; then "
  41. $prepCmd += "cd '$REPO_PATH' && git fetch origin && git checkout $BRANCH && git pull origin $BRANCH; "
  42. $prepCmd += "else "
  43. $prepCmd += "git clone --branch $BRANCH '$REPO_URL' '$REPO_PATH'; "
  44. $prepCmd += "fi"
  45. $sshArgs = Get-BaseArgs
  46. $sshArgs += "$SSH_USER@$SSH_HOST", $prepCmd
  47. ssh @sshArgs
  48. if ($LASTEXITCODE -ne 0) { Write-Error "Repo sync failed (exit $LASTEXITCODE)." }
  49. # ---------------------------------------------------------------------------
  50. # Step 2 — copy .env_prod as .env into the now-existing repo dir (second prompt)
  51. # ---------------------------------------------------------------------------
  52. Write-Step "Copying .env_prod to $SSH_USER@$SSH_HOST as .env"
  53. $scpArgs = Get-BaseArgs
  54. $scpArgs += ".env_prod", "${SSH_USER}@${SSH_HOST}:${REPO_PATH}/.env"
  55. scp @scpArgs
  56. if ($LASTEXITCODE -ne 0) { Write-Error "scp failed (exit $LASTEXITCODE)." }
  57. # ---------------------------------------------------------------------------
  58. # Step 3 — copy the SQLite database (disabled — do not overwrite live data)
  59. # ---------------------------------------------------------------------------
  60. # Write-Step "Copying database/app.sqlite to $SSH_USER@$SSH_HOST"
  61. # $scpDbArgs = Get-BaseArgs
  62. # $scpDbArgs += "database/app.sqlite", "${SSH_USER}@${SSH_HOST}:${REPO_PATH}/database/app.sqlite"
  63. # scp @scpDbArgs
  64. # if ($LASTEXITCODE -ne 0) { Write-Error "scp database failed (exit $LASTEXITCODE)." }
  65. # ---------------------------------------------------------------------------
  66. # Step 4 — start the container (third password prompt)
  67. # ---------------------------------------------------------------------------
  68. Write-Step "Starting container on $SSH_USER@$SSH_HOST"
  69. $deployCmd = "set -e; "
  70. $deployCmd += "docker rm -f kci-kanban-app 2>/dev/null || true; "
  71. $deployCmd += "cd '$REPO_PATH' && docker compose up -d --build --wait"
  72. $sshArgs = Get-BaseArgs
  73. $sshArgs += "$SSH_USER@$SSH_HOST", $deployCmd
  74. ssh @sshArgs
  75. if ($LASTEXITCODE -ne 0) { Write-Error "Deployment failed (exit $LASTEXITCODE)." }
  76. Write-Host "`nDone. KCI Kanban is running on $SSH_HOST." -ForegroundColor Green

Powered by TurnKey Linux.