Skip to content

Commit

Permalink
Adding Packet example for Py and Ts (pulumi#447)
Browse files Browse the repository at this point in the history
stack72 authored Nov 15, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 3eb48fc commit cf9dc10
Showing 11 changed files with 201 additions and 0 deletions.
18 changes: 18 additions & 0 deletions misc/test/examples_test.go
Original file line number Diff line number Diff line change
@@ -943,6 +943,24 @@ func TestAccGcpTsServerlessRaw(t *testing.T) {
integration.ProgramTest(t, &test)
}

func TestAccPacketPyWebserver(t *testing.T) {
test := getBaseOptions(t).
With(integration.ProgramTestOptions{
Dir: path.Join(getCwd(t), "..", "..", "packet-py-webserver"),
})

integration.ProgramTest(t, &test)
}

func TestAccPacketTsWebserver(t *testing.T) {
test := getBaseOptions(t).
With(integration.ProgramTestOptions{
Dir: path.Join(getCwd(t), "..", "..", "packet-ts-webserver"),
})

integration.ProgramTest(t, &test)
}

func skipIfShort(t *testing.T) {
if testing.Short() {
t.Skip("skipping long-running test in short mode")
1 change: 1 addition & 0 deletions packet-py-webserver/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
3 changes: 3 additions & 0 deletions packet-py-webserver/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: packet-py-webserver
description: A simple server on Packet.
runtime: python
45 changes: 45 additions & 0 deletions packet-py-webserver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new)

# Packet Webserver

This example demonstrates creating a webserver in Packet.net with Python

# Running the Example

After cloning this repo, `cd` into it and run these commands.

1. Create a new stack, which is an isolated deployment target for this example:

```bash
$ pulumi stack init
```

1. Install all of the dependencies for the application:

```bash
$ npm install
```

1. Deploy everything with the `pulumi up` command. This provisions the webserver:

```bash
$ pulumi up
```

1. After a couple minutes, your webserver will be ready.

```bash
$ pulumi up
...
Outputs:
+ ip : "147.75.65.213"
+ name: "new-vervet"
```

1. Once you are done, you can destroy all of the resources, and the stack:

```bash
$ pulumi destroy
$ pulumi stack rm
```
25 changes: 25 additions & 0 deletions packet-py-webserver/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pulumi_packet as packet
import pulumi_random as random
from pulumi import export

random_host_name = random.RandomPet("hostname")
random_project_name = random.RandomPet("projectname")

project = packet.Project(
"project",
name=random_project_name.id,
)

vm = packet.Device(
"vm",
billing_cycle="hourly",
facility="ewr1",
hostname=random_host_name.id,
operating_system="coreos_stable",
plan="baremetal_0",
project_id=project.id,
ip_address_types=["public_ipv4"],
)

export('ip', vm.access_public_ipv4)
export('name', vm.hostname)
3 changes: 3 additions & 0 deletions packet-py-webserver/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pulumi>=1.0.0
pulumi-packet>=1.0.0
pulumi-random>=1.0.0
4 changes: 4 additions & 0 deletions packet-ts-webserver/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: webserver-packet
description: A simple server on Packet.
runtime: nodejs

45 changes: 45 additions & 0 deletions packet-ts-webserver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new)

# Packet Webserver

This example demonstrates creating a webserver in Packet.net

# Running the Example

After cloning this repo, `cd` into it and run these commands.

1. Create a new stack, which is an isolated deployment target for this example:

```bash
$ pulumi stack init
```

1. Install all of the dependencies for the application:

```bash
$ npm install
```

1. Deploy everything with the `pulumi up` command. This provisions the webserver:

```bash
$ pulumi up
```

1. After a couple minutes, your webserver will be ready.

```bash
$ pulumi up
...
Outputs:
+ ip : "147.75.65.213"
+ name: "new-vervet"
```

1. Once you are done, you can destroy all of the resources, and the stack:

```bash
$ pulumi destroy
$ pulumi stack rm
```
24 changes: 24 additions & 0 deletions packet-ts-webserver/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

import * as packet from "@pulumi/packet";
import * as random from "@pulumi/random";

const randomHostName = new random.RandomPet("hostname");
const randomProjectName = new random.RandomPet("project-name");

const project = new packet.Project("project", {
name: randomProjectName.id,
});

const vm = new packet.Device("vm", {
facilities: [packet.Facilities.EWR1],
billingCycle: packet.BillingCycles.Hourly,
hostname: randomHostName.id,
operatingSystem: packet.OperatingSystems.CoreOSStable,
plan: packet.Plans.T1SmallX86,
projectId: project.id,
ipAddressTypes: [packet.IpAddressTypes.PublicIPv4, packet.IpAddressTypes.PrivateIPv4, packet.IpAddressTypes.PublicIPv6],
});

export const ip = vm.accessPublicIpv4;
export const name = vm.hostname;
12 changes: 12 additions & 0 deletions packet-ts-webserver/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "packet-ts-webserver",
"version": "0.1.0",
"devDependencies": {
"@types/node": "^8.0.0"
},
"dependencies": {
"@pulumi/packet": "latest",
"@pulumi/random": "latest"
},
"license": "Apache-2.0"
}
21 changes: 21 additions & 0 deletions packet-ts-webserver/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"outDir": "bin",
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"stripInternal": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true,
"strictNullChecks": true
},
"files": [
"index.ts"
]
}

0 comments on commit cf9dc10

Please sign in to comment.