-
-
Save jermdavis/25655ee9c095d20d15caf42fa3d27ded to your computer and use it in GitHub Desktop.
An example of checking license expiry before starting Sitecore docker containers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param( | |
[switch]$build = $false, | |
[switch]$attach = $false | |
) | |
function Validate-LicenseData | |
{ | |
Param ( | |
$EnvironmentFile = ".env", | |
$EnvironmentKey = "SITECORE_LICENSE" | |
) | |
$file = Get-Content $EnvironmentFile -Encoding UTF8 | |
$key = $file | ForEach-Object { | |
if($_ -imatch "^$EnvironmentKey=.*") | |
{ | |
return $_.SubString($EnvironmentKey.Length + 1) | |
} | |
} | |
$data = [System.Convert]::FromBase64String($key) | |
$memory = [System.IO.MemoryStream]::new() | |
$memory.Write($data, 0, $data.Length) | |
$memory.Flush() | |
$memory.Seek(0, [System.IO.SeekOrigin]::Begin) | Out-Null | |
$gzip = [System.IO.Compression.GZipStream]::new($memory, [System.IO.Compression.CompressionMode]::Decompress) | |
$s = [System.IO.StreamReader]::new($gzip); | |
$xml = $s.ReadToEnd() | |
$s.Dispose(); | |
$gzip.Dispose() | |
$memory.Dispose(); | |
$xml -match '<expiration>(.*?)</expiration>' | Out-Null | |
$textExpiry = $Matches[1] | |
$expiry = [System.DateTime]::ParseExact($textExpiry, "yyyyMMddThhmmss", [System.Globalization.CultureInfo]::InvariantCulture) | |
if($expiry -lt [System.DateTime]::Now) | |
{ | |
throw "Your Sitecore license has expired." | |
} | |
else | |
{ | |
$daysLeft = [int]($expiry - [System.DateTime]::Now).TotalDays | |
Write-Host "You have $daysLeft days left on your license." -ForegroundColor Green | |
} | |
} | |
try | |
{ | |
pushd ".\docker" | |
Validate-LicenseData | |
$buildFlag = "" | |
if($build) | |
{ | |
$buildFlag = "--build" | |
} | |
Write-Host "Starting: XP=$xp, Build=$build, Attach=$attach" | |
$detachFlag = "--detach" | |
if($attach) | |
{ | |
$detachFlag = "" | |
} | |
docker-compose up $buildFlag $detachFlag | |
} | |
finally | |
{ | |
popd | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment