Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
296 commits
Select commit Hold shift + click to select a range
8c42be5
Build succeeds after adding PrepareServer.sql and ResetValidationServ…
lizbaron Jul 2, 2021
9e45551
We do not have access to HKLM:\SOFTWARE\Microsoft\MSSQLServer\Client\…
lizbaron Jul 2, 2021
210e9d4
or silentlycontinue?
lizbaron Jul 3, 2021
f50fc39
test for null
lizbaron Jul 3, 2021
f5e4812
trust the connection or the server, or whatever else needs trust
lizbaron Jul 3, 2021
867ae1e
remove timeouts for powershell scripts in ant. we'll take care of thi…
lizbaron Jul 3, 2021
c336a6f
path names were wildly changed and we have a failing build
lizbaron Jul 6, 2021
cae4dca
Modified tSQLt step to create public files and validation files.
lizbaron Jul 7, 2021
af1ce15
added a backslash for consistency
lizbaron Jul 7, 2021
1727267
#asciiArt
lizbaron Jul 7, 2021
22f6705
Removed debugging from Build.ps1
lizbaron Jul 7, 2021
eefcef6
Import GitHub action for tSQLt build and test on spawn (https://githu…
lizbaron Jul 7, 2021
3b38cfc
possibly fixed the workflow
lizbaron Jul 8, 2021
6dba8fa
set retention period for artifacts in github actions
lizbaron Jul 8, 2021
e7e52d7
reorganizing the azure devops pipeline files, so that we can really b…
lizbaron Jul 8, 2021
33da684
Porting github actions for aks from https://github.com/lizbaron/db-ci…
lizbaron Jul 8, 2021
6042162
very very important indentation of random ascii art.
lizbaron Jul 9, 2021
5654b40
Merge branch 'main' of https://github.com/tSQLt-org/tSQLt into tSQLtF…
lizbaron Jul 14, 2021
fe9da0b
move AZ_NightlyCleanup.yml to trigger off of the main branch
lizbaron Jul 16, 2021
427f805
It's important to read the task...
lizbaron Jul 16, 2021
8b80744
All of the CI/ paths should change!
lizbaron Jul 16, 2021
a73cdab
Made things more compliant
lizbaron Jul 16, 2021
2ee72e0
We should change the name in all the places.
lizbaron Jul 16, 2021
e62ae15
Tasks are flaky so we use Set-Location $(Pipeline.Workspace)/tSQLt
lizbaron Jul 16, 2021
04ba65a
need to download the pipeline artifact
lizbaron Jul 17, 2021
a99fc1d
Playing with stage variables
lizbaron Jul 26, 2021
1b77dd2
removed spurious dependency
lizbaron Jul 26, 2021
1bc5116
random deletions because someone isn't paying attention.
lizbaron Jul 26, 2021
5353adc
add agent name
lizbaron Jul 26, 2021
2cc28a3
print out all the env
lizbaron Jul 26, 2021
5569324
where do all the variables go if not in the env?
lizbaron Jul 26, 2021
d53b826
more trying
lizbaron Jul 26, 2021
394095a
"a." doesn't work
lizbaron Jul 26, 2021
7ca3f78
syntax?
lizbaron Jul 26, 2021
1323b4b
parenthesis!
lizbaron Jul 27, 2021
dcc2358
testVar!
lizbaron Jul 27, 2021
7ac83a7
just trying things
lizbaron Jul 27, 2021
1a9ffb7
brackets
lizbaron Jul 27, 2021
a72ef2a
start here: https://docs.microsoft.com/en-us/azure/devops/pipelines/p…
lizbaron Jul 27, 2021
0018993
more variables
lizbaron Jul 28, 2021
300b92c
changed the names of the matrix
lizbaron Jul 28, 2021
2606753
env:
lizbaron Jul 28, 2021
b70e59e
trying round ones.
lizbaron Jul 28, 2021
5a89026
trying curly ones.
lizbaron Jul 28, 2021
42a068b
we have no idea what we're doing.
lizbaron Jul 28, 2021
1c4a974
commenting out stuff that definitely doesn't work.
lizbaron Jul 28, 2021
fb444d6
more variables
lizbaron Jul 28, 2021
8f95d83
objects
lizbaron Jul 28, 2021
0a51e18
more objects likely
lizbaron Jul 28, 2021
ceb3d43
making stuff fail
lizbaron Jul 28, 2021
7c64c93
convertToJson
lizbaron Jul 28, 2021
98727f9
we did a thing!
lizbaron Jul 28, 2021
6450ad3
for real.
lizbaron Jul 28, 2021
801f634
@" needs to be treated specially.
lizbaron Jul 29, 2021
b5fe530
single quotes?
lizbaron Jul 29, 2021
ed1a852
some people read errors... some don't
lizbaron Jul 29, 2021
019bf0b
no AsHashtable
lizbaron Jul 29, 2021
cef6324
testing json strings
lizbaron Jul 29, 2021
580f929
maybe fixed the json issue with regex
lizbaron Aug 3, 2021
9581578
yay for ascii art
lizbaron Aug 3, 2021
5c5af5b
regex were super helpful.
lizbaron Aug 3, 2021
be63fe4
test of matrix strategy from pipeline variable
lizbaron Aug 4, 2021
f3e7260
debugging
lizbaron Aug 4, 2021
ed3d770
compile or runtime?
lizbaron Aug 5, 2021
e240a6e
but parameters
lizbaron Aug 5, 2021
1491408
using arrays instead
lizbaron Aug 5, 2021
8ca4a69
different format for parameters
lizbaron Aug 5, 2021
694f39f
arrays are not strings
lizbaron Aug 5, 2021
426ff61
adding the mysterious jobs parameter
lizbaron Aug 5, 2021
e52585e
empty default array for jobs
lizbaron Aug 5, 2021
f4df623
remove type specification
lizbaron Aug 5, 2021
5754937
parameters default to string type when the type is not specified
lizbaron Aug 5, 2021
1af699d
Perhaps jobs should not be empty
lizbaron Aug 5, 2021
b65c5c7
not in quotes
lizbaron Aug 5, 2021
5b3bce1
debugging
lizbaron Aug 5, 2021
b86fe77
turns out we don't know what's going on
lizbaron Aug 5, 2021
28647ac
trying more stuff
lizbaron Aug 5, 2021
69a82b2
more objects
lizbaron Aug 5, 2021
ab05997
no jobs parameter
lizbaron Aug 5, 2021
c734e8b
trying sqlVersionEdition
lizbaron Aug 5, 2021
ac73417
use arrays in Main
lizbaron Aug 5, 2021
f51d36d
check if exists job has been deleted so too go the dependencies.
lizbaron Aug 5, 2021
5c3e0f3
no commas for dependsOn when depending on multiple
lizbaron Aug 5, 2021
e1a51b6
no more SQLSQL and prettified parameter objects
lizbaron Aug 5, 2021
b3b5fee
setting up pipeline variables
lizbaron Aug 7, 2021
ad3b306
fixing main build to dacpacs
lizbaron Aug 7, 2021
e09892d
debugging matrixed variables
lizbaron Aug 7, 2021
d7a57ec
trust but verify
lizbaron Aug 7, 2021
f886a5a
print out all the things
lizbaron Aug 7, 2021
1d27ebf
hopefully fix parallelism in stages, and actually publish output vari…
lizbaron Aug 7, 2021
79b21ae
temp pwd fix and use output vars in next step
lizbaron Aug 7, 2021
04ef827
json strings
lizbaron Aug 7, 2021
83cd3fa
n o s p a c e s
lizbaron Aug 7, 2021
5a4a166
Fix delete resources
lizbaron Aug 7, 2021
f518528
test saving and retrieving matrixed files
lizbaron Aug 7, 2021
995e77c
moving the code to where it is supposed to be
lizbaron Aug 7, 2021
87355c1
Value makes more sense here. ALso syntax.
lizbaron Aug 7, 2021
e14ed20
names are important for pipeline artifacts, you can't reuse them.
lizbaron Aug 7, 2021
9a91364
let's not download the whole project a bunch of times.
lizbaron Aug 7, 2021
d70cf78
more testing
lizbaron Aug 7, 2021
22a3657
#recurse
lizbaron Aug 7, 2021
d31bae7
dependencies aren't working for me.
lizbaron Aug 7, 2021
2df2a16
Fixing artifact directories and hopefully downloading the right dacpacs
lizbaron Aug 8, 2021
6b4aacf
names and dependencies are important
lizbaron Aug 8, 2021
eaa6011
TODO added to reduce chances of the delete vm job failing.
lizbaron Aug 8, 2021
d0fb5ea
quick refactor of resourcegroupname
lizbaron Aug 9, 2021
095dd8f
the paths are inconsistent, fixing.
lizbaron Aug 10, 2021
d67ee6e
debugging
lizbaron Aug 10, 2021
d068883
all the variables have to match...
lizbaron Aug 10, 2021
8264c63
putting dacpacs in the right directory
lizbaron Aug 10, 2021
eb1ec0f
fixing file paths
lizbaron Aug 10, 2021
8bb457b
replaced tSQLt dir reference with $(TSQLT_REPO_DIR) and checked out t…
lizbaron Aug 12, 2021
e9a3254
Fixing artifact repo directory
lizbaron Aug 12, 2021
e3445ec
debugging
lizbaron Aug 12, 2021
982944a
fixing more directories
lizbaron Aug 12, 2021
4a2c724
fix test artifact directories
lizbaron Aug 12, 2021
ecdd4a0
fixed ant parameters and added another directory variables.
lizbaron Aug 13, 2021
597a37f
Does order matter for ant and quotes?
lizbaron Aug 13, 2021
fce1f66
more quote experiments
lizbaron Aug 13, 2021
fa62440
rearranging more quotes and it is infuriating and why are we using an…
lizbaron Aug 13, 2021
46530f3
no more quotes!!
lizbaron Aug 14, 2021
459fc3a
begrudgingly restoring a single set of single quotes
lizbaron Aug 14, 2021
18a0ac9
single quotes decorating only the credentials
lizbaron Aug 14, 2021
d9b7195
you get quotes, and you get quotes, and you ....
lizbaron Aug 14, 2021
2771e74
but what about double-quotes?!?
lizbaron Aug 14, 2021
71aef79
all the double-quotes!
lizbaron Aug 14, 2021
17b9462
what about using dashes??
lizbaron Aug 14, 2021
5986993
single quote and double quotes
lizbaron Aug 14, 2021
27b11de
we could also try unit tests
lizbaron Aug 14, 2021
853d0ee
everything is mysterious
lizbaron Aug 14, 2021
3d44b87
more tests
lizbaron Aug 14, 2021
f7c0c97
magical incantation
lizbaron Aug 14, 2021
593313a
trying to make ant work
lizbaron Aug 15, 2021
61e6ec0
quotes are just a problem everywhere
lizbaron Aug 15, 2021
e11a8a7
trying a cmdline tasks and publishing test results in a separate task
lizbaron Aug 15, 2021
0e06d11
double quotes and ant are terrible
lizbaron Aug 15, 2021
314ea3f
names of tasks can't use "."
lizbaron Aug 15, 2021
8af7814
ant is terrible
lizbaron Aug 15, 2021
7a2fbd5
now nothing works
lizbaron Aug 15, 2021
89fe60b
more debugging
lizbaron Aug 15, 2021
2d076ec
Take 3: trying to run ant with a local build file in the command line…
lizbaron Sep 1, 2021
0fb50ee
trying this --> https://stackoverflow.com/questions/34388714/passing-…
lizbaron Sep 2, 2021
7f5b13d
If this works, we both need to sit and reflect on the error of our ways.
lizbaron Sep 2, 2021
e7127e0
but what is in TSQLT_VALIDATION_ARTIFACT_DIR?
lizbaron Sep 2, 2021
3f61dfc
Perhaps this is where our dacpacs should go?
lizbaron Sep 2, 2021
4fab016
Where are my files??
lizbaron Sep 2, 2021
b7bd8ce
Do the slashes really ahve to be consistent?
lizbaron Sep 2, 2021
f0825a5
backslashes
lizbaron Sep 2, 2021
6755942
fix recursive copy
lizbaron Sep 2, 2021
59edf6e
But where are all my files? Where have they gone?
lizbaron Sep 3, 2021
8eb2121
oops
lizbaron Sep 3, 2021
180b55b
Lessons were learned
lizbaron Sep 3, 2021
3c903cb
It's not clear that I needed that.
lizbaron Sep 3, 2021
99b7dde
Storing test artifacts in the artifact directory
lizbaron Sep 3, 2021
bea79eb
Turns out we need to use --all to recursively add the entire folder s…
lizbaron Sep 3, 2021
1c4d65a
but does the right directory exist?
lizbaron Sep 4, 2021
016a17a
Debugging and more carefully reading https://stackoverflow.com/questi…
lizbaron Sep 4, 2021
3f6bf37
git
lizbaron Sep 4, 2021
ae188fc
Oh, Copy-Item, will we ever get along?
lizbaron Sep 4, 2021
6cf126e
-Recurse, does it allow a new directory to be created? Let's just mak…
lizbaron Sep 4, 2021
7e2ebee
Fixing test file names
lizbaron Sep 4, 2021
24a075a
quotes. :(
lizbaron Sep 14, 2021
92e51a0
update defaults to production pipeline requirements
lizbaron Sep 14, 2021
ca8c2e4
Did the API change? We'll find out!
lizbaron Sep 14, 2021
d267d6a
quotes?
lizbaron Sep 14, 2021
1f74907
updated string to int
lizbaron Sep 14, 2021
13f9722
change template file path
mbt1 Sep 14, 2021
de73400
quotes?
lizbaron Sep 14, 2021
62c02b3
Merge branch 'tSQLtFacadeBuild' of https://github.com/tSQLt-org/tSQLt…
lizbaron Sep 14, 2021
1b8e26b
hard code things
lizbaron Sep 15, 2021
d0d3f78
vmImage upgrade and restoring quotes
lizbaron Sep 15, 2021
b50e51a
Let's try something completely different, like a bicep file.
lizbaron Sep 15, 2021
532b5a9
debugging statements
lizbaron Sep 15, 2021
4d68197
more debugging
lizbaron Sep 15, 2021
3afa0ad
more debugging
Sep 15, 2021
fbc77c7
let's try with az cli.
lizbaron Sep 16, 2021
1b4685c
switch to az cli task
lizbaron Sep 16, 2021
6e42fe9
merge AZ_NightlyCleanup.yml changes
Sep 16, 2021
265b646
Merge branch 'tSQLtFacadeBuild'
mbt1 Sep 16, 2021
d298408
Merge branch 'main' into tSQLtFacadeBuild
mbt1 Sep 16, 2021
f7761cd
Merge branch 'tSQLtFacadeBuild' into 20210916114600
mbt1 Sep 16, 2021
f2e94d1
Merge pull request #104 from tSQLt-org/20210916114600
mbt1 Sep 16, 2021
6e4d987
tried out the az cli and there is error handling that would need to b…
lizbaron Sep 17, 2021
5cdc22f
Merge branch 'tSQLtFacadeBuild' of https://github.com/tSQLt-org/tSQLt…
lizbaron Sep 17, 2021
caf2118
switch to az cli, figure out error handling next.
lizbaron Sep 18, 2021
e1ab187
quotes?
lizbaron Sep 18, 2021
84381b7
quotes still but more?
lizbaron Sep 18, 2021
184c260
get-history of commands so that we can better see what is failing
lizbaron Sep 18, 2021
f30f746
must print output to get the output
lizbaron Sep 18, 2021
906eb16
screams into the debugging and logging void
lizbaron Sep 18, 2021
66759aa
hard-code all the things
lizbaron Sep 18, 2021
1e20494
sqlcmd has disappeared and powershell won't delete resourcegroups
lizbaron Sep 18, 2021
542a371
There are (at least) two outstanding issues from this evening.
lizbaron Sep 18, 2021
9bc3475
using keyvault again
Sep 18, 2021
a15dd68
let's error-handle the last statement too
Sep 18, 2021
f1cdad7
let's find SQLCMD
Sep 18, 2021
adf2ba4
fix failing test for 2008R2
lizbaron Sep 18, 2021
63a0912
now n to windows-latest
Sep 18, 2021
d025850
find sqlpackage, too
Sep 19, 2021
a5588fa
in parallel
Sep 19, 2021
2beb357
creating tSQLt dacpacs, too
Sep 19, 2021
169af1d
package them, too
Sep 19, 2021
3526539
Upgrade Azure DevOps agent vmImage to windows-latest and changed the …
lizbaron Sep 19, 2021
f0257a2
this pipeline takes forever and we don't need to run it on every chec…
lizbaron Sep 19, 2021
ef4f609
in fact order does matter.
lizbaron Sep 19, 2021
1e9e3a0
quotes! jk.
lizbaron Sep 19, 2021
1d5a8e9
so much hard-coding.
lizbaron Sep 19, 2021
e7b317c
more hard-coding fixes and pulling all dacpacs from the DevOps artifact
lizbaron Sep 19, 2021
2ff1b7f
using more of a random password
lizbaron Sep 19, 2021
5f4c405
reordered entries in tSQLt.validatebuild.xml and allowed for deployme…
Sep 19, 2021
2dd6ce8
mostly fixed the build
Sep 20, 2021
c423654
mostly fixed the build
Sep 20, 2021
0dcd256
Merge branch 'tSQLtFacadeBuild' of github.com:tSQLt-org/tSQLt into tS…
Sep 20, 2021
233de01
This might work...
Sep 20, 2021
a276a64
rabbit holes...
Sep 20, 2021
e1b0e2c
.gitignore updated to exclude tSQLt dacpacs
Sep 20, 2021
d8d953a
tests are passing again
Sep 20, 2021
06a1461
this time really
Sep 21, 2021
6792d78
moved dacpac exclusion to subfolder
Sep 21, 2021
4e786d4
moved Get-SnipContent to a common function
Sep 21, 2021
1d0f23c
beautification ¯\_(ツ)_/¯
Sep 21, 2021
e99fb29
added missing files to artifact (Why is this needed?)
Sep 21, 2021
a36110f
missing logtable.name parameter
Sep 21, 2021
0b1d9e0
add files to intermediate artifacts and then use them there, too
Sep 21, 2021
6d8824d
quotes
Sep 21, 2021
a76748c
deja vu
Sep 21, 2021
66686c1
prepare the server before creating the log table
Sep 21, 2021
0d2f835
actually adding the missing files
Sep 21, 2021
24f44ce
Create build execution SQL logins
Sep 21, 2021
6b4c825
LogTable.name for AzureDevops, too
Sep 21, 2021
bd4d35c
.....
Sep 21, 2021
b24070c
antpath...
Sep 21, 2021
9fed6b5
TODO updated
Sep 21, 2021
812c393
changed Get-FriendlySQLServerVersion to not require a DB parameter
Sep 22, 2021
0acc737
now actually deploying the dacpac
Sep 22, 2021
751052c
DONE: <!-- TODO: failing tests should fail build -->
Sep 22, 2021
b25b101
new SPAWN image names
Sep 22, 2021
fc29f62
changed step order again
Sep 23, 2021
174931b
Fixing messy tests by making other messy tests, but more.
lizbaron Sep 23, 2021
b20b219
added test to enforce that every public run method calls the tSQLt.Ru…
Sep 23, 2021
7076f3a
trying different images for SPAWN
Sep 23, 2021
fd76122
fixing the connections issue
lizbaron Sep 24, 2021
196b4d0
Black magic --> tSQLt.Private_NullCellTable will contain a NULL row a…
lizbaron Sep 24, 2021
2bbcc4c
Ultimately we don't believe that truncate is a big enough problem to …
lizbaron Sep 25, 2021
fd43283
Update tSQLt.Private_Init to call the tSQLt.Private_NulLCellTable tri…
lizbaron Sep 25, 2021
59311aa
remove unique constraint when comparing dacpac installation to script…
lizbaron Sep 25, 2021
f832aa4
Split name and SpawnImage in the matrix setup.
lizbaron Sep 26, 2021
eec4aa4
you can't get there from here.
lizbaron Sep 26, 2021
4dd80c1
Re-enable testRunTitle for jUnit results
lizbaron Sep 26, 2021
464d0f8
Created release notes for this epic (way too large and took way too l…
lizbaron Sep 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
492 changes: 492 additions & 0 deletions .github/workflows/aks_build_and_test.yml

Large diffs are not rendered by default.

294 changes: 294 additions & 0 deletions .github/workflows/aks_build_container_images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
# This workflow creates the ACR images for the different supported SQL Server versions.

name: Build MSSQL Images

on:
# schedule:
# # * is a special character in YAML so you have to quote this string
# # Run every sunday at 6:20 AM
# - cron: '20 6 * * 0'
workflow_dispatch:
inputs:
projectName:
description: 'Project Name'
required: true
default: 'test_20210224'
machineName:
description: 'Machine Name, cannot be more than 15 characters long, be entirely numeric, or contain the following characters: ` ~ ! @ # $ % ^ & * ( ) = + _ [ ] { } \ | ; : . singlequote " , < > / ?.'
required: true
default: 'w2019c1'
msSqlVersions:
description: 'names of the k8s deployment files in JSON array format (e.g. ["windows-2008r2","windows-2012","windows-2014","windows-2016","windows-2017","windows-2019"])'
required: true
default: '["windows-2014","windows-2016","windows-2017","windows-2019"]'
debugVM:
description: 'set to "true" to retain the VM for debugging purposes'
required: false
default: 'false'


jobs:

# 💖 💖 💖 💖 💖 💖 💖 💖 💖 💖 💖 💖 💖 💖
create-vm:
name: Create The VM
runs-on: windows-latest
# if: ${{ false }}

env:
PROJECT_NAME: ${{ github.event.inputs.projectName }}
MACHINE_NAME: ${{ github.event.inputs.machineName }}
MS_SQL_VERSIONS: ${{ github.event.inputs.msSqlVersions }}
AZ_SERVICE_PRINCIPAL_CREDENTIALS: ${{ secrets[format('AZ_SP_CRED_{0}', github.event.inputs.projectName)] }}

steps:
- name: Checkout self
uses: actions/checkout@v2
with:
path: cicd

- name: create variables
id: create-vars
shell: pwsh
run: |
function Get-MD5HashOfString($string) {
$stringAsStream = [System.IO.MemoryStream]::new();
$writer = [System.IO.StreamWriter]::new($stringAsStream);
$writer.write($string);
$writer.Flush();
$stringAsStream.Position = 0;
$hashedString = (Get-FileHash -InputStream $stringAsStream).Hash;
return [String]$hashedString;
}

$projectNameHash = (Get-MD5HashOfString($env:PROJECT_NAME)).Substring(0,10);
$machineName = "$env:MACHINE_NAME";
$machineRgName = "rg_$machineName";
$azSecretsManagerName = "sm-" + $projectNameHash;
$containerRegistryURL = "crn" + $projectNameHash + ".azurecr.io";
$repoURL = "${{ github.SERVER_URL }}/${{ github.REPOSITORY }}.git";
$commitId = "${{ github.SHA }}" ;
$msSqlVersionForMatrix = '{"windows-version":'+$env:MS_SQL_VERSIONS+'}';


Write-Host "✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ";
Write-Host "";
Write-Host ("projectName value: {0}" -f $env:PROJECT_NAME);
Write-Host ("machineName value: {0}" -f $machineName);
Write-Host ("machineRgName value: {0}" -f $machineRgName);
Write-Host ("msSqlVersionForMatrix: {0}" -f "$msSqlVersionForMatrix");
Write-Host ("azSecretsManagerName: {0}" -f "$azSecretsManagerName");
Write-Host ("containerRegistryURL: {0}" -f "$containerRegistryURL");
Write-Host ("repoURL: {0}" -f "$repoURL");
Write-Host ("commitId: {0}" -f "$commitId");
Write-Host "";
Write-Host "✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ";

Write-Host ('::set-output name=azsecretsmanagername::'+$azSecretsManagerName);
Write-Host ('::set-output name=containerregistryurl::'+$containerRegistryURL);
Write-Host ('::set-output name=repoURL::'+$repoURL);
Write-Host ('::set-output name=machineName::'+$machineName);
Write-Host ('::set-output name=machineRgName::'+$machineRgName);
Write-Host ('::set-output name=commitId::'+$commitId);
Write-Host ("::set-output name=msSqlVersionForMatrix::{0}" -f "$msSqlVersionForMatrix");

- name: decode az sp cred
id: cred-decode
shell: pwsh
run: |
$decodedCreds = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String("${{ env.AZ_SERVICE_PRINCIPAL_CREDENTIALS}}"))
Write-Host ('::set-output name=az_sp_creds::'+$decodedCreds);

# documentation: https://github.com/azure/login#configure-azure-credentials
- name: login via az module
uses: azure/login@v1
with:
creds: ${{ steps.cred-decode.outputs.az_sp_creds }}
enable-AzPSSession: true

# documentation: https://github.com/Azure/get-keyvault-secrets
- name: get azure secrets
id: azure-secrets
uses: Azure/get-keyvault-secrets@v1.0
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true' # Note that this task can be replaced with a similar pattern as setting the namespace to the env variables (above), but is also not secure.
with:
keyvault: ${{ steps.create-vars.outputs.azsecretsmanagername }}
secrets: 'azResourceGroupName' # comma separated list of secret keys that need to be fetched from the Key Vault

- name: run azure powershell script
id: buildMachine-ps
uses: azure/powershell@v1
with:
azpsversion: 'latest'
errorActionPreference: 'continue'
inlineScript: |
$Parameters = @{
projectName = "$env:PROJECT_NAME";
azSecretsManagerName = "${{ steps.create-vars.outputs.azsecretsmanagername }}";
azResourceGroupName = "${{ steps.azure-secrets.outputs.azResourceGroupName }}";
machineRgName = "${{ steps.create-vars.outputs.machineRgName }}";
repoURL = "${{ steps.create-vars.outputs.repoURL }}";
commitId = "${{ steps.create-vars.outputs.commitId }}";
machineName = "${{ steps.create-vars.outputs.machineName }}";
debugOn = $true;
};
./cicd/envSetup/createContainerBuildMachine.ps1 @Parameters;

outputs:
mssqlversion: ${{ steps.create-vars.outputs.msSqlVersionForMatrix }}
containerregistryurl: ${{ steps.create-vars.outputs.containerregistryurl }}
azsecretsmanagername: ${{ steps.create-vars.outputs.azSecretsManagerName }}
machinergname: ${{ steps.create-vars.outputs.machineRgName }}
machinename: ${{ steps.create-vars.outputs.machineName }}

# 💖 💖 💖 💖 💖 💖 💖 💖 💖 💖 💖 💖 💖 💖
create-images:
name: create and publish the ACR images
needs: create-vm

runs-on: windows-latest

env:
AZ_CONTAINER_REGISTRY_URL: ${{ needs.create-vm.outputs.containerregistryurl }}
AZ_SECRETS_MANAGER_NAME: ${{ needs.create-vm.outputs.azsecretsmanagername }}
MACHINE_NAME: ${{ needs.create-vm.outputs.machinename }}
MACHINE_RG_NAME: ${{ needs.create-vm.outputs.machinergname }}
AZ_SERVICE_PRINCIPAL_CREDENTIALS: ${{ secrets[format('AZ_SP_CRED_{0}', github.event.inputs.projectName)] }}

strategy:
matrix: ${{fromJson(needs.create-vm.outputs.mssqlversion)}}
max-parallel: 1

steps:

- name: Checkout self
uses: actions/checkout@v2
with:
path: cicd

- name: build and push docker image
shell: pwsh
run: |
$mssqlversion = '${{ matrix.mssqlversion }}';

Write-Host "✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ";
Write-Host "";
Write-Host ("mssqlversion: {0}" -f "$mssqlversion");
Write-Host ("azContainerRegistryURL: {0}" -f "$env:AZ_CONTAINER_REGISTRY_URL");
Write-Host ("azSecretsManagerName: {0}" -f "$env:AZ_SECRETS_MANAGER_NAME");
Write-Host ("machineName: {0}" -f "$env:MACHINE_NAME");
Write-Host ("machineRGName: {0}" -f "$env:MACHINE_RG_NAME");
Write-Host "";
Write-Host "✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ";

- name: decode az sp cred
id: cred-decode
shell: pwsh
run: |
$decodedCreds = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String("${{ env.AZ_SERVICE_PRINCIPAL_CREDENTIALS}}"));
Write-Host ('::set-output name=az_sp_creds::'+$decodedCreds);

# documentation: https://github.com/azure/login#configure-azure-credentials
- name: login via az module
uses: azure/login@v1
with:
creds: ${{ steps.cred-decode.outputs.az_sp_creds }}
enable-AzPSSession: true

- name: build and push image script
id: build-and-push-image
uses: azure/powershell@v1
with:
azpsversion: 'latest'
errorActionPreference: 'continue'
inlineScript: |
$builImageScriptPath = 'cicd\envSetup\buildAndPushImage.ps1';
Invoke-AzVMRunCommand -ResourceGroupName $env:MACHINE_RG_NAME -VMName $env:MACHINE_NAME -CommandId 'RunPowerShellScript' -ScriptPath $builImageScriptPath -Parameter @{mssqlVersion = "${{ matrix.mssqlversion }}"; acrURL = "$env:AZ_CONTAINER_REGISTRY_URL"; azSpCrBase64 = "${{ env.AZ_SERVICE_PRINCIPAL_CREDENTIALS}}"; debugOnString = "$debugOn"}

# 💖 💖 💖 💖 💖 💖 💖 💖 💖 💖 💖 💖 💖 💖
prune-untagged-images:
name: prune images
needs: [create-vm, create-images]
if: ${{ always() }}

runs-on: windows-latest

env:
AZ_CONTAINER_REGISTRY_URL: ${{ needs.create-vm.outputs.containerregistryurl }}
AZ_SERVICE_PRINCIPAL_CREDENTIALS: ${{ secrets[format('AZ_SP_CRED_{0}', github.event.inputs.projectName)] }}

steps:
- name: decode az sp cred
id: cred-decode
shell: pwsh
run: |
$decodedCreds = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String("${{ env.AZ_SERVICE_PRINCIPAL_CREDENTIALS}}"))
Write-Host ('::set-output name=az_sp_creds::'+$decodedCreds);

