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.
Example with docker and ACI for C# and F# (pulumi#482)
* Example with docker and ACI for C# and F# * Fix build errrors * EOL
- Loading branch information
1 parent
b78037d
commit 1950078
Showing
19 changed files
with
732 additions
and
17 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
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,105 @@ | ||
// Copyright 2016-2018, Pulumi Corporation. All rights reserved. | ||
|
||
using System.Collections.Generic; | ||
|
||
using Pulumi; | ||
using Pulumi.Azure.ContainerService; | ||
using Pulumi.Azure.ContainerService.Inputs; | ||
using Pulumi.Azure.Core; | ||
using Pulumi.Docker; | ||
|
||
public static class Containers | ||
{ | ||
public static IDictionary<string, object> Run() | ||
{ | ||
// Read a list of target locations from the config file: | ||
// Expecting a comma-separated list, e.g., "westus,eastus,westeurope" | ||
var locations = new Pulumi.Config().Require("locations").Split(","); | ||
|
||
var resourceGroup = new ResourceGroup("cosmosaci-rg", new ResourceGroupArgs { Location = locations[0] }); | ||
|
||
var app = new CosmosApp("aci", new CosmosAppArgs | ||
{ | ||
ResourceGroup = resourceGroup, | ||
Locations = locations, | ||
DatabaseName = "pricedb", | ||
ContainerName = "prices", | ||
Factory = global => | ||
{ | ||
var registry = new Registry("global", new RegistryArgs | ||
{ | ||
ResourceGroupName = resourceGroup.Name, | ||
AdminEnabled = true, | ||
Sku = "Premium", | ||
}, global.Options); | ||
|
||
var dockerImage = new Image("node-app", new ImageArgs | ||
{ | ||
ImageName = Output.Format($"{registry.LoginServer}/mynodeapp:v1.0.0"), | ||
Build = "./container", | ||
Registry = new ImageRegistry | ||
{ | ||
Server = registry.LoginServer, | ||
Username = registry.AdminUsername, | ||
Password = registry.AdminPassword, | ||
}, | ||
}, new ComponentResourceOptions { Parent = registry }); | ||
|
||
return region => | ||
{ | ||
var connectionString = global.CosmosAccount.ConnectionStrings.Apply(cs => cs[0]); | ||
var group = new Group($"aci-{region.Location}", new GroupArgs | ||
{ | ||
ResourceGroupName = resourceGroup.Name, | ||
Location = region.Location, | ||
ImageRegistryCredentials = | ||
{ | ||
new GroupImageRegistryCredentialsArgs | ||
{ | ||
Server = registry.LoginServer, | ||
Username = registry.AdminUsername, | ||
Password = registry.AdminPassword, | ||
} | ||
}, | ||
OsType = "Linux", | ||
Containers = | ||
{ | ||
new GroupContainersArgs | ||
{ | ||
Cpu = 0.5, | ||
Image = dockerImage.ImageName, | ||
Memory = 1.5, | ||
Name = "hello-world", | ||
Ports = | ||
{ | ||
new GroupContainersPortsArgs | ||
{ | ||
Port = 80, | ||
Protocol = "TCP", | ||
} | ||
}, | ||
EnvironmentVariables = | ||
{ | ||
{ "ENDPOINT", global.CosmosAccount.Endpoint }, | ||
{ "MASTER_KEY", global.CosmosAccount.PrimaryMasterKey }, | ||
{ "DATABASE", global.Database.Name }, | ||
{ "COLLECTION", global.Container.Name }, | ||
{ "LOCATION", region.Location }, | ||
}, | ||
}, | ||
}, | ||
IpAddressType = "public", | ||
DnsNameLabel = $"acishop-{region.Location}", | ||
}, global.Options); | ||
|
||
return new ExternalEndpoint(group.Fqdn); | ||
}; | ||
} | ||
}); | ||
|
||
return new Dictionary<string, object> | ||
{ | ||
{ "containersEndpoint", Output.Format($"{app.Endpoint}/cosmos") } | ||
}; | ||
} | ||
} |
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
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,33 @@ | ||
<html> | ||
<head> | ||
<title>YEAH Welcome to Azure Container Instances!</title> | ||
</head> | ||
<style> | ||
h1 { | ||
color: darkblue; | ||
font-family:arial, sans-serif; | ||
font-weight: lighter; | ||
} | ||
</style> | ||
|
||
<body> | ||
|
||
<div align="center"> | ||
<h1>Welcome to Azure Container Instances!</h1> | ||
|
||
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 49.8 49.9" width="250px" height="250px"> | ||
<title>ContainerInstances_rgb_UI</title> | ||
<path d="M41.9,11.368A11.929,11.929,0,0,0,20.3,5.061a9.444,9.444,0,0,0-14.932,9.8A8.969,8.969,0,0,0,9.064,32H39.442A10.463,10.463,0,0,0,41.9,11.368Z" transform="translate(-0.1 -0.1)" fill="#fff"/> | ||
<path d="M41.9,11.368A11.929,11.929,0,0,0,20.3,5.061a9.444,9.444,0,0,0-14.932,9.8A8.969,8.969,0,0,0,9.064,32H39.442A10.463,10.463,0,0,0,41.9,11.368Z" transform="translate(-0.1 -0.1)" fill="#27a9e1" opacity="0.6" style="isolation:isolate"/> | ||
<path d="M13,22a1,1,0,0,0-1,1V49a1,1,0,0,0,1,1H37a1,1,0,0,0,1-1V23a1,1,0,0,0-1-1Z" transform="translate(-0.1 -0.1)" fill="#672a7a"/> | ||
<path d="M26.95,16" transform="translate(-0.1 -0.1)" fill="none"/> | ||
<path d="M34.95,20" transform="translate(-0.1 -0.1)" fill="none"/> | ||
<polygon points="22.9 21.9 22.9 14.9 19.9 14.9 24.9 7.9 29.9 14.9 26.9 14.9 26.9 21.9 22.9 21.9" fill="#fff"/> | ||
<path d="M26.95,16" transform="translate(-0.1 -0.1)" fill="#814a98"/> | ||
<path d="M33,25H15V47H35V25ZM21,45H17V27h4Zm6,0H23V27h4Zm6,0H29V27h4Z" transform="translate(-0.1 -0.1)" fill="#b92025" opacity="0.3" style="isolation:isolate"/> | ||
<path d="M33,25H15V47H35V25ZM21,45H17V27h4Zm6,0H23V27h4Zm6,0H29V27h4Z" transform="translate(-0.1 -0.1)" fill="#fff" style="isolation:isolate"/> | ||
</svg> | ||
</div> | ||
|
||
</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,37 @@ | ||
const express = require('express'); | ||
const morgan = require('morgan'); | ||
const cosmos = require('@azure/cosmos'); | ||
|
||
const app = express(); | ||
app.use(morgan('combined')); | ||
|
||
|
||
app.get('/', (req, res) => { | ||
res.sendFile(__dirname + '/index.html') | ||
}); | ||
|
||
app.get('/cosmos', async (req, res) => { | ||
const endpoint = process.env.ENDPOINT; | ||
const key = process.env.MASTER_KEY; | ||
const database = process.env.DATABASE; | ||
const collection = process.env.COLLECTION; | ||
const location = process.env.LOCATION; | ||
|
||
const client = new cosmos.CosmosClient({ endpoint, key, connectionPolicy: { preferredLocations: [location] } }); | ||
const container = client.database(database).container(collection); | ||
const response = await container.item("test", undefined).read(); | ||
|
||
if (response.resource && response.resource.url) { | ||
res.send(response.resource.url); | ||
} else { | ||
res.status(404).end(); | ||
} | ||
}); | ||
|
||
app.get('/api/ping', (req, res) => { | ||
res.send('Ack') | ||
}); | ||
|
||
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,13 @@ | ||
{ | ||
"name": "aci-helloworld", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"dependencies": { | ||
"@azure/cosmos": "^3.1.1", | ||
"express": "^4.14.0", | ||
"morgan": "^1.8.2" | ||
}, | ||
"devDependencies": {}, | ||
"author": "" | ||
} |
Oops, something went wrong.