Skip to content

Commit d67b1c3

Browse files
authored
Add java examples (#1210)
* Add aws-java-webserver example * Add aws-java-eks-minimal example * Add aws-native-java-s3-folder example * Add azure-java-appservice-sql example * Add azure-java-function-graal-spring example * Add azure-java-static-website example * Add gcp-java-gke-hello-world example
1 parent 61ad2c8 commit d67b1c3

File tree

58 files changed

+1904
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1904
-0
lines changed

aws-java-eks-minimal/.gitattributes

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# These are explicitly windows files and should use crlf
5+
*.bat text eol=crlf
6+

aws-java-eks-minimal/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore Gradle project-specific cache directory
2+
.gradle
3+
4+
# Ignore Gradle build output directory
5+
build

aws-java-eks-minimal/Pulumi.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: eks-minimal
2+
description: A minimal example of using pulumi-eks
3+
runtime: java

aws-java-eks-minimal/README.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# eks-minimal
2+
3+
This example demonstrates consuming
4+
[Pulumi AWS EKS Components](https://github.com/pulumi/pulumi-eks)
5+
from Java.
6+
7+
The high-level Cluster component automatically provisions roles,
8+
security groups and other necessary resources with good defaults,
9+
making it easy to get started. For more information, checkout the
10+
relevant
11+
[Pulumi blog](https://www.pulumi.com/blog/easily-create-and-manage-aws-eks-kubernetes-clusters-with-pulumi)
12+
13+
14+
## Running the example
15+
16+
1. Start a new stack:
17+
18+
```bash
19+
pulumi stack init dev
20+
```
21+
22+
1. Configure your AWS region, for example:
23+
24+
```bash
25+
pulumi config set aws:region us-east-1
26+
```
27+
28+
1. Deploy the example. Note it will take up to 10 minutes to provision
29+
the EKS cluster:
30+
31+
```bash
32+
pulumi up
33+
```
34+
35+
1. Access the Kubernetes Cluster using `kubectl`.
36+
37+
To access your new Kubernetes cluster using `kubectl`, we need to
38+
setup the `kubeconfig` file and download `kubectl`. We can leverage
39+
the Pulumi stack output in the CLI, as Pulumi facilitates exporting
40+
these objects for us.
41+
42+
```bash
43+
$ pulumi stack output kubeconfig --show-secrets > kubeconfig
44+
$ export KUBECONFIG=$PWD/kubeconfig
45+
$ kubectl version
46+
$ kubectl cluster-info
47+
$ kubectl get nodes
48+
```

aws-java-eks-minimal/app/build.gradle

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
plugins {
2+
id 'application'
3+
}
4+
5+
repositories {
6+
mavenLocal()
7+
maven { // The google mirror is less flaky than mavenCentral()
8+
url("https://maven-central.storage-download.googleapis.com/maven2/")
9+
}
10+
mavenCentral()
11+
}
12+
13+
dependencies {
14+
implementation "com.pulumi:pulumi:(,1.0]"
15+
implementation "com.pulumi:kubernetes:(3.0,4.0]"
16+
implementation "com.pulumi:aws:(5.0,6.0]"
17+
implementation "com.pulumi:eks:(,1.0]"
18+
}
19+
20+
application {
21+
mainClass = project.hasProperty("mainClass")
22+
? project.getProperty("mainClass")
23+
: 'com.pulumi.example.eksminimal.App'
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.pulumi.example.eksminimal;
2+
3+
import com.pulumi.Context;
4+
import com.pulumi.Pulumi;
5+
import com.pulumi.aws.ec2.Ec2Functions;
6+
import com.pulumi.aws.ec2.inputs.GetSubnetIdsArgs;
7+
import com.pulumi.aws.ec2.inputs.GetVpcArgs;
8+
import com.pulumi.aws.ec2.outputs.GetVpcResult;
9+
import com.pulumi.core.Output;
10+
import com.pulumi.eks.Cluster;
11+
import com.pulumi.eks.ClusterArgs;
12+
13+
import java.util.stream.Collectors;
14+
15+
public class App {
16+
public static void main(String[] args) {
17+
Pulumi.run(App::stack);
18+
}
19+
20+
private static void stack(Context ctx) {
21+
var vpcIdOutput = Output.of(
22+
Ec2Functions.getVpc(
23+
GetVpcArgs.builder().default_(true).build()
24+
).thenApply(GetVpcResult::id)
25+
);
26+
ctx.export("vpcIdOutput", vpcIdOutput);
27+
28+
var subnetIdsOutput = vpcIdOutput
29+
.apply(vpcId -> Output.of(Ec2Functions.getSubnetIds(GetSubnetIdsArgs.builder()
30+
.vpcId(vpcId)
31+
.build())))
32+
.applyValue(getSubnetIdsResult ->
33+
getSubnetIdsResult.ids()
34+
.stream()
35+
.sorted()
36+
.limit(2)
37+
.collect(Collectors.toList()));
38+
39+
ctx.export("subnetIdsOutput", subnetIdsOutput.applyValue(vs -> String.join(",", vs)));
40+
41+
var cluster = new Cluster("my-cluster", ClusterArgs.builder()
42+
.vpcId(vpcIdOutput)
43+
.subnetIds(subnetIdsOutput)
44+
.instanceType("t2.micro")
45+
.minSize(1)
46+
.maxSize(2)
47+
.build());
48+
49+
ctx.export("kubeconfig", cluster.kubeconfig());
50+
}
51+
}

aws-java-eks-minimal/settings.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rootProject.name = 'eksminimal'
2+
include('app')

aws-java-webserver/.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Ignore Gradle project-specific cache directory
2+
.gradle
3+
4+
# Ignore Gradle build output directory
5+
app/build/**
6+
app/bin/**

aws-java-webserver/Pulumi.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: aws-java-webserver
2+
runtime: java
3+
description: Basic example of an AWS web server accessible over HTTP
4+
template:
5+
config:
6+
aws:region:
7+
description: The AWS region to deploy into
8+
default: us-east-1

aws-java-webserver/README.md

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Web Server Using Amazon EC2
2+
3+
This example deploys a simple AWS EC2 virtual machine running a Python web server.
4+
5+
## Deploying the App
6+
7+
To deploy your infrastructure, follow the below steps.
8+
9+
### Prerequisites
10+
11+
1. [Install Pulumi](https://www.pulumi.com/docs/get-started/install/)
12+
2. [Configure AWS Credentials](https://www.pulumi.com/docs/intro/cloud-providers/aws/setup/)
13+
14+
### Steps
15+
16+
After cloning this repo, from this working directory, run these commands:
17+
18+
1. Create a new stack, which is an isolated deployment target for this example:
19+
20+
```bash
21+
$ pulumi stack init
22+
```
23+
24+
2. Set the required configuration variables for this program:
25+
26+
```bash
27+
$ pulumi config set aws:region us-east-1
28+
```
29+
30+
3. Stand up the VM, which will also boot up your Python web server on port 80:
31+
32+
```bash
33+
$ pulumi up
34+
```
35+
36+
4. After a couple minutes, your VM will be ready, and two stack outputs are printed:
37+
38+
```bash
39+
$ pulumi stack output
40+
Current stack outputs (2):
41+
OUTPUT VALUE
42+
publicHostName ec2-53-40-227-82.compute-1.amazonaws.com
43+
publicIp 53.40.227.82
44+
```
45+
46+
5. Thanks to the security group making port 80 accessible to the 0.0.0.0/0 CIDR block (all addresses), we can curl it:
47+
48+
```bash
49+
$ curl $(pulumi stack output publicIp)
50+
Hello, World!
51+
```
52+
53+
6. From there, feel free to experiment. Simply making edits and running `pulumi up` will incrementally update your VM.
54+
55+
7. Afterwards, destroy your stack and remove it:
56+
57+
```bash
58+
$ pulumi destroy --yes
59+
$ pulumi stack rm --yes
60+
```

aws-java-webserver/app/build.gradle

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
plugins {
2+
id 'application'
3+
}
4+
5+
repositories {
6+
mavenLocal()
7+
maven { // The google mirror is less flaky than mavenCentral()
8+
url("https://maven-central.storage-download.googleapis.com/maven2/")
9+
}
10+
mavenCentral()
11+
}
12+
13+
dependencies {
14+
implementation "com.pulumi:pulumi:(,1.0]"
15+
implementation "com.pulumi:aws:(5.0,6.0]"
16+
}
17+
18+
application {
19+
mainClass = project.hasProperty("mainClass")
20+
? project.getProperty("mainClass")
21+
: 'webserver.App'
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package webserver;
2+
3+
import com.pulumi.Context;
4+
import com.pulumi.Pulumi;
5+
import com.pulumi.aws.ec2.Ec2Functions;
6+
import com.pulumi.aws.ec2.Instance;
7+
import com.pulumi.aws.ec2.InstanceArgs;
8+
import com.pulumi.aws.ec2.SecurityGroup;
9+
import com.pulumi.aws.ec2.SecurityGroupArgs;
10+
import com.pulumi.aws.ec2.inputs.GetAmiArgs;
11+
import com.pulumi.aws.ec2.inputs.GetAmiFilter;
12+
import com.pulumi.aws.ec2.inputs.SecurityGroupIngressArgs;
13+
import com.pulumi.aws.ec2.outputs.GetAmiResult;
14+
import com.pulumi.core.Output;
15+
16+
import java.util.List;
17+
import java.util.Map;
18+
19+
public class App {
20+
public static void main(String[] args) {
21+
Pulumi.run(App::stack);
22+
}
23+
24+
public static void stack(Context ctx) {
25+
final var ami = Ec2Functions.getAmi(GetAmiArgs.builder()
26+
.filters(GetAmiFilter.builder()
27+
.name("name")
28+
.values("amzn-ami-hvm-*-x86_64-ebs")
29+
.build())
30+
.owners("137112412989")
31+
.mostRecent(true)
32+
.build()
33+
).thenApply(GetAmiResult::id);
34+
35+
final var group = new SecurityGroup("web-secgrp", SecurityGroupArgs.builder()
36+
.ingress(SecurityGroupIngressArgs.builder()
37+
.protocol("tcp")
38+
.fromPort(80)
39+
.toPort(80)
40+
.cidrBlocks("0.0.0.0/0")
41+
.build())
42+
.build()
43+
);
44+
45+
// (optional) create a simple web server using the startup
46+
// script for the instance
47+
48+
final var userData =
49+
"#!/bin/bash\n" +
50+
"echo \"Hello, World!\" > index.html\n" +
51+
"nohup python -m SimpleHTTPServer 80 &";
52+
53+
final var server = new Instance("web-server-www", InstanceArgs.builder()
54+
.tags(Map.of("Name", "web-server-www"))
55+
.instanceType(Output.ofRight(com.pulumi.aws.ec2.enums.InstanceType.T2_Micro))
56+
.vpcSecurityGroupIds(group.getId().applyValue(List::of))
57+
.ami(Output.of(ami))
58+
.userData(userData)
59+
.build()
60+
);
61+
62+
ctx.export("publicIp", server.publicIp());
63+
ctx.export("publicHostName", server.publicDns());
64+
}
65+
}

aws-java-webserver/settings.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rootProject.name = 'aws-java-webserver'
2+
include('app')

aws-native-java-s3-folder/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore Gradle project-specific cache directory
2+
.gradle
3+
4+
# Ignore Gradle build output directory
5+
build

aws-native-java-s3-folder/Pulumi.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: aws-java-s3-folder
2+
runtime: java
3+
description: A static website hosted on AWS S3

0 commit comments

Comments
 (0)