Skip to content

Commit

Permalink
fixes, using localstack
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyakio Maina authored and Nyakio Maina committed Apr 30, 2024
1 parent 3694a0b commit 73f8fb1
Showing 1 changed file with 41 additions and 28 deletions.
69 changes: 41 additions & 28 deletions infra/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,43 @@ 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");
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",
}),
});
assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({ Service: "ecs-tasks.amazonaws.com" }),
}, { provider: localProvide });

new aws.iam.RolePolicyAttachment("taskExecPolicyAttachment", {
role: taskExecRole,
policyArn: aws.iam.ManagedPolicy.AWSLambdaBasicExecutionRole,
});
policyArn: aws.iam.ManagedPolicy.AmazonEC2ContainerServiceforEC2Role,
}, { provider: localProvide });

// default VPC and its subnets
const vpc = new awsx.ec2.Vpc.DefaultVpc("default-vpc");

// task definition for Kubo/IPFS
// Kubo/IPFS task definition with S3 as datastore
const ipfsTask = new aws.ecs.TaskDefinition("ipfsTask", {
family: "ipfs",
cpu: "256",
Expand All @@ -39,14 +52,14 @@ const ipfsTask = new aws.ecs.TaskDefinition("ipfsTask", {
"image": "ipfs/go-ipfs:latest",
"essential": true,
"environment": [
{ "name": "IPFS_S3_BUCKET", "value": "${ipfsBucket.bucket}" }
{ "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", {
Expand All @@ -55,13 +68,13 @@ const ipfsService = new aws.ecs.Service("ipfsService", {
launchType: "FARGATE",
taskDefinition: ipfsTask.arn,
networkConfiguration: {
subnets: vpc.publicSubnets.map(subnet => subnet.id),
securityGroups: [vpc.securityGroups[0].id],
subnets: ["subnet-xxxx"],
securityGroups: ["sg-xxxx"],
assignPublicIp: true,
},
});
}, { provider: localProvide });

// Task definition for Lambada
// Lambada task definition
const lambadaTask = new aws.ecs.TaskDefinition("lambadaTask", {
family: "lambada",
cpu: "512",
Expand All @@ -74,15 +87,15 @@ const lambadaTask = new aws.ecs.TaskDefinition("lambadaTask", {
"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 }
],
"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", {
Expand All @@ -91,12 +104,12 @@ const lambadaService = new aws.ecs.Service("lambadaService", {
launchType: "FARGATE",
taskDefinition: lambadaTask.arn,
networkConfiguration: {
subnets: vpc.publicSubnets.map(subnet => subnet.id),
securityGroups: [vpc.securityGroups[0].id],
subnets: ["subnet-xxxx"],
securityGroups: ["sg-xxxx"],
assignPublicIp: true,
},
});
}, { provider: localProvide });

// 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`;
// 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`;

0 comments on commit 73f8fb1

Please sign in to comment.