Skip to content

Commit 8d722c6

Browse files
authoredJan 10, 2025··
Ignore username/password changes in registryAuth config (#1327)
This PR modifies how the Docker provider handles changes to registry authentication credentials. Previously, any changes to the registryAuth configuration would trigger resource updates. Now, changes to usernames and passwords are ignored while changes to registry addresses still trigger updates. This aligns the native `docker.Image` resource (which already ignored username/password changes) with the rest of the bridged resources. To handle nested json-encoded configuration (related to pulumi/pulumi#17667) the provider is leveraging the `UnfoldProperties` method from the bridge. This way it can transparently operate on the config without having to worry about the json encoding. Fixes #952
1 parent 91808c6 commit 8d722c6

File tree

18 files changed

+776
-7
lines changed

18 files changed

+776
-7
lines changed
 

‎examples/examples_nodejs_test.go

+72-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"testing"
3030

3131
"github.com/pulumi/pulumi/pkg/v3/testing/integration"
32+
"github.com/pulumi/pulumi/sdk/v3/go/auto/optpreview"
3233
"github.com/stretchr/testify/assert"
3334
"github.com/stretchr/testify/require"
3435
"golang.org/x/crypto/ssh"
@@ -200,12 +201,21 @@ func TestSecretsInExplicitProviderNode(t *testing.T) {
200201
"Unexpected panic recorded in engine events")
201202
}
202203
})
204+
205+
t.Run("providerWithRandomPassword", func(t *testing.T) {
206+
pw := stack.Outputs["randomPassword"].(string)
207+
realPW, err := base64.StdEncoding.DecodeString(pw)
208+
assert.NoError(t, err)
209+
assert.NotContainsf(t, string(deploymentJSON), string(realPW),
210+
"Secret properties like RegistryAuth.Password should not be stored in the plain")
211+
})
203212
}
204213
test := getJsOptions(t).With(integration.ProgramTestOptions{
205-
Dir: path.Join(getCwd(t), "test-secrets-in-explicit-provider", "ts"),
206-
Quick: true,
207-
SkipRefresh: true,
208-
ExtraRuntimeValidation: check,
214+
Dir: path.Join(getCwd(t), "test-secrets-in-explicit-provider", "ts"),
215+
// Changes to registry username or password should not trigger a diff
216+
AllowEmptyPreviewChanges: false,
217+
SkipEmptyPreviewUpdate: false,
218+
ExtraRuntimeValidation: check,
209219
})
210220
integration.ProgramTest(t, &test)
211221
}
@@ -288,6 +298,64 @@ func TestLocalRepoDigestNode(t *testing.T) {
288298
integration.ProgramTest(t, &test)
289299
}
290300

