Skip to content

Commit

Permalink
initial commit: project setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyakio Maina authored and Nyakio Maina committed Apr 28, 2024
1 parent 7338bcf commit 3694a0b
Show file tree
Hide file tree
Showing 13 changed files with 6,838 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .devcontainer/Dockerfile
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
11 changes: 11 additions & 0 deletions .devcontainer/devcontainer.json
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"
}
2 changes: 2 additions & 0 deletions infra/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bin/
/node_modules/
2 changes: 2 additions & 0 deletions infra/Pulumi.dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config:
aws:region: us-east-1
7 changes: 7 additions & 0 deletions infra/Pulumi.yaml
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
102 changes: 102 additions & 0 deletions infra/index.ts
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`;
Loading

0 comments on commit 3694a0b

Please sign in to comment.