Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-kastil committed Sep 6, 2024
1 parent e2fa883 commit f32e8b1
Show file tree
Hide file tree
Showing 9 changed files with 273 additions and 155 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# plugin for Dotnet and/or NuGet to ~/.nuget/plugins directory
# To install netcore, run installcredprovider.ps1
# To install netcore and netfx, run installcredprovider.ps1 -AddNetfx
# To overwrite existing plugin with the latest version, run installcredprovider.ps1 -Force
# To use a specific version of a credential provider, run installcredprovider.ps1 -Version "1.0.1" or installcredprovider.ps1 -Version "1.0.1" -Force

param(
# whether or not to install netfx folder for nuget
[switch]$AddNetfx,
# override existing cred provider with the latest version
[switch]$Force,
# install the version specified
[string]$Version,
# install Net6 version of the netcore cred provider instead of NetCore3.1
[switch]$InstallNet6 = $true
)

$script:ErrorActionPreference='Stop'

# Without this, System.Net.WebClient.DownloadFile will fail on a client with TLS 1.0/1.1 disabled
if ([Net.ServicePointManager]::SecurityProtocol.ToString().Split(',').Trim() -notcontains 'Tls12') {
[Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12
}

if ($Version.StartsWith("0.") -and $InstallNet6 -eq $True) {
Write-Error "You cannot install the .Net 6 version with versions lower than 1.0.0"
return
}

$userProfilePath = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::UserProfile);
if ($userProfilePath -ne '') {
$profilePath = $userProfilePath
} else {
$profilePath = $env:UserProfile
}

$tempPath = [System.IO.Path]::GetTempPath()

$pluginLocation = [System.IO.Path]::Combine($profilePath, ".nuget", "plugins");
$tempZipLocation = [System.IO.Path]::Combine($tempPath, "CredProviderZip");

$localNetcoreCredProviderPath = [System.IO.Path]::Combine("netcore", "CredentialProvider.Microsoft");
$localNetfxCredProviderPath = [System.IO.Path]::Combine("netfx", "CredentialProvider.Microsoft");

$fullNetfxCredProviderPath = [System.IO.Path]::Combine($pluginLocation, $localNetfxCredProviderPath)
$fullNetcoreCredProviderPath = [System.IO.Path]::Combine($pluginLocation, $localNetcoreCredProviderPath)

$netfxExists = Test-Path -Path ($fullNetfxCredProviderPath)
$netcoreExists = Test-Path -Path ($fullNetcoreCredProviderPath)

# Check if plugin already exists if -Force swich is not set
if (!$Force) {
if ($AddNetfx -eq $True -and $netfxExists -eq $True -and $netcoreExists -eq $True) {
Write-Host "The netcore and netfx Credential Providers are already in $pluginLocation"
return
}

if ($AddNetfx -eq $False -and $netcoreExists -eq $True) {
Write-Host "The netcore Credential Provider is already in $pluginLocation"
return
}
}

# Get the zip file from the GitHub release
$releaseUrlBase = "https://api.github.com/repos/Microsoft/artifacts-credprovider/releases"
$versionError = "Unable to find the release version $Version from $releaseUrlBase"
$releaseId = "latest"
if (![string]::IsNullOrEmpty($Version)) {
try {
$releases = Invoke-WebRequest -UseBasicParsing $releaseUrlBase
$releaseJson = $releases | ConvertFrom-Json
$correctReleaseVersion = $releaseJson | ? { $_.name -eq $Version }
$releaseId = $correctReleaseVersion.id
} catch {
Write-Error $versionError
return
}
}

if (!$releaseId) {
Write-Error $versionError
return
}