# documentation: https://github.com/azure/login#configure-azure-credentials
- name: login via az module
uses: azure/login@v1
with:
creds: ${{ steps.cred-decode.outputs.az_sp_creds }}
enable-AzPSSession: true

- name: drop image script
id: dropBuildMachine-ps
uses: azure/powershell@v1
with:
azpsversion: 'latest'
errorActionPreference: 'continue'
inlineScript: |
# Documented here: https://docs.microsoft.com/en-us/azure/container-registry/container-registry-delete#delete-all-untagged-images

$registry = "$env:AZ_CONTAINER_REGISTRY_URL";
$repository = "windows-mssql"; # https://github.com/distribution/distribution/blob/main/docs/spec/api.md#overview, must adhere to: [a-z0-9]+(?:[._-][a-z0-9]+)*

az acr repository show-manifests --name $registry --repository $repository --query "[?tags[0]==null].digest" -o tsv | %{ az acr repository delete --name $registry --image $repository@$_ --yes }


# 💖 💖 💖 💖 💖 💖 💖 💖 💖 💖 💖 💖 💖 💖
drop-vm:
name: drop the VM
needs: [create-vm, create-images]
if: ${{ always() }}

runs-on: windows-latest

env:
AZ_SERVICE_PRINCIPAL_CREDENTIALS: ${{ secrets[format('AZ_SP_CRED_{0}', github.event.inputs.projectName)] }}
MACHINE_RG_NAME: ${{ needs.create-vm.outputs.machinergname }}

