Browse Source

Add option to include production parameters to colossus

Anuj Bansal 3 years ago
parent
commit
470fe5be9f

+ 1 - 0
.dockerignore

@@ -6,3 +6,4 @@ query-node/**/dist
 query-node/lib
 cli/
 tests/
+devops/

+ 9 - 2
devops/infrastructure/kubernetes/Pulumi.dev.yaml

@@ -1,4 +1,11 @@
-encryptionsalt: v1:nPWInMpmigw=:v1:X1I9D4nnHSzvfEJ/:eVSSXQqisXdm5Lm09+phZ0eCviANrA==
+encryptionsalt: v1:kqdIgrY7tCI=:v1:rR0N31Qa+qhxZjqQ:Xlxmi2hMyUFDXZ/T9T5WddJPFZsMZA==
 config:
-  aws:region: us-east-1
   aws:profile: joystream-user
+  aws:region: us-east-1
+  eks-cluster:isProduction: 'true'
+  eks-cluster:keyFile: PATH
+  eks-cluster:passphrase:
+    secure: v1:Qxeuju3X9BgnL59p:/NH8z1BlrmJWLJX8oM6BoD1IxUb153+tQkQ=
+  eks-cluster:providerId: ID
+  eks-cluster:publicURL: DOMAIN
+  eks-cluster:wsProviderEndpointURI: wss://18.209.241.63.nip.io/

+ 16 - 1
devops/infrastructure/kubernetes/Pulumi.yaml

@@ -1,9 +1,24 @@
 name: eks-cluster
 runtime: nodejs
-description: A minimal AWS TypeScript Pulumi program
+description: A Pulumi program to deploy storage node to cloud environment
 template:
   config:
     aws:profile:
       default: joystream-user
     aws:region:
       default: us-east-1
+    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
+    providerId:
+      description: StorageProviderId assigned to you in working group
+    keyFile:
+      description: JSON key export file to use as the storage provider (role account)
+    publicURL:
+      description: API Public URL to announce
+    passphrase:
+      description: Optional passphrase to use to decrypt the key-file
+      secret: true

+ 16 - 3
devops/infrastructure/kubernetes/README.md

@@ -34,12 +34,19 @@ After cloning this repo, from this working directory, run these commands:
    $ pulumi stack init
    ```
 
-1. Set the required AWS configuration variables in `Pulumi.<stack>.yaml`
+1. Set the required configuration variables in `Pulumi.<stack>.yaml`
 
-1. Set `WS_PROVIDER_ENDPOINT_URI` environment variable.
+   ```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/'
+   ```
+
+   If running for production use the below mentioned config
 
    ```bash
-   $ export WS_PROVIDER_ENDPOINT_URI='wss://18.209.241.63.nip.io/'
+   $ 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 providerId=<ID> --plaintext keyFile=<PATH> --plaintext publicURL=<DOMAIN> --secret passphrase=<PASSPHRASE>
    ```
 
 1. Stand up the EKS cluster:
@@ -74,6 +81,12 @@ After cloning this repo, from this working directory, run these commands:
    $ kubectl logs <PODNAME> --all-containers
    ```
 
+   To run a command on a pod
+
+   ```bash
+   $ kubectl exec ${POD_NAME} -c ${CONTAINER_NAME} -- ${CMD} ${ARG1}
+   ```
+
    To see complete pulumi stack output
 
    ```bash

+ 50 - 30
devops/infrastructure/kubernetes/index.ts

@@ -4,6 +4,10 @@ import * as k8s from '@pulumi/kubernetes'
 import * as pulumi from '@pulumi/pulumi'
 
 const awsConfig = new pulumi.Config('aws')
+const config = new pulumi.Config()
+
+const wsProviderEndpointURI = config.require('wsProviderEndpointURI')
+const isProduction = config.require('isProduction') === 'true'
 
 // Create a VPC for our cluster.
 const vpc = new awsx.ec2.Vpc('vpc', { numberOfAvailabilityZones: 2 })
@@ -39,8 +43,50 @@ const ns = new k8s.core.v1.Namespace(name, {}, { provider: cluster.provider })
 // Export the Namespace name
 export const namespaceName = ns.metadata.name
 
-// Create a Deployment
 const appLabels = { appClass: name }
+
+// Create a LoadBalancer Service for the Deployment
+const service = new k8s.core.v1.Service(
+  name,
+  {
+    metadata: {
+      labels: appLabels,
+      namespace: namespaceName,
+    },
+    spec: {
+      type: 'LoadBalancer',
+      ports: [{ name: 'port-1', port: 3001 }],
+      selector: appLabels,
+    },
+  },
+  {
+    provider: cluster.provider,
+  }
+)
+
+// Export the Service name and public LoadBalancer Endpoint
+export const serviceName = service.metadata.name
+// When "done", this will print the public IP.
+export let serviceHostname: pulumi.Output<string>
+serviceHostname = service.status.loadBalancer.ingress[0].hostname
+const publicUrlInput: pulumi.Input<string> = pulumi.interpolate`http://${serviceHostname}:${3001}/`
+
+let additionalParams: string[] | pulumi.Input<string>[] = []
+
+if (isProduction) {
+  const providerId = config.require('providerId')
+  const keyFile = config.require('keyFile')
+  const publicUrl = config.get('publicURL') ? config.get('publicURL')! : publicUrlInput
+
+  additionalParams = ['--provider-id', providerId, '--key-file', keyFile, '--public-url', publicUrl]
+
+  const passphrase = config.get('passphrase')
+  if (passphrase) {
+    additionalParams.push('--passphrase', passphrase)
+  }
+}
+
+// Create a Deployment
 const deployment = new k8s.apps.v1.Deployment(
   name,
   {
@@ -77,7 +123,7 @@ const deployment = new k8s.apps.v1.Deployment(
                 {
                   name: 'WS_PROVIDER_ENDPOINT_URI',
                   // example 'wss://18.209.241.63.nip.io/'
-                  value: process.env.WS_PROVIDER_ENDPOINT_URI,
+                  value: wsProviderEndpointURI,
                 },
                 {
                   name: 'DEBUG',
@@ -89,9 +135,10 @@ const deployment = new k8s.apps.v1.Deployment(
                 'colossus',
                 '--anonymous',
                 '--ws-provider',
-                '$(WS_PROVIDER_ENDPOINT_URI)',
+                wsProviderEndpointURI,
                 '--ipfs-host',
                 'ipfs',
+                ...additionalParams,
               ],
               ports: [{ containerPort: 3001 }],
             },
@@ -107,30 +154,3 @@ const deployment = new k8s.apps.v1.Deployment(
 
 // Export the Deployment name
 export const deploymentName = deployment.metadata.name
-
-// Create a LoadBalancer Service for the Deployment
-const service = new k8s.core.v1.Service(
-  name,
-  {
-    metadata: {
-      labels: appLabels,
-      namespace: namespaceName,
-    },
-    spec: {
-      type: 'LoadBalancer',
-      ports: [{ name: 'port-1', port: 3001 }],
-      selector: appLabels,
-    },
-  },
-  {
-    provider: cluster.provider,
-  }
-)
-
-// Export the Service name and public LoadBalancer Endpoint
-export const serviceName = service.metadata.name
-
-// When "done", this will print the public IP.
-export let serviceHostname: pulumi.Output<string>
-
-serviceHostname = service.status.loadBalancer.ingress[0].hostname