The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

569532 (7) [Avatar] Offline
#1
Another windows question,
I got stuck in the CI/CD chapter because of the OS. It doesn't seem possible to run the code and this would mean that I'd have to install Ubuntu (for example) to get the code to work.

I might do that in the future, but would be great to find a faster solution on windows?
Yan Cui (73) [Avatar] Offline
#2
Try installing the Windows Subsystem for Linux (WSL), alternatively, maybe create an equivalent shell script for windows seeing as the build script does only two things - npm install, and 'sls deploy'.

Another thing you can try is bypassing the build script entirely and just use NPM scripts instead. Add a NPM script - e.g. "deploy": ... - to run npm install and 'sls deploy' etc. and use that to drive your build steps instead.
569532 (7) [Avatar] Offline
#3
Ok cool, so this is what I did and it seems to work.
(readers, don't hesitate to let me know what can be done better)

# Run script: Powershell.exe -File build.ps1

# Get arguments
# Ref: https://stackoverflow.com/questions/2157554/how-to-handle-command-line-arguments-in-powershell
# Ref: https://stackoverflow.com/questions/15120597/passing-multiple-values-to-a-single-powershell-script-parameter

# Comparison Operators
# Ref: http://www.tomsitpro.com/articles/powershell-comparison-operators-conditional-logic,2-850.html
param (
    # [string]$deploy = "integration",
    # [string]$password = $( Read-Host "Input password, please" ),
    [Parameter(Mandatory=$true)][string]$action = "none",
    [Parameter(Mandatory=$false)][string]$env = ""
 )

# Print instructions
function instruction {
  Write-Output "<action> <env>"
  Write-Output ""
  Write-Output "-action, int-test, acceptance-test or deploy"
  Write-Output ""
  Write-Output "-env, [string]"
}

# Handle inputs
Try {
    if ($action -eq "int-test") {
        cmd /c 'npm install'
        cmd /c 'npm run integration-test'
    }
    elseif ($action -eq "acceptance-test") {
        cmd /c 'npm install'
        cmd /c 'npm run acceptance-test'
    }
    elseif (($action -eq "deploy") -and ($env -eq "")){
        cmd /c 'npm install'
        $pathToServerless = (Get-Item -Path ".\").FullName + "\node_modules\.bin\serverless.cmd deploy"
        cmd /c $pathToServerless
    }
    elseif (($action -eq "deploy") -and ($env -ne "")){
        cmd /c 'npm install'
        $pathToServerless = (Get-Item -Path ".\").FullName + "\node_modules\.bin\serverless.cmd deploy -s $env"
        cmd /c $pathToServerless
    }
    else {
        instruction
        exit
    }
} catch {
    $ErrorMessage = $_.Exception.Message
    $FailedItem = $_.Exception.ItemName
    Write-Output "Execution failed for $FailedItem. The error message was $ErrorMessage"
    Break
}