PSEC - Powershell Enhanced Capability
Version 1.2.1

Task Execute for: Deploy Application

Properties

Implemented Functions

getTaskDesc Function Meta


    function getTaskDesc([Task]$task) {
      $tfs = $task.tfs;
      $gfn = $tfs.globMap.gaelGlobs.gfn;
      [string]$desc       = @"
This deploys the GAEL web app to production project $($gfn.gaelProj)

Note: There is radio silence for about 5 minutes "@ return $desc }

params Function Meta



    # ---------- define task parameters
    function params([Task]$task,[hashtable]$htOpts) {
      $parms = @{};
      $parms.brief    = "$($task.statlocn)"
      $parms.str      = "create Brief"
      $parms.gen      = "5"
      $parms.genstr   = "output line from parm defintition line="
      $parms.bool1    = $null
      $parms['swkey=']  = 'key-value';
      return  $parms
    }

    # ---------- define task options
    <#function options {
      param([Object]$task)
      $opts = @();
      $opts += @{type='input';  parm='gen';     label='Gen';     place='number of lines to generate'; regex='^[0-9]+$'}
      $opts += @{type='input';  parm='genstr';  label='GenStr';  place='string to generate'}
      $opts += @{type='input';  parm='genbrf';  label='GenBrf';  place='number of brief.GenArr lines to generate'; regex='^[0-9]+$'}
      $opts += @{type='check';  parm='bool1';   label='bool1';   place='turns on bool1 option when checked'}
      $opts += @{type='radio';  parm='trap';    label='trap';    valset='*/*no trap,fail/gen FAIL,trap/gen TRAP'}
      $opts += @{type='combo';  parm='combo';   label='combo';   valset='*/*--none--,green,red/show red,blue/set blue'}
      return  ,$opts
    }#>

prepareDeploy func-prepareDeploy



    function prepareDeploy([string]$locn) {
      $targ = "$($locn)\war\res"
      $date = Get-Date
      $textDeploy = "deploy:$($date.ToString('yyyy-MM-dd.HH:mm:ss:fff'))"
      $textDeploy | Set-Content $targ\txt\deploy-ts.txt
      return $textDeploy
    }

runScript Function Meta



    # ---------- the actual script
    function runScript([Task]$task, [hashtable]$parms, [hashtable]$status) {
      $tfs = $task.tfs;
      $gfn = $tfs.globMap.gaelGlobs.gfn;
      hlogBoth("Running deployment script $($task.name) locn $locn curBase $($gfn.curBase)")
      $locn = "$($gfn.curBase)"
      $warBase = "$($gfn.curBase)/war"
      $prodWar = "$($warBase)-prod"
      hilite -yellow "Deploy $($gfn.gaelServer.desc) locns $locn $warBase $prodWar"
      $status.deploy = "$($gfn.gaelProj)"
      $status.locn   = "$locn"
      $status.title  = "$($gfn.gaelServer.desc)"
      try {
        [void](& prepareDeploy $locn)
        [int]$nJarLines = (& $ENV:GAELIC_HOME\ps\prodify.ps1 "$locn")
      } catch {
        $e = $_
        hlog("prodify error");
        hLogErr("$( $e.exception.message ) $($e.getType() )")
        hLogErr("$( $e.ScriptStackTrace )")
        return;
      }
      $status.prodify = "executed $prodWar"
      hlogBoth("prodify completed $($status.prodify)")
      # this contortion allows us to run in a command window so we avoid radio silence while the deploy executes
      $var1 = "$($prodWar)/WEB-INF/appengine-web.xml"
      $fileStr = (Get-Content -path $var1 -raw -encoding ascii)
      $fileStr -match "(?[^>]*)"
      $var2 = "--project=$($gfn.gaelProj)"
      # we should check this to see it matches with $matches['proj']
      $cmd  = "gcloud app deploy $var1 $var2 --quiet && pause check-out"
      hilite -magenta $cmd
      $status.run="deploy $prodWar"
      if ($nJarLines -lt 0) {
        $status.sCondCode = "FAIL";
        $status.sReason = "jar build incorrect code=$nJarLines";
      }  else {
        $status.jarLines = "jar OK with $nJarLines entries";
      }
      <#
        cit671.gae@gmail.com
        srp7474@gmail.com
        to set the active account, run:
          $ gcloud config set account `ACCOUNT`
          gcloud config set account cit671.gae@gmail.com

          gcloud config set project PROJECTID

        # K instead of C to keep window alive
      # >
      }
      hlogBoth("Cmd $cmd");
      Start-Process -FilePath "C:\Windows\System32\cmd.exe" -verb runas -ArgumentList '/K',"$cmd"
    }

PSEC - Powershell Enhanced Capability
1.2.1

Copyright © 2018-2021, 2022, Rexcel System Inc.

 

 

 

 

 

X