Преглед изворни кода

Add persistent storage, option to change port, change public url

Anuj Bansal пре 3 година
родитељ
комит
98b3c89ad6

+ 9 - 3
devops/infrastructure/storage-node/Pulumi.yaml

@@ -10,12 +10,18 @@ template:
     wsProviderEndpointURI:
       description: Chain RPC endpoint
       default: 'wss://rome-rpc-endpoint.joystream.org:9944/'
-    isProduction:
-      description: Whether you are deploying a production storage node
-      default: false
+    isAnonymous:
+      description: Whether you are deploying an anonymous storage node
+      default: true
     isLoadBalancerReady:
       description: Whether the load balancer service is ready and has been assigned an IP
       default: false
+    colossusPort:
+      description: Port that is exposed for the colossus container
+      default: 3000
+    storage:
+      description: Amount of storage in gigabytes for ipfs volume
+      default: 40
     providerId:
       description: StorageProviderId assigned to you in working group
     keyFile:

+ 4 - 2
devops/infrastructure/storage-node/README.md

@@ -39,17 +39,19 @@ After cloning this repo, from this working directory, run these commands:
    ```bash
    $ pulumi config set-all --plaintext aws:region=us-east-1 --plaintext aws:profile=joystream-user \
     --plaintext wsProviderEndpointURI='wss://rome-rpc-endpoint.joystream.org:9944/' \
-    --plaintext isProduction=false
+    --plaintext isAnonymous=true
    ```
 
    If running for production use the below mentioned config
 
    ```bash
    $ pulumi config set-all --plaintext aws:region=us-east-1 --plaintext aws:profile=joystream-user \
-    --plaintext wsProviderEndpointURI='wss://rome-rpc-endpoint.joystream.org:9944/' --plaintext isProduction=true \
+    --plaintext wsProviderEndpointURI='wss://rome-rpc-endpoint.joystream.org:9944/' --plaintext isAnonymous=false \
     --plaintext providerId=<ID> --plaintext keyFile=<PATH> --plaintext publicURL=<DOMAIN> --secret passphrase=<PASSPHRASE>
    ```
 
+   You can also set the `storage` and the `colossusPort` config parameters if required
+
 1. Stand up the EKS cluster:
 
    Running `pulumi up -y` will deploy the EKS cluster. Note, provisioning a

+ 76 - 47
devops/infrastructure/storage-node/index.ts

@@ -11,8 +11,16 @@ const awsConfig = new pulumi.Config('aws')
 const config = new pulumi.Config()
 
 const wsProviderEndpointURI = config.require('wsProviderEndpointURI')
-const isProduction = config.require('isProduction') === 'true'
+const isAnonymous = config.require('isAnonymous') === 'true'
 const lbReady = config.get('isLoadBalancerReady') === 'true'
+const name = 'storage-node'
+const colossusPort = parseInt(config.get('colossusPort') || '3000')
+const storage = parseInt(config.get('storage') || '40')
+
+let additionalParams: string[] | pulumi.Input<string>[] = []
+let volumeMounts: pulumi.Input<pulumi.Input<k8s.types.input.core.v1.VolumeMount>[]> = []
+let caddyVolumeMounts: pulumi.Input<pulumi.Input<k8s.types.input.core.v1.VolumeMount>[]> = []
+let volumes: pulumi.Input<pulumi.Input<k8s.types.input.core.v1.Volume>[]> = []
 
 // Create a VPC for our cluster.
 const vpc = new awsx.ec2.Vpc('vpc', { numberOfAvailabilityZones: 2 })
@@ -39,9 +47,6 @@ export const colossusImage = repo.buildAndPushImage({
   context: '../../../',
 })
 
-const name = 'storage-node'
-const colossusPort = 3001
-
 // Create a Kubernetes Namespace
 const ns = new k8s.core.v1.Namespace(name, {}, { provider: cluster.provider })
 
@@ -50,6 +55,29 @@ export const namespaceName = ns.metadata.name
 
 const appLabels = { appClass: name }
 