$releaseUrl = [System.IO.Path]::Combine($releaseUrlBase, $releaseId)
$releaseUrl = $releaseUrl.Replace("\","/")

$zipFile = "Microsoft.NetCore3.NuGet.CredentialProvider.zip"
if ($Version.StartsWith("0.")) {
# versions lower than 1.0.0 installed NetCore2 zip
$zipFile = "Microsoft.NetCore2.NuGet.CredentialProvider.zip"
}
if ($InstallNet6 -eq $True) {
$zipFile = "Microsoft.Net6.NuGet.CredentialProvider.zip"
}
if ($AddNetfx -eq $True) {
$zipFile = "Microsoft.NuGet.CredentialProvider.zip"
}

function InstallZip {
Write-Verbose "Using $zipFile"

try {
Write-Host "Fetching release $releaseUrl"
$release = Invoke-WebRequest -UseBasicParsing $releaseUrl
if (!$release) {
throw ("Unable to make Web Request to $releaseUrl")
}
$releaseJson = $release.Content | ConvertFrom-Json
if (!$releaseJson) {
throw ("Unable to get content from JSON")
}
$zipAsset = $releaseJson.assets | ? { $_.name -eq $zipFile }
if (!$zipAsset) {
throw ("Unable to find asset $zipFile from release json object")
}
$packageSourceUrl = $zipAsset.browser_download_url
if (!$packageSourceUrl) {
throw ("Unable to find download url from asset $zipAsset")
}
}
catch {
Write-Error ("Unable to resolve the browser download url from $releaseUrl `nError: " + $_.Exception.Message)
return
}

# Create temporary location for the zip file handling
Write-Verbose "Creating temp directory for the Credential Provider zip: $tempZipLocation"
if (Test-Path -Path $tempZipLocation) {
Remove-Item $tempZipLocation -Force -Recurse
}
New-Item -ItemType Directory -Force -Path $tempZipLocation

# Download credential provider zip to the temp location
$pluginZip = ([System.IO.Path]::Combine($tempZipLocation, $zipFile))
Write-Host "Downloading $packageSourceUrl to $pluginZip"
try {
$client = New-Object System.Net.WebClient
$client.DownloadFile($packageSourceUrl, $pluginZip)
} catch {
Write-Error "Unable to download $packageSourceUrl to the location $pluginZip"
}

# Extract zip to temp directory
Write-Host "Extracting zip to the Credential Provider temp directory $tempZipLocation"
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($pluginZip, $tempZipLocation)
}

# Call InstallZip function
InstallZip

# Remove existing content and copy netfx directories to plugins directory
if ($AddNetfx -eq $True) {
if ($netfxExists) {
Write-Verbose "Removing existing content from $fullNetfxCredProviderPath"
Remove-Item $fullNetfxCredProviderPath -Force -Recurse
}
$tempNetfxPath = [System.IO.Path]::Combine($tempZipLocation, "plugins", $localNetfxCredProviderPath)
Write-Verbose "Copying Credential Provider from $tempNetfxPath to $fullNetfxCredProviderPath"
Copy-Item $tempNetfxPath -Destination $fullNetfxCredProviderPath -Force -Recurse
}

# Microsoft.NuGet.CredentialProvider.zip that installs netfx provider installs .netcore3.1 version
# If InstallNet6 is also true we need to replace netcore cred provider with net6
if ($AddNetfx -eq $True -and $InstallNet6 -eq $True) {
$zipFile = "Microsoft.Net6.NuGet.CredentialProvider.zip"
Write-Verbose "Installing Net6"
InstallZip
}
# Remove existing content and copy netcore directories to plugins directory
if ($netcoreExists) {
Write-Verbose "Removing existing content from $fullNetcoreCredProviderPath"
Remove-Item $fullNetcoreCredProviderPath -Force -Recurse
}
$tempNetcorePath = [System.IO.Path]::Combine($tempZipLocation, "plugins", $localNetcoreCredProviderPath)
Write-Verbose "Copying Credential Provider from $tempNetcorePath to $fullNetcoreCredProviderPath"
Copy-Item $tempNetcorePath -Destination $fullNetcoreCredProviderPath -Force -Recurse

# Remove $tempZipLocation directory
Write-Verbose "Removing the Credential Provider temp directory $tempZipLocation"
Remove-Item $tempZipLocation -Force -Recurse

Write-Host "Credential Provider installed successfully"
58 changes: 34 additions & 24 deletions demos/07-dependency-mgmt/02-azure-aritfacts/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,53 @@

[Azure Artifacts Upstream Sources](https://docs.microsoft.com/en-us/azure/devops/artifacts/concepts/upstream-sources?view=azure-devops)

## Demos
## Demo

- This demo uses [order-service](/src/services/order-service/) which references [food-app-common](/src/services/food-app-common/).

- Explain Azure Artifacts

- Create a Feed `food-packages` in Azure Artifacts and assign permissions to the [PROJECT]\Build Service ([PROJECT] is the name of your Azure DevOps project)
- Explain and run `food-app-common-ci-cd-artifacts.yml` and mention GitVersion settings

![feed-permissions](_images/feed-permissions.png)
- Run `food-app-common-ci-cd-artifacts.yml` to produce the common package

- Explain [Azure Artifacts Credential Provider](https://github.com/microsoft/artifacts-credprovider) and [Device Auth Flow](https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-device-code). The installation script can be downloaded [here](https://github.com/microsoft/artifacts-credprovider/blob/master/helpers/installcredprovider.ps1).
- Checkout commit with tag `project-using-feed` and explain nuget.config and updated package ref

`*.csproj:`
- The original `food-app-common` package was referenced in `order-service.csproj` using the following reference:

```xml
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
...
<PackageReference Include="FoodCalculations" Version="0.1.0" />
</ItemGroup>
</Project>
<ItemGroup>
<ProjectReference Include="..\food-app-common\food-app-common.csproj" />
</ItemGroup>
```

`dotnet restore --interactive`
- Replace it by using the package reference and remove the relative path reference:

![restore-interactive](_images/restore-interactive.jpg)
```xml
<ItemGroup>
...
<PackageReference Include="food-app-common" Version="1.0.0" />
</ItemGroup>

- Explain and run `consume-foodcalc.yaml`
- Show Feed and upstream sources
- Add a `nuget.config:`

```xml
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="food-packages" value="https://pkgs.dev.azure.com/integrations-development/az-400/_packaging/food-packages/nuget/v3/index.json" />
</packageSources>
</configuration>
```

![upstream](_images/upstream.png)
- Run `dotnet restore --interactive`

## Extensions & Tools
![restore-interactive](_images/restore-interactive.jpg)

Install GitVersion on Windows PC:
- Run `orders-ci.yml` to build the `order-service`

```
choco install gitversion.portable
```
- Show Feed and upstream sources

[GitTools - containing GitVersion for Azure DevOps](https://marketplace.visualstudio.com/items?itemName=gittools.gittools)
![upstream](_images/upstream.png)
4 changes: 2 additions & 2 deletions demos/08-feedback/01-insights/create-insights-app.azcli
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
env=monitoring
grp=az400-m09-$env
env=dev
grp=az400-$env
loc=westeurope
ai=foodapp$env
api=arambazamba/food-catalog-api:1.1.0
Expand Down
7 changes: 7 additions & 0 deletions src/services/order-service/nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="food-packages" value="https://pkgs.dev.azure.com/integrations-development/az-400/_packaging/food-packages/nuget/v3/index.json" />
</packageSources>
</configuration>
Loading

0 comments on commit f32e8b1

Please sign in to comment.