steps:
- name: check debug VM
shell: pwsh
if: ${{ github.event.inputs.debugVM == 'true' }}
run: |
Write-Host ("::error::✨ ✨ ✨TURN OFF THE VM WHEN YOU ARE DONE!✨ ✨ ✨");
exit 1;

- name: decode az sp cred
id: cred-decode
shell: pwsh
run: |
$decodedCreds = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String("${{ env.AZ_SERVICE_PRINCIPAL_CREDENTIALS}}"))
Write-Host ('::set-output name=az_sp_creds::'+$decodedCreds);

# documentation: https://github.com/azure/login#configure-azure-credentials
- name: login via az module
uses: azure/login@v1
with:
creds: ${{ steps.cred-decode.outputs.az_sp_creds }}
enable-AzPSSession: true

- name: drop image build machine resource group script
id: dropBuildMachine-ps
uses: azure/powershell@v1
with:
azpsversion: 'latest'
errorActionPreference: 'continue'
inlineScript: |
Remove-AzResourceGroup -Name "$env:MACHINE_RG_NAME" -Force ;


78 changes: 78 additions & 0 deletions .github/workflows/aks_cicd_environment_setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# This is the workflow to setup the environment for Data Platform CI/CD pipelines
#
# AZURE: Before this workflow will run successfully you must do the following
# 1. Run manualPrep.ps1 in the Azure Portal and follow the instructions to set up the AZ_SP_CRED_<projectName> secret in GitHub (Settings > Secrets > "New repository secret").
# 2. Set up the SSH_PASSPHRASE secret in Settings > Secrets > "New repository secret"

