-
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 30, 2024
1 parent
7338bcf
commit 5c367b7
Showing
13 changed files
with
6,851 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,115 @@ | ||
import * as pulumi from "@pulumi/pulumi"; | ||
import * as aws from "@pulumi/aws"; | ||
import * as awsx from "@pulumi/awsx"; | ||
|
||
const localProvide = new aws.Provider("localProvide", { | ||
accessKey: "test", | ||
secretKey: "testsecret", | ||
region: "us-east-1", | ||
skipCredentialsValidation: true, | ||
skipMetadataApiCheck: true, | ||
skipRegionValidation: true, | ||
skipRequestingAccountId: true, | ||
s3UsePathStyle: true, | ||
endpoints: [ | ||
{ | ||
s3: "http://localhost:4566", | ||
ecs: "http://localhost:4566", | ||
ec2: "http://localhost:4566", | ||
iam: "http://localhost:4566" | ||
} | ||
], | ||
}) | ||
// S3 bucket | ||
const ipfsBucket = new aws.s3.Bucket("ipfsBucket", { | ||
bucketPrefix: "ipfs-data-" | ||
}, { provider: localProvide }); | ||
|
||
// ECS cluster | ||
const cluster = new aws.ecs.Cluster("cluster", {}, { provider: localProvide }); | ||
|
||
// IAM role | ||
const taskExecRole = new aws.iam.Role("taskExecRole", { | ||
assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({ Service: "ecs-tasks.amazonaws.com" }), | ||
}, { provider: localProvide }); | ||
|
||
new aws.iam.RolePolicyAttachment("taskExecPolicyAttachment", { | ||
role: taskExecRole, | ||
policyArn: aws.iam.ManagedPolicy.AmazonEC2ContainerServiceforEC2Role, | ||
}, { provider: localProvide }); | ||
|
||
// Kubo/IPFS task definition with S3 as datastore | ||
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.id}" } | ||
], | ||
"portMappings": [ | ||
{ "containerPort": 5001, "hostPort": 5001 } | ||
] | ||
} | ||
]`, | ||
}, { provider: localProvide }); | ||
|
||
// ECS Service for IPFS | ||
const ipfsService = new aws.ecs.Service("ipfsService", { | ||
cluster: cluster.arn, | ||
desiredCount: 1, | ||
launchType: "FARGATE", | ||
taskDefinition: ipfsTask.arn, | ||
networkConfiguration: { | ||
subnets: ["subnet-xxxx"], | ||
securityGroups: ["sg-xxxx"], | ||
assignPublicIp: true, | ||
}, | ||
}, { provider: localProvide }); | ||
|
||
// Lambada task definition | ||
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, | ||
"portMappings": [ | ||
{ "containerPort": 80, "hostPort": 80 } | ||
], | ||
"environment": [ | ||
{ "name": "IPFS_API_URL", "value": "http://${ipfsService.cluster}.${aws.config.region}.amazonaws.com:5001" } | ||
] | ||
} | ||
]`, | ||
}, { provider: localProvide }); | ||
|
||
// ECS Service for Lambada | ||
const lambadaService = new aws.ecs.Service("lambadaService", { | ||
cluster: cluster.arn, | ||
desiredCount: 1, | ||
launchType: "FARGATE", | ||
taskDefinition: lambadaTask.arn, | ||
networkConfiguration: { | ||
subnets: ["subnet-xxxx"], | ||
securityGroups: ["sg-xxxx"], | ||
assignPublicIp: true, | ||
}, | ||
}, { provider: localProvide }); | ||
|
||
// service URLs | ||
export const ipfsServiceUrl = pulumi.interpolate`http://${ipfsService.cluster}.${aws.config.region}.amazonaws.com:5001`; | ||
export const lambadaServiceUrl = pulumi.interpolate`http://${lambadaService.cluster}.${aws.config.region}.amazonaws.com:80`; |
Oops, something went wrong.