index.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import * as awsx from '@pulumi/awsx'
  2. import * as eks from '@pulumi/eks'
  3. import * as k8s from '@pulumi/kubernetes'
  4. import * as pulumi from '@pulumi/pulumi'
  5. const awsConfig = new pulumi.Config('aws')
  6. const config = new pulumi.Config()
  7. const wsProviderEndpointURI = config.require('wsProviderEndpointURI')
  8. const isProduction = config.require('isProduction') === 'true'
  9. // Create a VPC for our cluster.
  10. const vpc = new awsx.ec2.Vpc('vpc', { numberOfAvailabilityZones: 2 })
  11. // Create an EKS cluster with the default configuration.
  12. const cluster = new eks.Cluster('eksctl-my-cluster', {
  13. vpcId: vpc.id,
  14. subnetIds: vpc.publicSubnetIds,
  15. instanceType: 't2.micro',
  16. providerCredentialOpts: {
  17. profileName: awsConfig.get('profile'),
  18. },
  19. })
  20. // Export the cluster's kubeconfig.
  21. export const kubeconfig = cluster.kubeconfig
  22. // Create a repository
  23. const repo = new awsx.ecr.Repository('colossus-image')
  24. // Build an image and publish it to our ECR repository.
  25. export const colossusImage = repo.buildAndPushImage({
  26. dockerfile: '../../../colossus.Dockerfile',
  27. context: '../../../',
  28. })
  29. const name = 'storage-node'
  30. // Create a Kubernetes Namespace
  31. const ns = new k8s.core.v1.Namespace(name, {}, { provider: cluster.provider })
  32. // Export the Namespace name
  33. export const namespaceName = ns.metadata.name
  34. const appLabels = { appClass: name }
  35. // Create a LoadBalancer Service for the Deployment
  36. const service = new k8s.core.v1.Service(
  37. name,
  38. {
  39. metadata: {
  40. labels: appLabels,
  41. namespace: namespaceName,
  42. },
  43. spec: {
  44. type: 'LoadBalancer',
  45. ports: [{ name: 'port-1', port: 3001 }],
  46. selector: appLabels,
  47. },
  48. },
  49. {
  50. provider: cluster.provider,
  51. }
  52. )
  53. // Export the Service name and public LoadBalancer Endpoint
  54. export const serviceName = service.metadata.name
  55. // When "done", this will print the public IP.
  56. export let serviceHostname: pulumi.Output<string>
  57. serviceHostname = service.status.loadBalancer.ingress[0].hostname
  58. const publicUrlInput: pulumi.Input<string> = pulumi.interpolate`http://${serviceHostname}:${3001}/`
  59. let additionalParams: string[] | pulumi.Input<string>[] = []
  60. if (isProduction) {
  61. const providerId = config.require('providerId')
  62. const keyFile = config.require('keyFile')
  63. const publicUrl = config.get('publicURL') ? config.get('publicURL')! : publicUrlInput
  64. additionalParams = ['--provider-id', providerId, '--key-file', keyFile, '--public-url', publicUrl]
  65. const passphrase = config.get('passphrase')
  66. if (passphrase) {
  67. additionalParams.push('--passphrase', passphrase)
  68. }
  69. }
  70. // Create a Deployment
  71. const deployment = new k8s.apps.v1.Deployment(
  72. name,
  73. {
  74. metadata: {
  75. namespace: namespaceName,
  76. labels: appLabels,
  77. },
  78. spec: {
  79. replicas: 1,
  80. selector: { matchLabels: appLabels },
  81. template: {
  82. metadata: {
  83. labels: appLabels,
  84. },
  85. spec: {
  86. hostname: 'ipfs',
  87. containers: [
  88. {
  89. name: 'ipfs',
  90. image: 'ipfs/go-ipfs:latest',
  91. ports: [{ containerPort: 5001 }, { containerPort: 8080 }],
  92. command: ['/bin/sh', '-c'],
  93. args: [
  94. 'set -e; \
  95. /usr/local/bin/start_ipfs config profile apply lowpower; \
  96. /usr/local/bin/start_ipfs config --json Gateway.PublicGateways \'{"localhost": null }\'; \
  97. /sbin/tini -- /usr/local/bin/start_ipfs daemon --migrate=true',
  98. ],
  99. },
  100. {
  101. name: 'colossus',
  102. image: colossusImage,
  103. env: [
  104. {
  105. name: 'WS_PROVIDER_ENDPOINT_URI',
  106. // example 'wss://18.209.241.63.nip.io/'
  107. value: wsProviderEndpointURI,
  108. },
  109. {
  110. name: 'DEBUG',
  111. value: 'joystream:*',
  112. },
  113. ],
  114. command: [
  115. 'yarn',
  116. 'colossus',
  117. '--anonymous',
  118. '--ws-provider',
  119. wsProviderEndpointURI,
  120. '--ipfs-host',
  121. 'ipfs',
  122. ...additionalParams,
  123. ],
  124. ports: [{ containerPort: 3001 }],
  125. },
  126. ],
  127. },
  128. },
  129. },
  130. },
  131. {
  132. provider: cluster.provider,
  133. }
  134. )
  135. // Export the Deployment name
  136. export const deploymentName = deployment.metadata.name