Skip to content

Commit

Permalink
Add Azure registry integration test (#494)
Browse files Browse the repository at this point in the history
* fix: Docker auth config lookup portability

On various platforms, the Docker credentials store may return keys with URLs
with a scheme ("https://") prefixed on all entries, or hostnames only. An
exception to this is the legacy Docker index server, which appears as
"https://index.docker.io/v1/".

The push auth config is now selected by first resolving a valid ("non-legacy")
entry, which will be either a hostname aka registry name, or the
"https://index.docker.io/v1/" value. This value is then passed to
`GetAuthConfig`, using the Docker library's existing lookup fallback behavior to
handle URLs.

Two additional legacy names are handled, as discovered by reading the ORAS'
project's implementation with the same goal. See:
https://github.com/oras-project/oras-go/blob/v1.2.2/pkg/auth/docker/resolver.go#L79-L86

* Alias Docker image to avoid deletion on upgrade to v4 (#483)

* Add alias to Image

* generate schema and SDKs

* fix up nodejs test

* Remove JS folder

* Fix up Python container registry test

* Add Go Container Registry test

* Clean up auth code and simplify

* Remove az-py as duplicate container registry test

* Add dotnet registry test

---------

Co-authored-by: Aaron Friel <[email protected]>
  • Loading branch information
guineveresaenger and AaronFriel authored Feb 16, 2023
1 parent 1bd61e4 commit c66fda9
Show file tree
Hide file tree
Showing 22 changed files with 364 additions and 626 deletions.
2 changes: 0 additions & 2 deletions examples/azure-py/.gitignore

This file was deleted.

3 changes: 0 additions & 3 deletions examples/azure-py/Pulumi.yaml

This file was deleted.

22 changes: 0 additions & 22 deletions examples/azure-py/__main__.py

This file was deleted.

4 changes: 0 additions & 4 deletions examples/azure-py/app/Dockerfile

This file was deleted.

1 change: 0 additions & 1 deletion examples/azure-py/app/content/index.html

This file was deleted.

2 changes: 0 additions & 2 deletions examples/azure-py/requirements.txt

This file was deleted.

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
97 changes: 53 additions & 44 deletions examples/container-registries/azure/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,67 @@ module github.com/pulumi/pulumi-docker/examples/container-registries/azure/go
go 1.19

require (
github.com/pulumi/pulumi-azure/sdk/v2 v2.5.0
github.com/pulumi/pulumi-azuread/sdk/v2 v2.6.1
github.com/pulumi/pulumi-docker/sdk/v2 v2.4.1
github.com/pulumi/pulumi-random/sdk/v2 v2.4.2
github.com/pulumi/pulumi/sdk/v2 v2.14.0
github.com/pulumi/pulumi-azure/sdk/v5 v5.33.0
github.com/pulumi/pulumi-docker/sdk/v4 v4.0.0-alpha.3
github.com/pulumi/pulumi/sdk/v3 v3.54.0
)

require (
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20221026131551-cf6655e29de4 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/cheggaaa/pb v1.0.18 // indirect
github.com/djherbis/times v1.2.0 // indirect
github.com/emirpasic/gods v1.12.0 // indirect
github.com/gofrs/flock v0.7.1 // indirect
github.com/gofrs/uuid v3.3.0+incompatible // indirect
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/golang/protobuf v1.3.5 // indirect
github.com/cheggaaa/pb v1.0.29 // indirect
github.com/cloudflare/circl v1.1.0 // indirect
github.com/djherbis/times v1.5.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.3.1 // indirect
github.com/go-git/go-git/v5 v5.5.1 // indirect
github.com/gofrs/uuid v4.2.0+incompatible // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd // indirect
github.com/mattn/go-runewidth v0.0.8 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/opentracing/basictracer-go v1.0.0 // indirect
github.com/opentracing/opentracing-go v1.1.0 // indirect
github.com/opentracing/basictracer-go v1.1.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pjbgf/sha1cd v0.2.3 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pulumi/pulumi/sdk v1.13.1 // indirect
github.com/sabhiram/go-gitignore v0.0.0-20180611051255-d3107576ba94 // indirect
github.com/sergi/go-diff v1.0.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v1.0.0 // indirect
github.com/spf13/pflag v1.0.3 // indirect
github.com/src-d/gcfg v1.4.0 // indirect
github.com/texttheater/golang-levenshtein v0.0.0-20191208221605-eb6844b05fc6 // indirect
github.com/pkg/term v1.1.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/skeema/knownhosts v1.1.0 // indirect
github.com/spf13/cobra v1.6.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.2.0 // indirect
github.com/texttheater/golang-levenshtein v1.0.1 // indirect
github.com/tweekmonster/luser v0.0.0-20161003172636-3fa38070dbd7 // indirect
github.com/uber/jaeger-client-go v2.22.1+incompatible // indirect
github.com/uber/jaeger-lib v2.2.0+incompatible // indirect
github.com/xanzy/ssh-agent v0.2.1 // indirect
go.uber.org/atomic v1.6.0 // indirect
golang.org/x/crypto v0.0.0-20200317142112-1b76d66859c6 // indirect
golang.org/x/net v0.0.0-20200301022130-244492dfa37a // indirect
golang.org/x/sys v0.0.0-20200317113312-5766fd39f98d // indirect
golang.org/x/text v0.3.2 // indirect
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 // indirect
google.golang.org/grpc v1.28.0 // indirect
gopkg.in/src-d/go-billy.v4 v4.3.2 // indirect
gopkg.in/src-d/go-git.v4 v4.13.1 // indirect
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.uber.org/atomic v1.9.0 // indirect
golang.org/x/crypto v0.3.0 // indirect
golang.org/x/net v0.2.0 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/term v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78 // indirect
google.golang.org/grpc v1.51.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/frand v1.4.2 // indirect
sourcegraph.com/sourcegraph/appdash v0.0.0-20211028080628-e2786a622600 // indirect
)
Loading

0 comments on commit c66fda9

Please sign in to comment.