301+
func TestRegistryImage(t *testing.T) {
302+
region := os.Getenv("AWS_REGION")
303+
if region == "" {
304+
t.Skipf("Skipping test due to missing AWS_REGION environment variable")
305+
}
306+
test := getJsOptions(t).
307+
With(integration.ProgramTestOptions{
308+
Dir: path.Join(getCwd(t), "test-registry-image"),
309+
Config: map[string]string{
310+
"aws:region": region,
311+
},
312+
ExtraRuntimeValidation: assertHasRepoDigest,
313+
})
314+
integration.ProgramTest(t, &test)
315+
}
316+
317+
// TestIgnoreAuthChangesTs tests that changes to username and password do not trigger a diff for runtimes
318+
// that receive json-encoded data for nested provider config. Nodejs is one such runtime.
319+
func TestIgnoreAuthChangesTs(t *testing.T) {
320+
t.Parallel()
321+
322+
ptest := pulumiTest(t, path.Join(getCwd(t), "test-ignore-auth-changes", "ts"))
323+
ptest.SetConfig(t, "address", "some-address")
324+
ptest.SetConfig(t, "username", "some-user")
325+
ptest.SetConfig(t, "password", "some-password")
326+
ptest.Up(t)
327+
328+
// Changes to username and password should not trigger a diff.
329+
ptest.SetConfig(t, "username", "some-other-user")
330+
ptest.SetConfig(t, "password", "some-other-password")
331+
ptest.Preview(t, optpreview.ExpectNoChanges())
332+
333+
// Changes to address should still trigger a diff.
334+
ptest.SetConfig(t, "address", "some-other-address")
335+
previewResult := ptest.Preview(t)
336+
AssertHasChanges(t, previewResult)
337+
}
338+
339+
// TestIgnoreAuthChangesYaml tests that changes to username and password do not trigger a diff for runtimes
340+
// that receive regular GRPC structs for nested provider config. YAML is one such runtime.
341+
func TestIgnoreAuthChangesYaml(t *testing.T) {
342+
ptest := pulumiTest(t, path.Join(getCwd(t), "test-ignore-auth-changes", "yaml"))
343+
ptest.SetConfig(t, "address", "some-address")
344+
ptest.SetConfig(t, "username", "some-user")
345+
ptest.SetConfig(t, "password", "some-password")
346+
ptest.Up(t)
347+
348+
// Changes to username and password should not trigger a diff.
349+
ptest.SetConfig(t, "username", "some-other-user")
350+
ptest.SetConfig(t, "password", "some-other-password")
351+
ptest.Preview(t, optpreview.ExpectNoChanges())
352+
353+
// Changes to address should trigger a diff.
354+
ptest.SetConfig(t, "address", "some-other-address")
355+
previewResult := ptest.Preview(t)
356+
AssertHasChanges(t, previewResult)
357+
}
358+
291359
func getJsOptions(t *testing.T) integration.ProgramTestOptions {
292360
base := getBaseOptions()
293361
baseJs := base.With(integration.ProgramTestOptions{

‎examples/examples_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ package examples
1616

1717
import (
1818
"os"
19+
"path/filepath"
1920
"testing"
2021

22+
"github.com/pulumi/providertest/pulumitest"
23+
"github.com/pulumi/providertest/pulumitest/changesummary"
24+
"github.com/pulumi/providertest/pulumitest/opttest"
2125
"github.com/pulumi/pulumi/pkg/v3/testing/integration"
26+
"github.com/pulumi/pulumi/sdk/v3/go/auto"
27+
"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
2228
"github.com/stretchr/testify/assert"
2329
)
2430

@@ -42,3 +48,22 @@ func assertHasRepoDigest(t *testing.T, stack integration.RuntimeValidationStackI
4248
assert.True(t, ok, "expected repoDigest output")
4349
assert.NotEmpty(t, repoDigest)
4450
}
51+
52+
func pulumiTest(t *testing.T, dir string, opts ...opttest.Option) *pulumitest.PulumiTest {
53+
cwd, err := os.Getwd()
54+
if err != nil {
55+
t.Error(err)
56+
}
57+
opts = append(opts, opttest.LocalProviderPath("docker", filepath.Join(cwd, "..", "bin")))
58+
ptest := pulumitest.NewPulumiTest(t, dir, opts...)
59+
return ptest
60+
}
61+
62+
func AssertHasChanges(t *testing.T, preview auto.PreviewResult) {
63+
t.Helper()
64+
65+
convertedMap := changesummary.ChangeSummary(preview.ChangeSummary)
66+
expectedOps := convertedMap.WhereOpEquals(apitype.OpDelete, apitype.OpDeleteReplaced, apitype.OpReplace, apitype.OpUpdate)
67+
68+
assert.NotEmpty(t, expectedOps, "expected changes, but preview returned no changes: %s", preview.StdOut)
69+
}

‎examples/go.mod

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ go 1.21
44

55
require (
66
github.com/docker/docker v27.0.3+incompatible
7+
github.com/pulumi/providertest v0.1.3
78
github.com/pulumi/pulumi/pkg/v3 v3.145.0
9+
github.com/pulumi/pulumi/sdk/v3 v3.145.0
810
github.com/stretchr/testify v1.9.0
911
golang.org/x/crypto v0.31.0
1012
)
@@ -66,6 +68,7 @@ require (
6668
github.com/edsrzf/mmap-go v1.1.0 // indirect
6769
github.com/emirpasic/gods v1.18.1 // indirect
6870
github.com/felixge/httpsnoop v1.0.4 // indirect
71+
github.com/fsnotify/fsnotify v1.7.0 // indirect
6972
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
7073
github.com/go-git/go-billy/v5 v5.5.0 // indirect
7174
github.com/go-git/go-git/v5 v5.12.0 // indirect
@@ -98,6 +101,7 @@ require (
98101
github.com/hashicorp/hcl/v2 v2.22.0 // indirect
99102
github.com/hashicorp/vault/api v1.12.0 // indirect
100103
github.com/inconshreveable/mousetrap v1.1.0 // indirect
104+
github.com/iwdgo/sigintwindows v0.2.2 // indirect
101105
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
102106
github.com/jmespath/go-jmespath v0.4.0 // indirect
103107
github.com/json-iterator/go v1.1.12 // indirect
@@ -121,6 +125,7 @@ require (
121125
github.com/muesli/reflow v0.3.0 // indirect
122126
github.com/muesli/termenv v0.15.2 // indirect
123127
github.com/natefinch/atomic v1.0.1 // indirect
128+
github.com/nxadm/tail v1.4.11 // indirect
124129
github.com/opencontainers/go-digest v1.0.0 // indirect
125130
github.com/opencontainers/image-spec v1.0.2 // indirect
126131
github.com/opentracing/basictracer-go v1.1.0 // indirect
@@ -134,7 +139,6 @@ require (
134139
github.com/pmezard/go-difflib v1.0.0 // indirect
135140
github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 // indirect
136141
github.com/pulumi/esc v0.10.0 // indirect
137-
github.com/pulumi/pulumi/sdk/v3 v3.145.0 // indirect
138142
github.com/rivo/uniseg v0.4.4 // indirect
139143
github.com/rogpeppe/go-internal v1.12.0 // indirect
140144
github.com/ryanuber/go-glob v1.0.0 // indirect
@@ -180,6 +184,7 @@ require (
180184
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
181185
google.golang.org/grpc v1.67.1 // indirect
182186
google.golang.org/protobuf v1.35.1 // indirect
187+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
183188
gopkg.in/warnings.v0 v0.1.2 // indirect
184189
gopkg.in/yaml.v3 v3.0.1 // indirect
185190
gotest.tools/v3 v3.5.1 // indirect

‎examples/go.sum

+28
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
147147
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
148148
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
149149
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
150+
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
151+
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
152+
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
153+
github.com/gkampitakis/ciinfo v0.3.0 h1:gWZlOC2+RYYttL0hBqcoQhM7h1qNkVqvRCV1fOvpAv8=
154+
github.com/gkampitakis/ciinfo v0.3.0/go.mod h1:1NIwaOcFChN4fa/B0hEBdAb6npDlFL8Bwx4dfRLRqAo=
155+
github.com/gkampitakis/go-diff v1.3.2 h1:Qyn0J9XJSDTgnsgHRdz9Zp24RaJeKMUHg2+PDZZdC4M=
156+
github.com/gkampitakis/go-diff v1.3.2/go.mod h1:LLgOrpqleQe26cte8s36HTWcTmMEur6OPYerdAAS9tk=
157+
github.com/gkampitakis/go-snaps v0.4.9 h1:x6+GEQeYWC+cnLNsHK5uXXgEQADmlH/1EqMrjfXjzk8=
158+
github.com/gkampitakis/go-snaps v0.4.9/go.mod h1:8HW4KX3JKV8M0GSw69CvT+Jqhd1AlBPMPpBfjBI3bdY=
150159
github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE=
151160
github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8=
152161
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
@@ -253,6 +262,8 @@ github.com/hashicorp/vault/api v1.12.0 h1:meCpJSesvzQyao8FCOgk2fGdoADAnbDu2WPJN1
253262
github.com/hashicorp/vault/api v1.12.0/go.mod h1:si+lJCYO7oGkIoNPAN8j3azBLTn9SjMGS+jFaHd1Cck=
254263
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
255264
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
265+
github.com/iwdgo/sigintwindows v0.2.2 h1:P6oWzpvV7MrEAmhUgs+zmarrWkyL77ycZz4v7+1gYAE=
266+
github.com/iwdgo/sigintwindows v0.2.2/go.mod h1:70wPb8oz8OnxPvsj2QMUjgIVhb8hMu5TUgX8KfFl7QY=
256267
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
257268
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
258269
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
@@ -319,6 +330,8 @@ github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo
319330
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
320331
github.com/natefinch/atomic v1.0.1 h1:ZPYKxkqQOx3KZ+RsbnP/YsgvxWQPGxjC0oBt2AhwV0A=
321332
github.com/natefinch/atomic v1.0.1/go.mod h1:N/D/ELrljoqDyT3rZrsUmtsuzvHkeB/wWjHV22AZRbM=
333+
github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY=
334+
github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc=
322335
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
323336
github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M=
324337
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
@@ -349,6 +362,8 @@ github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 h1:vkHw5I/plNdTr435
349362
github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231/go.mod h1:murToZ2N9hNJzewjHBgfFdXhZKjY3z5cYC1VXk+lbFE=
350363
github.com/pulumi/esc v0.10.0 h1:jzBKzkLVW0mePeanDRfqSQoCJ5yrkux0jIwAkUxpRKE=
351364
github.com/pulumi/esc v0.10.0/go.mod h1:2Bfa+FWj/xl8CKqRTWbWgDX0SOD4opdQgvYSURTGK2c=
365+
github.com/pulumi/providertest v0.1.3 h1:GpNKRy/haNjRHiUA9bi4diU4Op2zf3axYXbga5AepHg=
366+
github.com/pulumi/providertest v0.1.3/go.mod h1:GcsqEGgSngwaNOD+kICJPIUQlnA911fGBU8HDlJvVL0=
352367
github.com/pulumi/pulumi/pkg/v3 v3.145.0 h1:hAhFLieunnCKuMd3GbLqE5uWQ1hpNLdl6+bCDFSF4YQ=
353368
github.com/pulumi/pulumi/pkg/v3 v3.145.0/go.mod h1:N19IsMJ3GyYO5N2JfpsCAVk0eH1NKkF05fZGn5dnhBE=
354369
github.com/pulumi/pulumi/sdk/v3 v3.145.0 h1:r5iOgz67RElFXJt4GVVY2SBGh5sR24mL9NOcKBiBi/k=
@@ -375,6 +390,8 @@ github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG
375390
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
376391
github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A=
377392
github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo=
393+
github.com/spf13/cast v1.4.1 h1:s0hze+J0196ZfEMTs80N7UlFt0BDuQ7Q+JDnHiMWKdA=
394+
github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
378395
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
379396
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
380397
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
@@ -397,6 +414,14 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
397414
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
398415
github.com/texttheater/golang-levenshtein v1.0.1 h1:+cRNoVrfiwufQPhoMzB6N0Yf/Mqajr6t1lOv8GyGE2U=
399416
github.com/texttheater/golang-levenshtein v1.0.1/go.mod h1:PYAKrbF5sAiq9wd+H82hs7gNaen0CplQ9uvm6+enD/8=
417+
github.com/tidwall/gjson v1.17.0 h1:/Jocvlh98kcTfpN2+JzGQWQcqrPQwDrVEMApx/M5ZwM=
418+
github.com/tidwall/gjson v1.17.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
419+
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
420+
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
421+
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
422+
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
423+
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
424+
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
400425
github.com/uber/jaeger-client-go v2.30.0+incompatible h1:D6wyKGCecFaSRUpo8lCVbaOOb6ThwMmTEbhRwtKR97o=
401426
github.com/uber/jaeger-client-go v2.30.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk=
402427
github.com/uber/jaeger-lib v2.4.1+incompatible h1:td4jdvLcExb4cBISKIpHuGoVXh+dVKhn2Um6rjCsSsg=
@@ -515,6 +540,7 @@ golang.org/x/sys v0.0.0-20211110154304-99a53858aa08/go.mod h1:oPkhp1MJrh7nUepCBc
515540
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
516541
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
517542
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
543+
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
518544
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
519545
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
520546
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -608,6 +634,8 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
608634
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
609635
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
610636
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
637+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
638+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
611639
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
612640
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
613641
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: test-ignore-auth-changes
2+
runtime: nodejs
3+
description: A minimal TypeScript Pulumi program
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as pulumi from "@pulumi/pulumi";
2+
import * as docker from "@pulumi/docker";
3+
4+
const config = new pulumi.Config();
5+
6+
// Changes to username and password should not trigger a diff, but changes to address should.
7+
const provider = new docker.Provider("docker", {
8+
registryAuth: [
9+
{
10+
address: config.require("address"),
11+
username: config.require("username"),
12+
password: config.require("password"),
13+
},
14+
],
15+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "test-ignore-auth-changes",
3+
"devDependencies": {
4+
"@types/node": "^14.0.0"
5+
},
6+
"dependencies": {
7+
"@pulumi/docker": "^4.5.8",
8+
"@pulumi/pulumi": "^3.144.1"
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: docker-provider-config
2+
runtime: yaml
3+
config:
4+
username:
5+
type: string
6+
password:
7+
type: string
8+
address:
9+
type: string
10+
resources:
11+
dockerProvider:
12+
type: pulumi:providers:docker
13+
properties:
14+
registryAuth:
15+
- address: ${address}
16+
username: ${username}
17+
password: ${password}
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/bin/
2+
/node_modules/
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: test-registry-image
2+
runtime: nodejs
3+
description: A minimal AWS TypeScript Pulumi program
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM nginx
2+
RUN echo "<h1>Hi from Pulumi!</h1>" > \
3+
/usr/share/nginx/html/index.html

‎examples/test-registry-image/index.ts

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import * as aws from "@pulumi/aws";
2+
import * as docker from "@pulumi/docker";
3+
4+
// Create a private ECR registry.
5+
const repo = new aws.ecr.Repository("my-repo",{
6+
forceDelete: true,
7+
});
8+
9+
// Get registry info (creds and endpoint) so we can build/publish to it.
10+
const registryInfo = repo.registryId.apply(async id => {
11+
const credentials = await aws.ecr.getCredentials({ registryId: id });
12+
const decodedCredentials = Buffer.from(credentials.authorizationToken, "base64").toString();
13+
const [username, password] = decodedCredentials.split(":");
14+
if (!password || !username) {
15+
throw new Error("Invalid credentials");
16+
}
17+
return {
18+
address: credentials.proxyEndpoint,
19+
username: username,
20+
password: password,
21+
};
22+
});
23+
24+
25+
// Build and publish the image.
26+
const image = new docker.Image("my-image", {
27+
build: {
28+
context: "app",
29+
},
30+
imageName: repo.repositoryUrl,
31+
skipPush: true
32+
});
33+
34+
const ecrProvider = new docker.Provider("ecr-provider", {
35+
registryAuth: [registryInfo],
36+
});
37+
38+
// Publish the image to the registry
39+
const registryImage = new docker.RegistryImage("my-registry-image",
40+
{
41+
name: repo.repositoryUrl,
42+
},
43+
{ provider: ecrProvider, dependsOn: [image] },
44+
);
45+
46+
// Export the resulting image name
47+
export const imageName = registryImage.name;
48+
export const repoDigest = registryImage.sha256Digest;
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "test-registry-image",
3+
"devDependencies": {
4+
"@types/node": "^14.0.0"
5+
},
6+
"dependencies": {
7+
"@pulumi/aws": "^6.10.0",
8+
"@pulumi/pulumi": "^3.0.0",
9+
"@pulumi/docker": "^4.5.0"
10+
}
11+
}

0 commit comments

Comments
 (0)
Please sign in to comment.