forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
79 lines (73 loc) · 2.36 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"github.com/pulumi/pulumi-azure/sdk/v2/go/azure/containerservice"
"github.com/pulumi/pulumi-azure/sdk/v2/go/azure/core"
"github.com/pulumi/pulumi-docker/sdk/v2/go/docker"
"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
// Create a resource group.
resourceGroup, err := core.NewResourceGroup(ctx, "aci-rg", nil)
if err != nil {
return err
}
// Create a registry.
registryArgs := containerservice.RegistryArgs{
ResourceGroupName: resourceGroup.Name,
AdminEnabled: pulumi.Bool(true),
Sku: pulumi.String("Premium"),
}
registry, err := containerservice.NewRegistry(ctx, "registry", ®istryArgs)
if err != nil {
return err
}
// Create the docker image.
imageArgs := docker.ImageArgs{
ImageName: pulumi.Sprintf("%s/mynodeapp:v1.0.0", registry.LoginServer),
Build: &docker.DockerBuildArgs{
Context: pulumi.String("./app"),
},
Registry: &docker.ImageRegistryArgs{
Server: registry.LoginServer,
Username: registry.AdminUsername,
Password: registry.AdminPassword,
},
}
image, err := docker.NewImage(ctx, "node-app", &imageArgs)
if err != nil {
return err
}
// Create a group.
credentialArgs := containerservice.GroupImageRegistryCredentialArgs{
Server: registry.LoginServer,
Username: registry.AdminUsername,
Password: registry.AdminPassword,
}
portArgs := containerservice.GroupContainerPortArgs{
Port: pulumi.Int(80),
Protocol: pulumi.String("TCP"),
}
containerArgs := containerservice.GroupContainerArgs{
Cpu: pulumi.Float64(0.5),
Image: image.ImageName,
Memory: pulumi.Float64(1.5),
Name: pulumi.String("hello-world"),
Ports: containerservice.GroupContainerPortArray{portArgs},
}
groupArgs := containerservice.GroupArgs{
ResourceGroupName: resourceGroup.Name,
ImageRegistryCredentials: containerservice.GroupImageRegistryCredentialArray{credentialArgs},
OsType: pulumi.String("Linux"),
Containers: containerservice.GroupContainerArray{containerArgs},
IpAddressType: pulumi.String("public"),
DnsNameLabel: pulumi.String("acigo"),
}
group, err := containerservice.NewGroup(ctx, "aci", &groupArgs)
if err != nil {
return err
}
ctx.Export("endpoint", group.Fqdn)
return nil
})
}