Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding PowerShell Deployment Option to the Helper #528

Merged
merged 12 commits into from
Jun 29, 2023
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ jobs:
matrix:
files:
- 'postdeploy/scripts/postdeploy.sh'
- 'postdeploy/scripts/postdeploy.ps1'
- 'postdeploy/k8smanifests/networkpolicy-deny-all.yml'
- 'postdeploy/helm/Az-CertManagerIssuer-0.3.0.tgz'
- 'helper/src/dependencies.json'
Expand Down
102 changes: 90 additions & 12 deletions helper/src/components/deployTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,32 +240,33 @@ export default function DeployTab({ defaults, updateFn, tabValues, invalidArray,

const deployRelease = deploy.templateVersions.find(t => t.key === deploy.selectedTemplate) || {}

const preview_post_deploycmd = Object.keys(preview_post_params).map(k => {

//Bash (Remember to align any changes with Powershell)
const preview_post_deployBASHcmd = Object.keys(preview_post_params).map(k => {
const val = preview_post_params[k]
const targetVal = Array.isArray(val) ? JSON.stringify(JSON.stringify(val)) : val
return ` \\\n\t-p ${k}=${targetVal}`
}).join('')

const post_deploycmd = `\n\n# Deploy charts into cluster\n` +
(deploy.selectedTemplate === "local" ? `bash .${ cluster.apisecurity === "private" ? '' : '/postdeploy/scripts'}/postdeploy.sh ` : `curl -sL ${deployRelease.post_url} | bash -s -- `) +
const post_deployBASHcmd = `\n\n# Deploy charts into cluster\n` +
(deploy.selectedTemplate === "local" ? `bash .${ cluster.apisecurity === "private" ? '' : '/postdeploy/scripts'}/postdeploy.sh ` : `curl -sL ${deployRelease.postBASH_url} | bash -s -- `) +
(deploy.selectedTemplate === 'local' ? (cluster.apisecurity === "private" ? '-r .' : '') : `-r ${deployRelease.base_download_url}`) +
Object.keys(post_params).map(k => {
const val = post_params[k]
const targetVal = Array.isArray(val) ? JSON.stringify(JSON.stringify(val)) : val
return ` \\\n\t-p ${k}=${targetVal}`
}).join('')+
(!deploy.disablePreviews ? preview_post_deploycmd : '')

(!deploy.disablePreviews ? preview_post_deployBASHcmd : '')

const post_deploystr = cluster.apisecurity !== "private" ?
const post_deployBASHstr = cluster.apisecurity !== "private" ?
'# Get credentials for your new AKS cluster & login (interactive)\n' +
`az aks get-credentials -g ${deploy.rg} -n ${aks}\n` +
'kubectl get nodes' +
post_deploycmd
post_deployBASHcmd
:
'# Private cluster, so use command invoke\n' +
`az aks command invoke -g ${deploy.rg} -n ${aks} --command "` +
post_deploycmd.replaceAll('"', '\\"') +
post_deployBASHcmd.replaceAll('"', '\\"') +
`\n"${deploy.selectedTemplate === "local" ? ' --file ./postdeploy/scripts/postdeploy.sh --file ./postdeploy/helm/Az-CertManagerIssuer-0.3.0.tgz --file ./postdeploy/k8smanifests/networkpolicy-deny-all.yml --file ./helper/src/dependencies.json' : ''}`

const networkWatcher = net.nsg && net.nsgFlowLogs !== defaults.net.nsgFlowLogs ?
Expand All @@ -274,7 +275,7 @@ export default function DeployTab({ defaults, updateFn, tabValues, invalidArray,

const cardSpecificWorkloadDeployCmd = deploy.workloadDeployCommands && deploy.workloadDeployCommands.length>0 ? deploy.workloadDeployCommands.map(w => w).join('\n').replace(/\$RESOURCEGROUP/g,deploy.rg).replace(/\$AKSNAME/g, aks) : ''

const deploycmd =
const deployBASHcmd =
`# Create Resource Group\n` +
`az group create -l ${deploy.location} -n ${deploy.rg}\n\n` + networkWatcher +
`# Deploy template with in-line parameters\n` +
Expand All @@ -283,9 +284,46 @@ export default function DeployTab({ defaults, updateFn, tabValues, invalidArray,
const val = finalParams[k]
const targetVal = Array.isArray(val) ? JSON.stringify(JSON.stringify(val)) : val
return ` \\\n\t${k}=${targetVal}`
}).join('') + '\n\n' + (Object.keys(post_params).length >0 || (!deploy.disablePreviews && Object.keys(preview_post_params).length >0) ? post_deploystr : '')
}).join('') + '\n\n' + (Object.keys(post_params).length >0 || (!deploy.disablePreviews && Object.keys(preview_post_params).length >0) ? post_deployBASHstr : '')

//Powershell (Remember to align any changes with Bash)
const preview_post_deployPScmd = Object.keys(preview_post_params).map(k => {
const val = preview_post_params[k]
const targetVal = Array.isArray(val) ? JSON.stringify(JSON.stringify(val)) : val
return ` \`\n\t-${k} ${targetVal}`
}).join('')

const post_deployPScmd = `\n\n# Deploy charts into cluster\n` +
(deploy.selectedTemplate === "local" ? ` .${ cluster.apisecurity === "private" ? '' : '/postdeploy/scripts'}/postdeploy.ps1 ` : `& $([scriptblock]::Create((New-Object Net.WebClient).DownloadString("${deployRelease.postPS_url}")))`) +
(deploy.selectedTemplate === 'local' ? (cluster.apisecurity === "private" ? '-r .' : '') : ` -releace_version="${deployRelease.base_download_url}"`) +
Object.keys(post_params).map(k => {
const val = post_params[k]
const targetVal = Array.isArray(val) ? JSON.stringify(JSON.stringify(val)) : val
return ` \`\n\t-${k} ${targetVal}`
}).join('')+
(!deploy.disablePreviews ? preview_post_deployPScmd : '')


//Below used when not a private cluster (used further below the BASH postdeploy script if a private cluster)
const post_deployPSstr =
'# Get credentials for your new AKS cluster & login (interactive)\n' +
`az aks get-credentials -g ${deploy.rg} -n ${aks}\n` +
'kubectl get nodes' +
post_deployPScmd

const deployPScmd =
`# Create Resource Group\n` +
`az group create -l ${deploy.location} -n ${deploy.rg}\n\n` + networkWatcher +
`# Deploy template with in-line parameters\n` +
`az deployment group create -g ${deploy.rg} ${deploy.selectedTemplate === "local" ? '--template-file ./bicep/main.bicep' : `--template-uri ${deployRelease.main_url}` } --parameters` +
Object.keys(finalParams).map(k => {
const val = finalParams[k]
const targetVal = Array.isArray(val) ? JSON.stringify(JSON.stringify(val)).replaceAll('"[\\', '\'[').replaceAll('\\"]"', '"]\'').replaceAll('\\",\\"','","') : val
return ` \`\n\t${k}=${targetVal}`
}).join('') + '\n\n' + (Object.keys(post_params).length >0 || (!deploy.disablePreviews && Object.keys(preview_post_params).length >0) ? cluster.apisecurity !== "private" ? post_deployPSstr: post_deployBASHstr : '')


//Terraform
const deployTfcmd = `#download the *.tf files and run these commands to deploy using terraform\n#for more AKS Construction samples of deploying with terraform, see https://aka.ms/aksc/terraform\n\nterraform fmt\nterraform init\nterraform validate\nterraform plan -out main.tfplan\nterraform apply main.tfplan\nterraform output`

const deployTfProviders =
Expand Down Expand Up @@ -355,6 +393,13 @@ az role assignment create --role "Managed Identity Operator" --assignee-principa

const ghOrg = deploy.githubrepo.replace(/.*com\//, "").replace(/\/.*/, '')
const ghRepo = deploy.githubrepo.replace(/.*\//, '')

//PowerShell is disabled generally due to a missing postdeploy.ps1 script missing in the release
if (deployRelease.postPS_url === undefined && deploy.selectedTemplate !== "local" && deploy.deployItemKey === "deployPSArmCli")
{
deploy.deployItemKey = "deployArmCli"
}

console.log (`deploy.deployItemKey=${deploy.deployItemKey}`)
return (

Expand Down Expand Up @@ -430,7 +475,7 @@ az role assignment create --role "Managed Identity Operator" --assignee-principa

<Pivot selectedKey={deploy.deployItemKey} onLinkClick={({props}) => updateFn('deployItemKey', props.itemKey)}>

<PivotItem headerText="Command Line" itemKey="deployArmCli" itemIcon="PasteAsCode" >
<PivotItem headerText="Bash" itemKey="deployArmCli" itemIcon="PasteAsCode" >

<Stack horizontal horizontalAlign="space-between" styles={{root: { width: '100%', marginTop: '10px'}}}>
<Stack.Item>
Expand All @@ -455,7 +500,7 @@ az role assignment create --role "Managed Identity Operator" --assignee-principa
</Stack.Item>
</Stack>

<CodeBlock hideSave={true} lang="shell script" error={allok ? false : 'Configuration not complete, please correct the tabs with the warning symbol before running'} deploycmd={deploycmd} testId={'deploy-deploycmd'}/>
<CodeBlock hideSave={true} lang="shell script" error={allok ? false : 'Configuration not complete, please correct the tabs with the warning symbol before running'} deploycmd={deployBASHcmd} testId={'deploy-deploycmd'}/>

{ cardSpecificWorkloadDeployCmd.length > 0 &&
<CodeBlock hideSave={true} lang="Workload Deployment shell script" error={allok ? false : 'Configuration not complete, please correct the tabs with the warning symbol before running'} deploycmd={cardSpecificWorkloadDeployCmd} testId={'deploy-deploycmd'}/>
Expand All @@ -465,6 +510,39 @@ az role assignment create --role "Managed Identity Operator" --assignee-principa
}
</PivotItem>

<PivotItem headerText="PowerShell" itemKey="deployPSArmCli" itemIcon="PasteAsCode" headerButtonProps={{disabled: deployRelease.postPS_url === undefined && deploy.selectedTemplate !== "local" ? true : false , 'style': {color: deployRelease.postPS_url === undefined && deploy.selectedTemplate !== "local" ? "grey" : "white"}}} >

<Stack horizontal horizontalAlign="space-between" styles={{root: { width: '100%', marginTop: '10px'}}}>
<Stack.Item>
<Label >PowerShell and Azure CLI commands to deploy your fully operational environment<br></br> PowerShell disabled is <i>postdeploy.ps1</i> not in selected Template Version</Label>
<Text>
Requires <Link target="_bl" href="https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.3">PowerShell (7 or greater) </Link>, <Link target="_bl" href="https://docs.microsoft.com/cli/azure/install-azure-cli">AZ CLI (2.37.0 or greater)</Link>, or execute in the <Link target="_cs" href="http://shell.azure.com/">Azure Cloud Shell</Link>.
</Text>
</Stack.Item>

<Stack.Item align="end">
<Stack horizontal tokens={{childrenGap: 5}}>
<Dropdown
errorMessage={getError(invalidArray, 'selectedTemplate')}
label='Template Version'
disabled={process.env.REACT_APP_TEMPLATERELEASE !== undefined}
selectedKey={deploy.selectedTemplate}
onChange={(ev, { key }) => updateFn('selectedTemplate', key)}
options={deploy.templateVersions}
styles={{ dropdown: { width: 200 } }}
/>
</Stack>
</Stack.Item>
</Stack>

<CodeBlock hideSave={true} lang="PowerShell script" error={allok ? false : 'Configuration not complete, please correct the tabs with the warning symbol before running'} deploycmd={deployPScmd} testId={'deploy-deploycmd'}/>

{ urlParams.toString() !== "" &&
<Text variant="medium">Not ready to deploy? Bookmark your configuration : <a href={"?" + urlParams.toString()}>here</a></Text>
}
</PivotItem>


<PivotItem headerText="Github Actions" itemKey="github" itemIcon="GitGraph">
<Stack horizontal tokens={{childrenGap: 30}}>
<Stack.Item styles={{root: {width: "60%"}}}>
Expand Down
3 changes: 2 additions & 1 deletion helper/src/components/portalnav.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ export default function PortalNav({ config }) {
key: rel.tag_name,
text: `${rel.tag_name}${i === 0 ? ' (latest)' : ''}`,
main_url: rel.assets.find(a => a.name === 'main.json').browser_download_url,
post_url: rel.assets.find(a => a.name === 'postdeploy.sh').browser_download_url,
postBASH_url: rel.assets.find(a => a.name === 'postdeploy.sh').browser_download_url,
postPS_url: rel.assets.find(a => a.name === 'postdeploy.ps1') ? rel.assets.find(a => a.name === 'postdeploy.ps1').browser_download_url : undefined, //Needs to be in the release to work.
base_download_url: rel.assets.find(a => a.name === 'main.json').browser_download_url.replace('/main.json', '')
}
}).concat(defaults.deploy.templateVersions)
Expand Down
Loading