Skip to content

Commit

Permalink
Add container example (pulumi#59)
Browse files Browse the repository at this point in the history
* Add container example
  • Loading branch information
lindydonna committed May 23, 2018
1 parent fae2771 commit 50c780c
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cloud-js-containers/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: container-quickstart
description: NGINX container example
runtime: nodejs
60 changes: 60 additions & 0 deletions cloud-js-containers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Easy container example

Companion to the tutorial [Provision containers on AWS](https://docs.pulumi.com/quickstart/aws-containers.html).

## Prerequisites

To run this example, make sure [Docker](https://docs.docker.com/engine/installation/) is installed and running.

## Running the App

1. Create a new stack:

```
$ pulumi stack init containers-dev
```

1. Configure Pulumi to use AWS Fargate, which is currently only available in `us-east-1`, `us-west-2`, and `eu-west-1`:

```
$ pulumi config set aws:region us-west-2
$ pulumi config set cloud-aws:useFargate true
```

1. Restore NPM modules via `npm install`.

1. Preview and deploy the app via `pulumi update`. The preview will take a few minutes, as it builds a Docker container. A total of 19 resources are created.

```
$ pulumi update
```

1. View the endpoint URL, and run curl or view in a browser.

```bash
$ pulumi stack output
Current stack outputs (1)
OUTPUT VALUE
hostname http:https://42dc3ff4-ac65d11-86a100b6e1d7f210.elb.us-west-2.amazonaws.com

$ curl $(pulumi stack output hostname)
<html>
<head>
<title>Hello Pulumi</title><meta charset="UTF-8">
...
```

![Screenshot of browser](./final-screenshot.png)

1. To view the runtime logs from the container, use the `pulumi logs` command. To get a log stream, use `pulumi logs --follow`.

```
$ pulumi logs --follow
Collecting logs for stack container-quickstart-dev since 2018-05-22T14:25:46.000-07:00.
2018-05-22T15:33:22.057-07:00[ pulumi-nginx] 172.31.13.248 - - [22/May/2018:22:33:22 +0000] "GET / HTTP/1.1" 200 189 "-" "curl/7.54.0" "-"
```

## Clean up

To clean up resources, run `pulumi destroy` and answer the confirmation question at the prompt.

2 changes: 2 additions & 0 deletions cloud-js-containers/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM nginx
COPY content /usr/share/nginx/html
Binary file added cloud-js-containers/app/content/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions cloud-js-containers/app/content/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<html>
<head>
<title>Hello Pulumi</title><meta charset="UTF-8">
<link rel="shortcut icon" href="favicon.png" type="image/png">

<style>
body { background: linear-gradient( #7c4792, white); }
p.main { font-size: 2.5em; }
p.footer { font-size: 1em; }
div {
font-family: Helvetica, Segoe UI, Arial, sans-serif;
margin: 20px;
text-align: center;
color: white;
}
</style>
</head>

<body>
<div>
<p class="main">Hello, containers!</p>
<p class="footer">Made with ❤️ using <a href="https://pulumi.com">Pulumi</a></p>
</div>
</body>
</html>
Binary file added cloud-js-containers/final-screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions cloud-js-containers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const cloud = require("@pulumi/cloud-aws");

let service = new cloud.Service("pulumi-nginx", {
containers: {
nginx: {
build: "./app",
memory: 128,
ports: [{ port: 80 }],
},
},
replicas: 2,
});

// export just the hostname property of the container frontend
exports.hostname = service.defaultEndpoint.apply(e => `http:https://${e.hostname}`);
10 changes: 10 additions & 0 deletions cloud-js-containers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "container-quickstart",
"main": "index.js",
"dependencies": {
"@pulumi/aws": "^0.13.0",
"@pulumi/cloud": "^0.13.0",
"@pulumi/cloud-aws": "^0.13.0",
"@pulumi/pulumi": "^0.12.2"
}
}

0 comments on commit 50c780c

Please sign in to comment.