name: Set Up CI/CD Environment

on:
workflow_dispatch:
inputs:
projectName:
description: 'Project Name'
required: true
default: 'db_cicd_project'
linuxNodePoolDefaultVMSize:
description: 'Linux Node Pool Default VM Size'
required: true
default: 'Standard_D2_v2'
windowsNodePoolDefaultVMSize:
description: 'Windows Node Pool Default VM Size'
required: true
default: 'Standard_D3_v2'
kubernetesVersion:
description: 'Kubernetes Version'
required: true
default: '1.19.6'

jobs:
build:
name: Setup Azure Environment
runs-on: ubuntu-latest

env:
PROJECT_NAME: ${{ github.event.inputs.projectName }}
LINUX_NODEPOOL_DEFAULT_VM_SIZE: ${{ github.event.inputs.linuxNodePoolDefaultVMSize }}
WINDOWS_NODEPOOL_DEFAULT_VM_SIZE: ${{ github.event.inputs.windowsNodePoolDefaultVMSize }}
KUBERNETES_VERSION: ${{ github.event.inputs.kubernetesVersion }}
AZ_SERVICE_PRINCIPAL_CREDENTIALS: ${{ secrets[format('AZ_SP_CRED_{0}', github.event.inputs.projectName)] }}
SSH_PASSPHRASE: ${{ secrets.SSH_PASSPHRASE }}

