Skip to content

Instantly share code, notes, and snippets.

@cdhunt
Last active October 20, 2020 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdhunt/9f3028063b1f5c90b781cc10f4fc749a to your computer and use it in GitHub Desktop.
Save cdhunt/9f3028063b1f5c90b781cc10f4fc749a to your computer and use it in GitHub Desktop.
#Requires -Module Requirements
& {
@{
Describe = 'SecretManagement is installed'
Test = {
$module = Get-Module -Name Microsoft.PowerShell.SecretManagement -ListAvailable -ErrorAction SilentlyContinue
$module.Version -contains '0.2.1'
}
Set = {
Install-Module -Name Microsoft.PowerShell.SecretManagement -RequiredVersion 0.2.1-alpha1 -AllowPrerelease -Force
}
}
@{
Describe = 'A New-Password function exists'
Test = { Test-Path function:\New-Password }
Set = {
New-Item Function:New-Password -Value {
param (
[int]$Count = 32,
[switch]$AsSecureString
)
function generator {
param (
[int]$c
)
(@((48..57) + (65..90) + (97..122)) | Get-Random -Count $c | ForEach-Object { [char]$_ }) -join ''
}
if ($AsSecureString) {
ConvertTo-SecureString -String (generator($Count)) -AsPlainText -Force
}
else {
generator($Count)
}
}
}
}
@{
Describe = 'SQL SA Password secret is created'
Test = {
$secrets = Get-SecretInfo
$secrets.Name -contains 'proget-sql'
}
Set = {
Set-Secret -Name 'proget-sql' -Secret (New-Password)
}
}
@{
Describe = 'Docker is running'
Test = {
$service = Get-Service -Name com.docker.service
$service.Status -eq 'Running'
}
Set = {
Start-Service -Name com.docker.service
}
}
@{
Describe = 'Docker Network is created'
Test = {
$networks = docker network ls --format '{{json .}}' | ConvertFrom-Json
$networks.Name -contains 'proget'
}
Set = {
docker network create proget
}
}
@{
Describe = 'SQL Server image is cached'
Test = {
$images = docker images --format '{{json .}}' | ConvertFrom-Json | Where-Object { $_.Repository -eq 'mcr.microsoft.com/mssql/server' -and $_.Tag -eq '2019-latest' }
$images.count -ge 1
}
Set = {
docker pull -q mcr.microsoft.com/mssql/server:2019-latest
}
}
@{
Describe = 'SQL Server container exists'
Test = {
$container = docker container ls -a --filter "name=proget-sql" --format '{{json .}}' | ConvertFrom-Json
$container.count -eq 1 -and $container.Networks -eq 'proget' -and $container.Image -eq 'mcr.microsoft.com/mssql/server:2019-latest'
}
Set = {
docker container create --name proget-sql `
-e 'ACCEPT_EULA=Y' -e "MSSQL_SA_PASSWORD=$(Get-Secret -Name proget-sql -AsPlainText)" `
-e 'MSSQL_PID=Express' --net=proget --restart=unless-stopped `
-d mcr.microsoft.com/mssql/server:2019-latest
}
}
@{
Describe = 'SQL Server container is running'
Test = {
$containers = docker ps --format '{{json .}}' | ConvertFrom-Json
$containers.Names -contains 'proget-sql'
}
Set = { docker start proget-sql }
}
@{
Describe = 'Create ProGet db'
Test = {
$result = & docker exec -it proget-sql /opt/mssql-tools/bin/sqlcmd `
-S localhost -U SA -P "$(Get-Secret -Name proget-sql -AsPlainText)" `
-Q 'IF DB_ID(''ProGet'') IS NOT NULL print 1'
$result -eq 1
}
Set = {
docker exec -it proget-sql /opt/mssql-tools/bin/sqlcmd `
-S localhost -U SA -P "$(Get-Secret -Name proget-sql -AsPlainText)" `
-Q 'CREATE DATABASE [ProGet] COLLATE SQL_Latin1_General_CP1_CI_AS'
}
}
@{
Describe = 'Proget image is cached'
Test = {
$images = docker images --format '{{json .}}' | ConvertFrom-Json | Where-Object { $_.Repository -eq 'proget.inedo.com/productimages/inedo/proget' -and $_.Tag -eq '5.3.13' }
$images.count -ge 1
}
Set = {
docker pull -q proget.inedo.com/productimages/inedo/proget:5.3.13
}
}
@{
Describe = 'Proget container exists'
Test = {
$container = docker container ls -a --filter "name=proget" --format '{{json .}}' | ConvertFrom-Json | Where-Object Names -eq 'proget'
$container.count -eq 1 -and $container.Networks -eq 'proget' -and $container.Image -eq 'proget.inedo.com/productimages/inedo/proget:5.3.13'
}
Set = {
docker container create -v C:\Downloads\proget-packages:/var/proget/packages -p 8080:80 --net=proget `
--name=proget --restart=unless-stopped `
-e SQL_CONNECTION_STRING="Data Source=proget-sql; Initial Catalog=ProGet; User ID=sa; Password=$(Get-Secret -Name proget-sql -AsPlainText)" `
proget.inedo.com/productimages/inedo/proget:5.3.13
}
}
@{
Describe = 'Local proget-packages folder exists'
Test = { Test-Path 'C:\Downloads\proget-packages' }
Set = { mkdir C:\Downloads\proget-packages }
}
@{
Describe = 'Proget container is running'
Test = {
$containers = docker ps --format '{{json .}}' | ConvertFrom-Json
$containers.Names -contains 'proget'
}
Set = { docker start proget }
}
} | Invoke-Requirement | Format-Checklist
@cdhunt
Copy link
Author

cdhunt commented Sep 28, 2020

An install script for spinning up a local instance of ProGet server inside Docker.

https://docs.inedo.com/docs/proget/installation/installation-guide/linux-docker

@cdhunt
Copy link
Author

cdhunt commented Sep 29, 2020

Example output

> .\Install-Proget.ps1
√ 09:16:49 SecretManagement is installed
√ 09:16:49 A New-Password function exists
√ 09:16:49 SQL SA Password secret is created
√ 09:16:49 Docker Network is created
√ 09:16:50 SQL Server image is cached
√ 09:16:50 SQL Server container exists
√ 09:16:50 SQL Server container is running
√ 09:16:51 Create ProGet db
√ 09:16:51 Proget image is cached
√ 09:16:51 Proget container exists
√ 09:16:51 Local proget-packages folder exists
√ 09:16:53 Proget container is running

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment