Skip to content

Commit

Permalink
Add dotnet registry test
Browse files Browse the repository at this point in the history
  • Loading branch information
guineveresaenger committed Feb 15, 2023
1 parent 22b0111 commit 2592c4f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 73 deletions.
65 changes: 12 additions & 53 deletions examples/container-registries/azure/csharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,80 +4,39 @@
using Pulumi;
using Pulumi.Azure.Authorization;
using Pulumi.Azure.Core;
using Pulumi.Azure.ContainerService;
using AAD = Pulumi.AzureAD;
using Azure = Pulumi.Azure.ContainerService;
using Docker = Pulumi.Docker;
using Pulumi.Random;
using Pulumi.Docker.Inputs;

class Program
{
static Task<int> Main() => Deployment.RunAsync(async () => {
// Conditionalize the auth mechanism.
var config = new Config();
var useServicePrincipalAuth = config.GetBoolean("useServicePrincipalAuth") ?? false;

// Create a private ACR registry.
var rg = new ResourceGroup("myrg");
var registry = new Registry("myregistry", new RegistryArgs
var registry = new Azure.Registry("myregistry", new Azure.RegistryArgs
{
ResourceGroupName = rg.Name,
AdminEnabled = !useServicePrincipalAuth,
AdminEnabled = true,
Sku = "basic"
});

// Get registry info (creds and endpoint) so we can build/publish to it.
var imageName = Output.Format($"{registry.LoginServer}/myapp");
Docker.ImageRegistry registryInfo;
if (useServicePrincipalAuth)
{
var sp = new AAD.ServicePrincipal("mysp", new AAD.ServicePrincipalArgs
{
ApplicationId = new AAD.Application("myspapp").ApplicationId,
});
var spPassword = new AAD.ServicePrincipalPassword("mysp-pass", new AAD.ServicePrincipalPasswordArgs
{
ServicePrincipalId = sp.Id,
Value = new RandomPassword("mypass",
new RandomPasswordArgs
{
Length = 32,
},
new CustomResourceOptions { AdditionalSecretOutputs = { "result" } }
).Result,
EndDateRelative = "8760h",
});
var spAuth = new Assignment("myauth", new AssignmentArgs
{
Scope = registry.Id,
RoleDefinitionName = "acrpush",
PrincipalId = sp.Id,
});
registryInfo = new Docker.ImageRegistry
{
Server = registry.LoginServer,
Username = sp.ApplicationId,
Password = spAuth.Id.Apply(_ => spPassword.Value),
};
}
else
{
registryInfo = new Docker.ImageRegistry
{
Server = registry.LoginServer,
Username = registry.AdminUsername,
Password = registry.AdminPassword,
};
}

// Build and publish the app image.
var image = new Docker.Image("my-image", new Docker.ImageArgs
{
Build = new Docker.DockerBuild { Context = "app" },
Build = new Docker.Inputs.DockerBuildArgs { Context = "app" },
ImageName = imageName,
Registry = registryInfo,
Registry = new Docker.Inputs.RegistryArgs
{
Server = registry.LoginServer,
Username = registry.AdminUsername,
Password = registry.AdminPassword,
},
});

// Export the resulting base name in addition to the specific version pushed.
// Export the resulting image name
return new Dictionary<string, object>
{
{ "baseImageName", image.BaseImageName },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="Pulumi.Azure" Version="2.*" />
<PackageReference Include="Pulumi.AzureAD" Version="2.*" />
<PackageReference Include="Pulumi.Docker" Version="2.2.2" />
<PackageReference Include="Pulumi.Docker" Version="4.*" />
<PackageReference Include="Pulumi.Random" Version="2.*" />
</ItemGroup>

Expand Down
21 changes: 19 additions & 2 deletions examples/examples_dotnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package examples

import (
"github.com/pulumi/pulumi/pkg/v3/testing/integration"
"os"
"path"
"testing"

"github.com/pulumi/pulumi/pkg/v3/testing/integration"
)

func TestNginxCs(t *testing.T) {
Expand All @@ -42,6 +42,23 @@ func TestDotNet(t *testing.T) {
integration.ProgramTest(t, &test)
}

func TestAzureContainerRegistryDotNet(t *testing.T) {
location := os.Getenv("AZURE_LOCATION")
if location == "" {
t.Skipf("Skipping test due to missing AZURE_LOCATION environment variable")
}
test := getCsharpBaseOptions(t).
With(integration.ProgramTestOptions{
Dir: path.Join(getCwd(t), "container-registries/azure/csharp"),
Config: map[string]string{
"azure:environment": "public",
"azure:location": location,
},
})

integration.ProgramTest(t, &test)
}

func getCsharpBaseOptions(t *testing.T) integration.ProgramTestOptions {
base := getBaseOptions()
baseCsharp := base.With(integration.ProgramTestOptions{
Expand Down
17 changes: 0 additions & 17 deletions examples/examples_py_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,6 @@ func TestAwsPy(t *testing.T) {
integration.ProgramTest(t, &test)
}

func TestAzurePy(t *testing.T) {
location := os.Getenv("AZURE_LOCATION")
if location == "" {
t.Skipf("Skipping test due to missing AZURE_LOCATION environment variable")
}
test := getPyOptions(t).
With(integration.ProgramTestOptions{
Config: map[string]string{
"azure:environment": "public",
"azure:location": location,
},
Dir: path.Join(getCwd(t), "azure-py"),
})

integration.ProgramTest(t, &test)
}

func TestAzureContainerRegistryPy(t *testing.T) {
location := os.Getenv("AZURE_LOCATION")
if location == "" {
Expand Down

0 comments on commit 2592c4f

Please sign in to comment.