steps:
- uses: actions/checkout@v2

- name: decode az sp cred
id: cred-decode
shell: pwsh
run: |
$decodedCreds = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String("${{ env.AZ_SERVICE_PRINCIPAL_CREDENTIALS}}"))
Write-Host ('::set-output name=az_sp_creds::'+$decodedCreds);

# documentation: https://github.com/azure/login#configure-azure-credentials
# TODO: set up a service principal which has permission only on the resource group and associated resources it creates
# MDP: This task can be replaced with Connect-AzAccount via service principal (https://docs.microsoft.com/en-us/powershell/azure/authenticate-azureps?view=azps-5.3.0). However for most pipelines, which would use azure powershell more than once, this is an anti-pattern.
# TODO: measure difference in performance between using this task and Connect-AzAccount in the next task
- name: login via az module
uses: azure/login@v1
with:
creds: ${{ steps.cred-decode.outputs.az_sp_creds }}
enable-azpssession: true

# documentation: https://github.com/marketplace/actions/azure-powershell-action
- name: run azure powershell script
uses: azure/powershell@v1
with:
azpsversion: 'latest'
errorActionPreference: 'continue'
inlineScript: |
$Parameters = @{
projectName = "$env:PROJECT_NAME";
azServicePrincipalCredentials = '${{ steps.cred-decode.outputs.az_sp_creds }}';
sshPassphrase = "$env:SSH_PASSPHRASE";
linuxNodePoolDefaultVMSize = "$env:LINUX_NODEPOOL_DEFAULT_VM_SIZE"
windowsNodePoolDefaultVMSize = "$env:WINDOWS_NODEPOOL_DEFAULT_VM_SIZE"
kubernetesVersion = "$env:KUBERNETES_VERSION"
debugOn = $false;
};
./envSetup/setup.ps1 @Parameters;
Loading