SkyWire-Docker.psm1
<# .SYNOPSIS Remove all containers. .DESCRIPTION Stops all processors and removes all containers. .EXAMPLE Remove-SkyWireContainer #> function Remove-SkyWireContainer { Stop-SkyWireContainer docker rm $(docker ps -aq) } <# .SYNOPSIS Create a docker-compose.yaml for Pos/WebConfig. .DESCRIPTION Create a docker-compose.yaml consisting of Pos, WebConfig, and Pos database containers. .PARAMETER PosTag Specify the Jira ticket number + pre-release tag for Pos if running a pre-release version. If not specified, all apps will be ran with tag "latest". .PARAMETER WcTag Specify the Jira ticket number + pre-release tag for WebConfig if running a pre-release version. If not specified, all apps will be ran with tag "latest". .PARAMETER DbTag Specify the Jira ticket number + pre-release tag for Pos database if running a pre-release version. If not specified, all apps will be ran with tag "latest". .PARAMETER RptTag Specify the Jira ticket number + pre-release tag for Reporting database if running a pre-release version. If not specified, all apps will be ran with tag "latest". .PARAMETER DataDir Specify the working directory where docker-compose.yaml will be created. .PARAMETER Version Specify the docker-compose.yaml version (default: 3.4). .PARAMETER WcPort Specify a port for WebConfig to run on (default: 8000). .PARAMETER PosImage Specify the name of the pos docker image (default: skywireinc/pos). Leave this unless the repository changes. .PARAMETER WcImage Specify the name of the WecConfig docker image (default: skywireinc/webconfig). Leave this unless the repository changes. .PARAMETER DbImage Specify the name of the pos database docker image (default: skywireinc/pos-db). Leave this unless the repository changes. .PARAMETER RptImage Specify the name of the reporting database docker image (default: skywireinc/reporting-db). Leave this unless the repository changes. .EXAMPLE New-SkyWirePosDockerYaml -posTag POS-999-beta -wcTag POS-999-beta -dbTag dev -rptTag dev -dataDir c:\temp #> function New-SkyWirePosDockerYaml { param( [Parameter(Mandatory=$true)] [string] $posTag, [Parameter(Mandatory=$true)] [string] $wcTag, [Parameter(Mandatory=$true)] [string] $dbTag, [Parameter(Mandatory=$true)] [string] $rptTag, [Parameter(Mandatory=$true)] [string] $dataDir, [Parameter(Mandatory=$false)] [string] $version = "3.4", [Parameter(Mandatory=$false)] [int] $wcPort = 8000, [Parameter(Mandatory=$false)] [string] $posImage = "skywireinc/pos", [Parameter(Mandatory=$false)] [string] $wcImage = "skywireinc/webconfig", [Parameter(Mandatory=$false)] [string] $dbImage = "skywireinc/pos-db", [Parameter(Mandatory=$false)] [string] $rptImage = "skywireinc/reporting-db" ) Write-Verbose "Current data dir: $dataDir" if (Test-Path $dataDir) { Write-Verbose "Removing existing data dir: $dataDir" Remove-Item -Path $dataDir -Recurse } Write-Verbose "Creating data dir: $dataDir" New-Item -Path $dataDir -ItemType Directory $pos = @{ image = "$($posImage):$($posTag)" volumes = @("$($dataDir):C:\exports") } $rpt = @{ image = "$($rptImage):$rptTag" volumes = @("$($dataDir):C:\Reporting") depends_on = @("pos") } $db = @{ image = "$($dbImage):$dbTag" ports = @("1433:1433") volumes = @("$($dataDir):C:\data") depends_on = @("rpt") } $wc = @{ image = "$($wcImage):$wcTag" ports = @("$($wcPort):80") depends_on = @("db") } $services = @{ pos = $pos db = $db wc = $wc rpt = $rpt } # Version must be first for docker-compose.yaml $yaml = New-Object ([System.Collections.Specialized.OrderedDictionary]); $yaml.Add("version", $version) $yaml.Add("services", $services) Write-Verbose "Writing $dataDir\docker-compose.yaml" Write-Verbose "$yaml" ConvertTo-Yaml $yaml | Out-File "$dataDir\docker-compose.yaml" } <# .SYNOPSIS Run Pos using docker-compose. .DESCRIPTION Run WebConfig and Pos database in docker-compose. This function will open the data directory where Pos installation resides. **Ensure that all containers are started and database is migrated before installing. Local SQL must be stopped.** .PARAMETER Tag Specify the Jira ticket number + pre-release tag for Pos if running a pre-release version. If not specified, all apps will be ran with tag "latest". .PARAMETER WcTag Specify the Jira ticket number + pre-release tag for WebConfig if running a pre-release version. If not specified, all apps will be ran with tag "latest". .PARAMETER DbTag Specify the docker tag for Pos database. If not specified, all apps will be ran with tag "latest". .PARAMETER RptTag Specify the docker tag for reporting database. If not specified, all apps will be ran with tag "latest". .PARAMETER Port Specify a port for WebConfig to run on. .PARAMETER RootDir Specify the root directory where all data will reside for the current session (default: %TEMP%\SkyWire\SkyWire-Docker) .EXAMPLE Start-SkyWirePos # Run production Pos .EXAMPLE Start-SkyWirePos -port 8001 -rootDir C:\temp\mydata # Run WebConfig on a port and a specific root directory for data where Pos installation file will reside. .EXAMPLE Start-SkyWirePos -tag POS-5470-beta # Run Pos beta version for Jira ticket# POS-5470 #> function Start-SkyWirePos { param( [Parameter(Mandatory=$false)] [string] $tag = "latest", [Parameter(Mandatory=$false)] [string] $wcTag = "latest", [Parameter(Mandatory=$false)] [string] $dbTag = "latest", [Parameter(Mandatory=$false)] [string] $rptTag = "latest", [Parameter(Mandatory=$false)] [int] $port = 8000, [Parameter(Mandatory=$false)] [string] $rootDir = "$env:TEMP\SkyWire\SkyWire-Docker" ) $posTag = $tag $wcPort = $port if ($tag -ne "latest") { # If wcTag is default (not user specified) then ask if ($wcTag -eq "latest") { $wcTag = Read-Host -Prompt "Enter WebConfig tag (default: $posTag)" if (!$wcTag) { $wcTag = $posTag } } # If dbTag is default (not user specified) then ask if ($dbTag -eq "latest") { $dbTag = Read-Host -Prompt "Enter database tag (default: dev)" if (!$dbTag) { $dbTag = "dev" } } # If rptTag is default (not user specified) then ask if ($rptTag -eq "latest") { $rptTag = Read-Host -Prompt "Enter reporting tag (default: dev)" if (!$rptTag) { $rptTag = "dev" } } } $dataDir = "$rootDir\$posTag" Write-Verbose "Creating docker-compose.yaml file" New-SkyWirePosDockerYaml -posTag $posTag -wcTag $wcTag -wcPort $wcPort -dbTag $dbTag -rptTag $rptTag -dataDir $dataDir Write-Verbose "Starting docker-compose" Write-Verbose "WebConfig: http://localhost:$wcPort" Write-Verbose "SQL: localhost" Write-Verbose "Opening $dataDir" Write-Information "Ensure that all containers are running and the database is migrated before instaling Pos" # Open the data directory so that the user can install POS Start-Process $dataDir Start-SkyWireDockerCompose -file "$dataDir\docker-compose.yaml" } <# .SYNOPSIS Run WebConfig using docker-compose. .DESCRIPTION Run WebConfig with Pos database with docker-compose. **This requires local SQL to be stopped.** .PARAMETER Tag Specify the Jira ticket number + pre-release tag for WebConfig if running a pre-release version. If not specified, all apps will be ran with tag "latest". .PARAMETER Port Specify a port for WebConfig to run on. .PARAMETER PosTag Specify the Jira ticket number + pre-release tag for Pos if running a pre-release version. If not specified, all apps will be ran with tag "latest". .PARAMETER DbTag Specify the docker tag for Pos database. If not specified, all apps will be ran with tag "latest". .PARAMETER RptTag Specify the docker tag for Reporting database. If not specified, all apps will be ran with tag "latest". .PARAMETER RootDir Specify the root directory where all data will reside for the current session (default: %TEMP%\SkyWire\SkyWire-Docker) .EXAMPLE Start-SkyWireWebConfig # Run production WebConfig .EXAMPLE Start-SkyWireWebConfig -port 8001 -rootDir C:\temp\mydata # Run WebConfig on a port and a specific root directory for data. .EXAMPLE Start-SkyWireWebConfig -tag POS-5470-beta # Run WebConfig beta version for Jira ticket# POS-5470 #> function Start-SkyWireWebConfig { param( [Parameter(Mandatory=$false)] [string] $tag = "latest", [Parameter(Mandatory=$false)] [int] $port = 8000, [Parameter(Mandatory=$false)] [string] $posTag = "latest", [Parameter(Mandatory=$false)] [string] $dbTag = "latest", [Parameter(Mandatory=$false)] [string] $rptTag = "latest", [Parameter(Mandatory=$false)] [string] $rootDir = "$env:TEMP\SkyWire\SkyWire-Docker" ) $wcTag = $tag $wcPort = $port if ($tag -ne "latest") { # If posTag is default (not user specified) then ask if ($posTag -eq "latest") { $posTag = Read-Host -Prompt "Enter Pos tag (default: $wcTag)" if (!$posTag) { $posTag = $wcTag } } # If dbTag is default (not user specified) then ask if ($dbTag -eq "latest") { $dbTag = Read-Host -Prompt "Enter database tag (default: dev)" if (!$dbTag) { $dbTag = "dev" } } # If rptTag is default (not user specified) then ask if ($rptTag -eq "latest") { $rptTag = Read-Host -Prompt "Enter database tag (default: dev)" if (!$rptTag) { $rptTag = "dev" } } } $dataDir = "$rootDir\$wcTag" Write-Verbose "Creating docker-compose.yaml file" New-SkyWirePosDockerYaml -posTag $posTag -wcTag $wcTag -wcPort $wcPort -dbTag $dbTag -rptTag $rptTag -dataDir $dataDir Write-Verbose "Starting docker-compose" Write-Verbose "WebConfig: http://localhost:$wcPort" Write-Verbose "SQL: localhost" Start-SkyWireDockerCompose -file "$dataDir\docker-compose.yaml" } <# .SYNOPSIS Stop all running containers. .DESCRIPTION Stop all running docker containers. .EXAMPLE Stop-SkyWireContainer #> function Stop-SkyWireContainer { docker ps stop $(docker ps -aq) } <# .SYNOPSIS Run docker-compose up. .DESCRIPTION Run docker-compose up by specify the docker-compose.yaml file. .EXAMPLE Start-SkyWireDockerCompose -File C:\temp\docker-compose.yaml #> function Start-SkyWireDockerCompose { param( [Parameter(Mandatory=$true)] [string] $file ) Write-Verbose "Running ""docker-compose -f $file up""" docker-compose -f $file up } Export-ModuleMember -Function Remove-SkyWireContainer Export-ModuleMember -Function New-SkyWirePosDockerYaml Export-ModuleMember -Function Start-SkyWireDockerCompose Export-ModuleMember -Function Start-SkyWirePos Export-ModuleMember -Function Start-SkyWireWebConfig Export-ModuleMember -Function Stop-SkyWireContainer |