|
@@ -3,6 +3,8 @@ import * as eks from '@pulumi/eks'
|
|
|
import * as pulumi from '@pulumi/pulumi'
|
|
|
import * as k8s from '@pulumi/kubernetes'
|
|
|
import { configMapFromFile } from './configMap'
|
|
|
+import { CaddyServiceDeployment } from './caddy'
|
|
|
+import { getSubkeyContainers, getValidatorContainers } from './utils'
|
|
|
|
|
|
const config = new pulumi.Config()
|
|
|
const awsConfig = new pulumi.Config('aws')
|
|
@@ -13,23 +15,12 @@ let provider: k8s.Provider
|
|
|
|
|
|
if (isMinikube) {
|
|
|
provider = new k8s.Provider('local', {})
|
|
|
-
|
|
|
- // Create image from local app
|
|
|
- // joystreamAppsImage = new docker.Image('joystream/apps', {
|
|
|
- // build: {
|
|
|
- // context: '../../../',
|
|
|
- // dockerfile: '../../../apps.Dockerfile',
|
|
|
- // },
|
|
|
- // imageName: 'joystream/apps:latest',
|
|
|
- // skipPush: true,
|
|
|
- // }).baseImageName
|
|
|
- // joystreamAppsImage = pulumi.interpolate`joystream/apps`
|
|
|
} else {
|
|
|
// Create a VPC for our cluster.
|
|
|
const vpc = new awsx.ec2.Vpc('joystream-node-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-node-network', {
|
|
|
vpcId: vpc.id,
|
|
|
subnetIds: vpc.publicSubnetIds,
|
|
|
desiredCapacity: 3,
|
|
@@ -69,8 +60,12 @@ const jsonModifyConfig = new configMapFromFile(
|
|
|
|
|
|
const dataPath = '/subkey-data'
|
|
|
const builderPath = '/builder-data'
|
|
|
-const networkPrefix = '8129'
|
|
|
+const networkSuffix = config.get('networkSuffix') || '8129'
|
|
|
const chainSpecPath = `${builderPath}/chainspec-raw.json`
|
|
|
+const numberOfValidators = config.getNumber('numberOfValidators') || 2
|
|
|
+
|
|
|
+const subkeyContainers = getSubkeyContainers(numberOfValidators, dataPath)
|
|
|
+const validatorContainers = getValidatorContainers(numberOfValidators, dataPath, builderPath, chainSpecPath)
|
|
|
|
|
|
const deployment = new k8s.apps.v1.Deployment(
|
|
|
name,
|
|
@@ -88,36 +83,15 @@ const deployment = new k8s.apps.v1.Deployment(
|
|
|
},
|
|
|
spec: {
|
|
|
initContainers: [
|
|
|
- {
|
|
|
- name: 'subkey-node',
|
|
|
- image: 'parity/subkey:latest',
|
|
|
- command: ['/bin/sh', '-c'],
|
|
|
- args: [`subkey generate-node-key >> ${dataPath}/privatekey1 2>> ${dataPath}/publickey1`],
|
|
|
- volumeMounts: [
|
|
|
- {
|
|
|
- name: 'subkey-data',
|
|
|
- mountPath: dataPath,
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'subkey-node-1',
|
|
|
- image: 'parity/subkey:latest',
|
|
|
- command: ['/bin/sh', '-c'],
|
|
|
- args: [`subkey generate-node-key >> ${dataPath}/privatekey2 2>> ${dataPath}/publickey2`],
|
|
|
- volumeMounts: [
|
|
|
- {
|
|
|
- name: 'subkey-data',
|
|
|
- mountPath: dataPath,
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
+ ...subkeyContainers,
|
|
|
{
|
|
|
name: 'builder-node',
|
|
|
image: 'joystream/node:latest',
|
|
|
command: ['/bin/sh', '-c'],
|
|
|
args: [
|
|
|
- `/joystream/chain-spec-builder generate -a 2 --chain-spec-path ${builderPath}/chainspec.json --deployment live --endowed 1 --keystore-path ${builderPath}/data >> ${builderPath}/seeds.txt`,
|
|
|
+ `/joystream/chain-spec-builder generate -a ${numberOfValidators} \
|
|
|
+ --chain-spec-path ${builderPath}/chainspec.json --deployment live \
|
|
|
+ --endowed 1 --keystore-path ${builderPath}/data >> ${builderPath}/seeds.txt`,
|
|
|
],
|
|
|
volumeMounts: [
|
|
|
{
|
|
@@ -130,7 +104,7 @@ const deployment = new k8s.apps.v1.Deployment(
|
|
|
name: 'json-modify',
|
|
|
image: 'python',
|
|
|
command: ['python'],
|
|
|
- args: ['/scripts/json_modify.py', '--path', `${builderPath}/chainspec.json`, '--prefix', networkPrefix],
|
|
|
+ args: ['/scripts/json_modify.py', '--path', `${builderPath}/chainspec.json`, '--prefix', networkSuffix],
|
|
|
volumeMounts: [
|
|
|
{
|
|
|
mountPath: '/scripts/json_modify.py',
|
|
@@ -161,62 +135,7 @@ const deployment = new k8s.apps.v1.Deployment(
|
|
|
},
|
|
|
],
|
|
|
containers: [
|
|
|
- {
|
|
|
- name: 'joystream-node',
|
|
|
- image: 'joystream/node:latest',
|
|
|
- ports: [{ containerPort: 9944 }, { containerPort: 9933 }],
|
|
|
- args: [
|
|
|
- '--chain',
|
|
|
- chainSpecPath,
|
|
|
- '--pruning',
|
|
|
- 'archive',
|
|
|
- '--node-key-file',
|
|
|
- `${dataPath}/privatekey1`,
|
|
|
- '--keystore-path',
|
|
|
- `${builderPath}/data/auth-0`,
|
|
|
- '--validator',
|
|
|
- '--log',
|
|
|
- 'runtime,txpool,transaction-pool,trace=sync',
|
|
|
- ],
|
|
|
- volumeMounts: [
|
|
|
- {
|
|
|
- name: 'subkey-data',
|
|
|
- mountPath: dataPath,
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'builder-data',
|
|
|
- mountPath: builderPath,
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'joystream-node-2',
|
|
|
- image: 'joystream/node:latest',
|
|
|
- ports: [{ containerPort: 9944 }, { containerPort: 9933 }],
|
|
|
- args: [
|
|
|
- '--chain',
|
|
|
- chainSpecPath,
|
|
|
- '--pruning',
|
|
|
- 'archive',
|
|
|
- '--node-key-file',
|
|
|
- `${dataPath}/privatekey2`,
|
|
|
- '--keystore-path',
|
|
|
- `${builderPath}/data/auth-1`,
|
|
|
- '--validator',
|
|
|
- '--log',
|
|
|
- 'runtime,txpool,transaction-pool,trace=sync',
|
|
|
- ],
|
|
|
- volumeMounts: [
|
|
|
- {
|
|
|
- name: 'subkey-data',
|
|
|
- mountPath: dataPath,
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'builder-data',
|
|
|
- mountPath: builderPath,
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
+ ...validatorContainers,
|
|
|
{
|
|
|
name: 'rpc-node',
|
|
|
image: 'joystream/node:latest',
|
|
@@ -281,9 +200,9 @@ const service = new k8s.core.v1.Service(
|
|
|
metadata: {
|
|
|
labels: appLabels,
|
|
|
namespace: namespaceName,
|
|
|
+ name: 'node-network',
|
|
|
},
|
|
|
spec: {
|
|
|
- type: 'NodePort',
|
|
|
ports: [
|
|
|
{ name: 'port-1', port: 9944 },
|
|
|
{ name: 'port-2', port: 9933 },
|
|
@@ -297,11 +216,12 @@ const service = new k8s.core.v1.Service(
|
|
|
// 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>
|
|
|
+const lbReady = config.get('isLoadBalancerReady') === 'true'
|
|
|
+const caddy = new CaddyServiceDeployment(
|
|
|
+ 'caddy-proxy',
|
|
|
+ { lbReady, namespaceName: namespaceName, isMinikube },
|
|
|
+ resourceOptions
|
|
|
+)
|
|
|
|
|
|
-if (isMinikube) {
|
|
|
- serviceHostname = service.spec.clusterIP
|
|
|
-} else {
|
|
|
- serviceHostname = service.status.loadBalancer.ingress[0].hostname
|
|
|
-}
|
|
|
+export const endpoint1 = caddy.primaryEndpoint
|
|
|
+export const endpoint2 = caddy.secondaryEndpoint
|