Generate user/pass for PowerShell deploy script
Generates the password to mirror deploy_stack.sh
Uses hardcoded admin to mirror deploy_stack.sh
Uses throw to exit when error
Updates faas-cli login command for Powershell
#!ps1
+param (
+ [switch] $noAuth,
+ [switch] $n
+)
+
if (Get-Command docker -errorAction SilentlyContinue)
{
docker node ls 2>&1 | out-null
- if($?)
+ if(-Not $?)
{
+ throw "Docker not in swarm mode, please initialise the cluster (`docker swarm init`) and retry"
+ }
+
+ Add-Type -AssemblyName System.Web
+ $secret = [System.Web.Security.Membership]::GeneratePassword(24,5)
+ $user = 'admin'
+
+ Write-Host "Attempting to create credentials for gateway.."
$user_secret = "basic-auth-user"
docker secret inspect $user_secret 2>&1 | out-null
if($?)
@@ -13,7 +26,6 @@ if (Get-Command docker -errorAction SilentlyContinue)
}
else
{
- $user = Read-Host 'Admin User?'
$user | docker secret create $user_secret -
}
@@ -25,20 +37,30 @@ if (Get-Command docker -errorAction SilentlyContinue)
}
else
{
- $pass = Read-Host 'Password?' -AsSecureString
- [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($pass)) | docker secret create $password_secret -
+ $secret | docker secret create $password_secret -
+ Write-Host "[Credentials]"
+ Write-Host " username: admin"
+ Write-Host " password: $secret"
+ Write-Host " Write-Output `"$secret`" | faas-cli login --username=$user --password-stdin"
}
- Write-Host "Deploying stack"
- docker stack deploy func --compose-file ./docker-compose.yml
-
+ if ($noAuth -Or $n) {
+ Write-Host ""
+ Write-Host "Disabling basic authentication for gateway.."
+ Write-Host ""
+ $env:BASIC_AUTH="false";
}
else
{
- Write-Host "Docker not in swarm mode, please initialise the cluster (`docker swarm init`) and retry"
+ Write-Host ""
+ Write-Host "Enabling basic authentication for gateway.."
+ Write-Host ""
}
+
+ Write-Host "Deploying stack"
+ docker stack deploy func --compose-file ./docker-compose.yml
}
else
{
- Write-Host "Unable to find docker command, please install Docker (https://www.docker.com/) and retry"
+ throw "Unable to find docker command, please install Docker (https://www.docker.com/) and retry"
}
