Kaynağa Gözat

Add colossus to kubernetes cluster

Anuj Bansal 3 yıl önce
ebeveyn
işleme
55eb0d7ae5

+ 18 - 0
colossus.Dockerfile

@@ -0,0 +1,18 @@
+FROM --platform=linux/x86-64 node:14 as builder
+
+WORKDIR /joystream
+COPY . /joystream
+RUN  rm -fr /joystream/pioneer
+
+EXPOSE 3001
+
+RUN yarn --frozen-lockfile
+
+RUN yarn workspace @joystream/types build
+RUN yarn workspace storage-node build
+
+# ENV WS_PROVIDER_ENDPOINT_URI=ws://host.docker.internal:9944/
+
+RUN yarn
+
+ENTRYPOINT yarn colossus --dev --ws-provider $WS_PROVIDER_ENDPOINT_URI

+ 6 - 0
devops/infrastructure/kubernetes/Pulumi.yaml

@@ -1,3 +1,9 @@
 name: eks-cluster
 runtime: nodejs
 description: A minimal AWS TypeScript Pulumi program
+template:
+  config:
+    aws:profile:
+      default: joystream-user
+    aws:region:
+      default: us-east-1

+ 59 - 26
devops/infrastructure/kubernetes/index.ts

@@ -1,42 +1,48 @@
-import * as awsx from "@pulumi/awsx";
-import * as eks from "@pulumi/eks";
-import * as k8s from "@pulumi/kubernetes";
+import * as awsx from '@pulumi/awsx'
+import * as eks from '@pulumi/eks'
+import * as k8s from '@pulumi/kubernetes'
+import * as pulumi from '@pulumi/pulumi'
 
-// kubeConfigOpts = eks.KubeconfigOptions;
+const awsConfig = new pulumi.Config('aws')
 
 // Create a VPC for our cluster.
-const vpc = new awsx.ec2.Vpc("vpc", { numberOfAvailabilityZones: 2 });
+const vpc = new awsx.ec2.Vpc('vpc', { numberOfAvailabilityZones: 2 })
 
 // Create an EKS cluster with the default configuration.
-const cluster = new eks.Cluster("eksctl-my-cluster", {
+const cluster = new eks.Cluster('eksctl-my-cluster', {
   vpcId: vpc.id,
   subnetIds: vpc.publicSubnetIds,
-  instanceType: "t2.micro",
+  instanceType: 't2.micro',
   providerCredentialOpts: {
-    profileName: "joystream-user",
+    profileName: awsConfig.get('profile'),
   },
-});
+})
 
 // Export the cluster's kubeconfig.
-export const kubeconfig = cluster.kubeconfig;
+export const kubeconfig = cluster.kubeconfig
 
 // Create a repository
-const repo = new awsx.ecr.Repository("my-repo");
+const repo = new awsx.ecr.Repository('my-repo')
 
 // Build an image from the "./app" directory
 // and publish it to our ECR repository.
-export const image = repo.buildAndPushImage("./app");
+export const ipfsImage = repo.buildAndPushImage('./app')
 
-const name = "ipfsworld";
+export const colossusImage = repo.buildAndPushImage({
+  dockerfile: '../../../colossus.Dockerfile',
+  context: '../../../',
+})
+
+const name = 'storage-node'
 
 // Create a Kubernetes Namespace
-const ns = new k8s.core.v1.Namespace(name, {}, { provider: cluster.provider });
+const ns = new k8s.core.v1.Namespace(name, {}, { provider: cluster.provider })
 
 // Export the Namespace name
-export const namespaceName = ns.metadata.name;
+export const namespaceName = ns.metadata.name
 
 // Create a NGINX Deployment
-const appLabels = { appClass: name };
+const appLabels = { appClass: name }
 const deployment = new k8s.apps.v1.Deployment(
   name,
   {
@@ -54,10 +60,34 @@ const deployment = new k8s.apps.v1.Deployment(
         spec: {
           containers: [
             {
-              name: name,
-              image: image,
+              name: 'ipfs',
+              image: ipfsImage,
               ports: [{ containerPort: 5001 }, { containerPort: 8080 }],
             },
+            {
+              name: 'colossus',
+              image: colossusImage,
+              env: [
+                {
+                  name: 'WS_PROVIDER_ENDPOINT_URI',
+                  value: 'wss://18.209.241.63.nip.io/',
+                },
+                {
+                  name: 'DEBUG',
+                  value: '*',
+                },
+              ],
+              command: [
+                'yarn',
+                'colossus',
+                '--dev',
+                '--ws-provider',
+                '$(WS_PROVIDER_ENDPOINT_URI)',
+                '--ipfs-host',
+                'ipfs',
+              ],
+              ports: [{ containerPort: 3001 }],
+            },
           ],
         },
       },
@@ -66,10 +96,10 @@ const deployment = new k8s.apps.v1.Deployment(
   {
     provider: cluster.provider,
   }
-);
+)
 
 // Export the Deployment name
-export const deploymentName = deployment.metadata.name;
+export const deploymentName = deployment.metadata.name
 
 // Create a LoadBalancer Service for the NGINX Deployment
 const service = new k8s.core.v1.Service(
@@ -80,10 +110,11 @@ const service = new k8s.core.v1.Service(
       namespace: namespaceName,
     },
     spec: {
-      type: "LoadBalancer",
+      type: 'LoadBalancer',
       ports: [
-        { name: "port-1", port: 5001 },
-        { name: "port-2", port: 8080 },
+        { name: 'port-1', port: 5001 },
+        { name: 'port-2', port: 8080 },
+        { name: 'port-3', port: 3001 },
       ],
       selector: appLabels,
     },
@@ -91,8 +122,10 @@ const service = new k8s.core.v1.Service(
   {
     provider: cluster.provider,
   }
-);
+)
 
 // Export the Service name and public LoadBalancer Endpoint
-export const serviceName = service.metadata.name;
-export const serviceHostname = service.status.loadBalancer.ingress[0].hostname;
+export const serviceName = service.metadata.name
+export const serviceHostname = service.status.loadBalancer.ingress[0].hostname
+
+console.log(serviceHostname)