-
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.
- Loading branch information
Nyakio Maina
authored and
Nyakio Maina
committed
Apr 28, 2024
1 parent
7338bcf
commit 3694a0b
Showing
13 changed files
with
6,838 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-14 | ||
|
||
# Install AWS CLI and Pulumi | ||
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \ | ||
unzip awscliv2.zip && \ | ||
./aws/install && \ | ||
curl -fsSL https://get.pulumi.com | sh | ||
|
||
# Install Docker CLI | ||
RUN apt-get update && \ | ||
apt-get install -y apt-transport-https docker-ce docker-ce-cli containerd.io | ||
|
||
# Set up your environment | ||
WORKDIR /workspace |
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,11 @@ | ||
{ | ||
"name": "AWS TypeScript Development Container", | ||
"build": { | ||
"dockerfile": "Dockerfile" | ||
}, | ||
"settings": {}, | ||
"extensions": ["dbaeumer.vscode-eslint"], | ||
"forwardPorts": [3000, 8080], | ||
"postCreateCommand": "npm install", | ||
"remoteUser": "node" | ||
} |
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 @@ | ||
/bin/ | ||
/node_modules/ |
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 @@ | ||
config: | ||
aws:region: us-east-1 |
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,7 @@ | ||
name: infra | ||
runtime: nodejs | ||
description: Deploy IPFS and Lambada on AWS | ||
config: | ||
pulumi:tags: | ||
value: | ||
pulumi:template: aws-typescript |
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,102 @@ | ||
import * as pulumi from "@pulumi/pulumi"; | ||
import * as aws from "@pulumi/aws"; | ||
import * as awsx from "@pulumi/awsx"; | ||
|
||
// S3 bucket | ||
const ipfsBucket = new aws.s3.Bucket("ipfsBucket", { | ||
bucketPrefix: "ipfs-data-" | ||
}); | ||
|
||
// ECS cluster | ||
const cluster = new aws.ecs.Cluster("cluster"); | ||
|
||
// IAM role | ||
const taskExecRole = new aws.iam.Role("taskExecRole", { | ||
assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({ | ||
Service: "ecs-tasks.amazonaws.com", | ||
}), | ||
}); | ||
|
||
new aws.iam.RolePolicyAttachment("taskExecPolicyAttachment", { | ||
role: taskExecRole, | ||
policyArn: aws.iam.ManagedPolicy.AWSLambdaBasicExecutionRole, | ||
}); | ||
|
||
// default VPC and its subnets | ||
const vpc = new awsx.ec2.Vpc.DefaultVpc("default-vpc"); | ||
|
||
// task definition for Kubo/IPFS | ||
const ipfsTask = new aws.ecs.TaskDefinition("ipfsTask", { | ||
family: "ipfs", | ||
cpu: "256", | ||
memory: "512", | ||
networkMode: "awsvpc", | ||
requiresCompatibilities: ["FARGATE"], | ||
executionRoleArn: taskExecRole.arn, | ||
containerDefinitions: pulumi.interpolate`[ | ||
{ | ||
"name": "ipfs", | ||
"image": "ipfs/go-ipfs:latest", | ||
"essential": true, | ||
"environment": [ | ||
{ "name": "IPFS_S3_BUCKET", "value": "${ipfsBucket.bucket}" } | ||
], | ||
"portMappings": [ | ||
{ "containerPort": 5001, "hostPort": 5001 } | ||
] | ||
} | ||
]`, | ||
}); | ||
|
||
// ECS Service for IPFS | ||
const ipfsService = new aws.ecs.Service("ipfsService", { | ||
cluster: cluster.arn, | ||
desiredCount: 1, | ||
launchType: "FARGATE", | ||
taskDefinition: ipfsTask.arn, | ||
networkConfiguration: { | ||
subnets: vpc.publicSubnets.map(subnet => subnet.id), | ||
securityGroups: [vpc.securityGroups[0].id], | ||
assignPublicIp: true, | ||
}, | ||
}); | ||
|
||
// Task definition for Lambada | ||
const lambadaTask = new aws.ecs.TaskDefinition("lambadaTask", { | ||
family: "lambada", | ||
cpu: "512", | ||
memory: "1024", | ||
networkMode: "awsvpc", | ||
requiresCompatibilities: ["FARGATE"], | ||
executionRoleArn: taskExecRole.arn, | ||
containerDefinitions: pulumi.interpolate`[ | ||
{ | ||
"name": "lambada", | ||
"image": "zippiehq/cartesi-lambada:latest", | ||
"essential": true, | ||
"environment": [ | ||
{ "name": "IPFS_NODE_URL", "value": "http://${ipfsService.cluster}.${aws.config.region}.amazonaws.com:5001" } | ||
], | ||
"portMappings": [ | ||
{ "containerPort": 80, "hostPort": 80 } | ||
] | ||
} | ||
]`, | ||
}); | ||
|
||
// ECS Service for Lambada | ||
const lambadaService = new aws.ecs.Service("lambadaService", { | ||
cluster: cluster.arn, | ||
desiredCount: 1, | ||
launchType: "FARGATE", | ||
taskDefinition: lambadaTask.arn, | ||
networkConfiguration: { | ||
subnets: vpc.publicSubnets.map(subnet => subnet.id), | ||
securityGroups: [vpc.securityGroups[0].id], | ||
assignPublicIp: true, | ||
}, | ||
}); | ||
|
||
// Export the URLs for accessing the services | ||
export const ipfsUrl = pulumi.interpolate`http://${ipfsService.cluster}.${aws.config.region}.amazonaws.com:5001`; | ||
export const lambadaUrl = pulumi.interpolate`http://${lambadaService.cluster}.${aws.config.region}.amazonaws.com:80`; |
Oops, something went wrong.