forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Azure Go Container Apps (pulumi#1109)
* Azure Go Container Apps * Simplify
- Loading branch information
1 parent
7fd20c4
commit 399e497
Showing
11 changed files
with
612 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: azure-go-containerapps | ||
runtime: go | ||
description: Creates an Azure Container App and deploys a custom Docker image to it |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new) | ||
|
||
# Azure Container Apps | ||
|
||
Starting point for building web application hosted in Azure Container Apps. | ||
|
||
## Running the App | ||
|
||
1. Create a new stack: | ||
|
||
``` | ||
$ pulumi stack init dev | ||
``` | ||
|
||
1. Login to Azure CLI (you will be prompted to do this during deployment if you forget this step): | ||
|
||
``` | ||
$ az login | ||
``` | ||
|
||
1. Set the Azure region location to use: | ||
|
||
``` | ||
$ pulumi config set azure-native:location westus2 | ||
``` | ||
|
||
1. Run `pulumi up` to preview and deploy changes: | ||
|
||
``` | ||
$ pulumi up | ||
Previewing changes: | ||
... | ||
Performing changes: | ||
... | ||
Resources: | ||
+ 7 created | ||
Duration: 4m18s | ||
``` | ||
|
||
1. Check the deployed endpoint: | ||
|
||
``` | ||
$ curl "$(pulumi stack output url)" | ||
<html> | ||
<body> | ||
<h1>Your custom docker image is running in Azure Container Apps!</h1> | ||
</body> | ||
</html> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module github.com/pulumi/examples/azure-go-containerapps | ||
|
||
go 1.16 | ||
|
||
require ( | ||
github.com/pulumi/pulumi-azure-native/sdk v1.44.0 | ||
github.com/pulumi/pulumi-docker/sdk/v3 v3.1.0 | ||
github.com/pulumi/pulumi/sdk/v3 v3.16.0 | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
// Copyright 2016-2021, Pulumi Corporation. All rights reserved. | ||
package main | ||
|
||
import ( | ||
"github.com/pulumi/pulumi-azure-native/sdk/go/azure/containerregistry" | ||
"github.com/pulumi/pulumi-azure-native/sdk/go/azure/operationalinsights" | ||
"github.com/pulumi/pulumi-azure-native/sdk/go/azure/resources" | ||
web "github.com/pulumi/pulumi-azure-native/sdk/go/azure/web/v20210301" | ||
"github.com/pulumi/pulumi-docker/sdk/v3/go/docker" | ||
"github.com/pulumi/pulumi/sdk/v3/go/pulumi" | ||
) | ||
|
||
func main() { | ||
pulumi.Run(func(ctx *pulumi.Context) error { | ||
|
||
resourceGroup, err := resources.NewResourceGroup(ctx, "rg", nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
workspace, err := operationalinsights.NewWorkspace(ctx, "workspace", &operationalinsights.WorkspaceArgs{ | ||
ResourceGroupName: resourceGroup.Name, | ||
RetentionInDays: pulumi.Int(30), | ||
Sku: operationalinsights.WorkspaceSkuArgs{ | ||
Name: pulumi.String("PerGB2018"), | ||
}, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
sharedKey := pulumi.All(resourceGroup.Name, workspace.Name).ApplyT( | ||
func(args []interface{}) (string, error) { | ||
resourceGroupName := args[0].(string) | ||
workspaceName := args[1].(string) | ||
accountKeys, err := operationalinsights.GetSharedKeys(ctx, &operationalinsights.GetSharedKeysArgs{ | ||
ResourceGroupName: resourceGroupName, | ||
WorkspaceName: workspaceName, | ||
}) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return *accountKeys.PrimarySharedKey, nil | ||
}, | ||
).(pulumi.StringOutput) | ||
|
||
kubeEnvironment, err := web.NewKubeEnvironment(ctx, "kubeEnvironment", &web.KubeEnvironmentArgs{ | ||
ResourceGroupName: resourceGroup.Name, | ||
Type: pulumi.String("Managed"), | ||
AppLogsConfiguration: web.AppLogsConfigurationArgs{ | ||
Destination: pulumi.String("log-analytics"), | ||
LogAnalyticsConfiguration: web.LogAnalyticsConfigurationArgs{ | ||
CustomerId: workspace.CustomerId, | ||
SharedKey: sharedKey, | ||
}, | ||
}, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
registry, err := containerregistry.NewRegistry(ctx, "registry", &containerregistry.RegistryArgs{ | ||
ResourceGroupName: resourceGroup.Name, | ||
Sku: containerregistry.SkuArgs{ | ||
Name: pulumi.String("Basic"), | ||
}, | ||
AdminUserEnabled: pulumi.Bool(true), | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
credentials := pulumi.All(resourceGroup.Name, registry.Name).ApplyT( | ||
func(args []interface{}) (*containerregistry.ListRegistryCredentialsResult, error) { | ||
resourceGroupName := args[0].(string) | ||
registryName := args[1].(string) | ||
return containerregistry.ListRegistryCredentials(ctx, &containerregistry.ListRegistryCredentialsArgs{ | ||
ResourceGroupName: resourceGroupName, | ||
RegistryName: registryName, | ||
}) | ||
}, | ||
) | ||
|
||
adminUsername := credentials.ApplyT(func(result interface{}) (string, error) { | ||
credentials := result.(*containerregistry.ListRegistryCredentialsResult) | ||
return *credentials.Username, nil | ||
}).(pulumi.StringOutput) | ||
adminPassword := credentials.ApplyT(func(result interface{}) (string, error) { | ||
credentials := result.(*containerregistry.ListRegistryCredentialsResult) | ||
return *credentials.Passwords[0].Value, nil | ||
}).(pulumi.StringOutput) | ||
|
||
newImage, err := docker.NewImage(ctx, "node-app", &docker.ImageArgs{ | ||
ImageName: pulumi.Sprintf("https://%s/node-app:v1.0.0", registry.LoginServer), | ||
Build: docker.DockerBuildArgs{ | ||
Context: pulumi.String("/node-app"), | ||
}, | ||
Registry: docker.ImageRegistryArgs{ | ||
Server: registry.LoginServer, | ||
Username: adminUsername, | ||
Password: adminPassword, | ||
}, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
containerApp, err := web.NewContainerApp(ctx, "app", &web.ContainerAppArgs{ | ||
ResourceGroupName: resourceGroup.Name, | ||
KubeEnvironmentId: kubeEnvironment.ID(), | ||
Configuration: web.ConfigurationArgs{ | ||
Ingress: web.IngressArgs{ | ||
External: pulumi.Bool(true), | ||
TargetPort: pulumi.IntPtr(80), | ||
}, | ||
Registries: web.RegistryCredentialsArray{ | ||
web.RegistryCredentialsArgs{ | ||
Server: registry.LoginServer, | ||
Username: adminUsername, | ||
PasswordSecretRef: pulumi.String("pwd")}, | ||
}, | ||
Secrets: web.SecretArray{ | ||
web.SecretArgs{ | ||
Name: pulumi.String("pwd"), | ||
Value: adminPassword, | ||
}, | ||
}, | ||
}, | ||
Template: web.TemplateArgs{ | ||
Containers: web.ContainerArray{ | ||
web.ContainerArgs{ | ||
Name: pulumi.String("myapp"), | ||
Image: newImage.ImageName, | ||
}, | ||
}, | ||
}, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ctx.Export("url", pulumi.Sprintf("https://%s", containerApp.LatestRevisionFqdn)) | ||
|
||
return nil | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM node:8.9.3-alpine | ||
RUN mkdir -p /usr/src/app | ||
COPY ./app/* /usr/src/app/ | ||
WORKDIR /usr/src/app | ||
RUN npm install | ||
CMD node /usr/src/app/index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
<html> | ||
<body> | ||
<h1>Your custom docker image is running in Azure Container Apps!</h1> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const express = require('express'); | ||
const morgan = require('morgan'); | ||
|
||
const app = express(); | ||
app.use(morgan('combined')); | ||
|
||
app.get('/', (req, res) => { | ||
res.sendFile(__dirname + '/index.html') | ||
}); | ||
|
||
var listener = app.listen(process.env.PORT || 80, function() { | ||
console.log('listening on port ' + listener.address().port); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "node-helloworld", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"dependencies": { | ||
"express": "^4.14.0", | ||
"morgan": "^1.8.2" | ||
}, | ||
"devDependencies": {}, | ||
"author": "" | ||
} |