+const pvc = new k8s.core.v1.PersistentVolumeClaim(`${name}-pvc`, {
+  metadata: {
+    labels: appLabels,
+    namespace: namespaceName,
+    name: `${name}-pvc`,
+  },
+  spec: {
+    accessModes: ['ReadWriteOnce'],
+    resources: {
+      requests: {
+        storage: `${storage}Gi`,
+      },
+    },
+  },
+})
+
+volumes.push({
+  name: 'ipfs-data',
+  persistentVolumeClaim: {
+    claimName: `${name}-pvc`,
+  },
+})
+
 // Create a LoadBalancer Service for the Deployment
 const service = new k8s.core.v1.Service(
   name,
@@ -80,48 +108,6 @@ serviceHostname = service.status.loadBalancer.ingress[0].hostname
 
 export let appLink: pulumi.Output<string>
 
-const publicUrlInput: pulumi.Input<string> = pulumi.interpolate`http://${serviceHostname}/`
-
-let additionalParams: string[] | pulumi.Input<string>[] = []
-let volumeMounts: pulumi.Input<pulumi.Input<k8s.types.input.core.v1.VolumeMount>[]> = []
-let caddyVolumeMounts: pulumi.Input<pulumi.Input<k8s.types.input.core.v1.VolumeMount>[]> = []
-let volumes: pulumi.Input<pulumi.Input<k8s.types.input.core.v1.Volume>[]> = []
-
-if (isProduction) {
-  const remoteKeyFilePath = '/joystream/key-file.json'
-  const providerId = config.require('providerId')
-  const keyFile = config.require('keyFile')
-  const publicUrl = config.get('publicURL') ? config.get('publicURL')! : publicUrlInput
-
-  const keyConfig = new k8s.core.v1.ConfigMap(name, {
-    metadata: { namespace: namespaceName, labels: appLabels },
-    data: { 'fileData': fs.readFileSync(keyFile).toString() },
-  })
-  const keyConfigName = keyConfig.metadata.apply((m) => m.name)
-
-  additionalParams = ['--provider-id', providerId, '--key-file', remoteKeyFilePath, '--public-url', publicUrl]
-
-  volumeMounts.push({
-    mountPath: remoteKeyFilePath,
-    name: 'keyfile-volume',
-    subPath: 'fileData',
-  })
-
-  volumes.push({
-    name: 'keyfile-volume',
-    configMap: {
-      name: keyConfigName,
-    },
-  })
-
-  const passphrase = config.get('passphrase')
-  if (passphrase) {
-    additionalParams.push('--passphrase', passphrase)
-  }
-} else {
-  additionalParams.push('--anonymous')
-}
-
 if (lbReady) {
   async function lookupPromise(url: string) {
     return new Promise((resolve, reject) => {
@@ -159,9 +145,46 @@ if (lbReady) {
     },
   })
 
-  appLink = pulumi.interpolate`${lbIp}.nip.io`
+  appLink = pulumi.interpolate`https://${lbIp}.nip.io`
 
   lbIp.apply((value) => console.log(`You can now access the app at: ${value}.nip.io`))
+
+  if (!isAnonymous) {
+    const remoteKeyFilePath = '/joystream/key-file.json'
+    const providerId = config.require('providerId')
+    const keyFile = config.require('keyFile')
+    const publicUrl = config.get('publicURL') ? config.get('publicURL')! : appLink
+
+    const keyConfig = new k8s.core.v1.ConfigMap('key-config', {
+      metadata: { namespace: namespaceName, labels: appLabels },
+      data: { 'fileData': fs.readFileSync(keyFile).toString() },
+    })
+    const keyConfigName = keyConfig.metadata.apply((m) => m.name)
+
+    additionalParams = ['--provider-id', providerId, '--key-file', remoteKeyFilePath, '--public-url', publicUrl]
+
+    volumeMounts.push({
+      mountPath: remoteKeyFilePath,
+      name: 'keyfile-volume',
+      subPath: 'fileData',
+    })
+
+    volumes.push({
+      name: 'keyfile-volume',
+      configMap: {
+        name: keyConfigName,
+      },
+    })
+
+    const passphrase = config.get('passphrase')
+    if (passphrase) {
+      additionalParams.push('--passphrase', passphrase)
+    }
+  }
+}
+
+if (isAnonymous) {
+  additionalParams.push('--anonymous')
 }
 
 // Create a Deployment
@@ -194,6 +217,12 @@ const deployment = new k8s.apps.v1.Deployment(
                 /usr/local/bin/start_ipfs config Datastore.StorageMax 200GB; \
                 /sbin/tini -- /usr/local/bin/start_ipfs daemon --migrate=true',
               ],
+              volumeMounts: [
+                {
+                  name: 'ipfs-data',
+                  mountPath: '/data/ipfs',
+                },
+              ],
             },
             // {
             //   name: 'httpd',