index.ts 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. import * as awsx from '@pulumi/awsx'
  2. import * as eks from '@pulumi/eks'
  3. // import * as k8s from '@pulumi/kubernetes'
  4. import * as docker from '@pulumi/docker'
  5. import * as pulumi from '@pulumi/pulumi'
  6. import * as k8sjs from './k8sjs'
  7. import * as k8s from '@pulumi/kubernetes'
  8. require('dotenv').config()
  9. // const awsConfig = new pulumi.Config('aws')
  10. // // Create a VPC for our cluster.
  11. // const vpc = new awsx.ec2.Vpc('vpc', { numberOfAvailabilityZones: 2 })
  12. // // Create an EKS cluster with the default configuration.
  13. // const cluster = new eks.Cluster('eksctl-my-cluster', {
  14. // vpcId: vpc.id,
  15. // subnetIds: vpc.publicSubnetIds,
  16. // instanceType: 't2.large',
  17. // providerCredentialOpts: {
  18. // profileName: awsConfig.get('profile'),
  19. // },
  20. // })
  21. // // Export the cluster's kubeconfig.
  22. // export const kubeconfig = cluster.kubeconfig
  23. // // Create a repository
  24. // const repo = new awsx.ecr.Repository('joystream/apps')
  25. // export const joystreamAppsImage = repo.buildAndPushImage({
  26. // dockerfile: '../../../apps.Dockerfile',
  27. // context: '../../../',
  28. // })
  29. // Create image from local app
  30. // export const joystreamAppsImage = new docker.Image('joystream/apps', {
  31. // build: {
  32. // context: '../../../',
  33. // dockerfile: '../../../apps.Dockerfile',
  34. // },
  35. // imageName: 'joystream/apps:latest',
  36. // skipPush: true,
  37. // localImageName: 'joystream/apps:latest',
  38. // }).imageName
  39. export const joystreamAppsImage = 'joystream/apps'
  40. const name = 'query-node'
  41. // Create a Kubernetes Namespace
  42. // const ns = new k8s.core.v1.Namespace(name, {}, { provider: cluster.provider })
  43. const ns = new k8s.core.v1.Namespace(name, {})
  44. // Export the Namespace name
  45. export const namespaceName = ns.metadata.name
  46. // Create a NGINX Deployment
  47. const appLabels = { appClass: name }
  48. const deployment = new k8s.apps.v1.Deployment(
  49. name,
  50. {
  51. metadata: {
  52. namespace: namespaceName,
  53. labels: appLabels,
  54. },
  55. spec: {
  56. replicas: 1,
  57. selector: { matchLabels: appLabels },
  58. template: {
  59. metadata: {
  60. labels: appLabels,
  61. },
  62. spec: {
  63. hostname: 'postgres-db',
  64. containers: [
  65. {
  66. name: 'redis',
  67. image: 'redis:6.0-alpine',
  68. ports: [{ containerPort: 6379 }],
  69. },
  70. {
  71. name: 'postgres-db',
  72. image: 'postgres:12',
  73. env: [
  74. { name: 'POSTGRES_USER', value: process.env.DB_USER! },
  75. { name: 'POSTGRES_PASSWORD', value: process.env.DB_PASS! },
  76. { name: 'POSTGRES_DB', value: process.env.INDEXER_DB_NAME! },
  77. ],
  78. ports: [{ containerPort: 5432 }],
  79. },
  80. {
  81. name: 'temp-db-prepare-container',
  82. image: joystreamAppsImage,
  83. imagePullPolicy: 'Never',
  84. env: [
  85. {
  86. name: 'DB_HOST',
  87. value: 'postgres-db',
  88. },
  89. ],
  90. command: ['/bin/sh', '-c'],
  91. args: ['yarn workspace query-node-root db:prepare; yarn workspace query-node-root db:migrate'],
  92. },
  93. // {
  94. // name: 'indexer',
  95. // image: 'joystream/hydra-indexer:2.1.0-beta.9',
  96. // env: [
  97. // { name: 'DB_HOST', value: 'postgres-db' },
  98. // { name: 'DB_NAME', value: process.env.INDEXER_DB_NAME! },
  99. // { name: 'INDEXER_WORKERS', value: '5' },
  100. // { name: 'REDIS_URI', value: 'redis://redis:6379/0' },
  101. // { name: 'DEBUG', value: 'index-builder:*' },
  102. // { name: 'WS_PROVIDER_ENDPOINT_URI', value: process.env.WS_PROVIDER_ENDPOINT_URI! },
  103. // { name: 'TYPES_JSON', value: 'types.json' },
  104. // ],
  105. // // volumeMounts: [
  106. // // {
  107. // // mountPath: '/home/hydra/packages/hydra-indexer/types.json',
  108. // // name: 'indexer-volume',
  109. // // },
  110. // // ],
  111. // command: ['sh', '-c', 'yarn db:bootstrap && yarn start:prod'],
  112. // },
  113. // {
  114. // name: 'hydra-indexer-gateway',
  115. // image: 'joystream/hydra-indexer-gateway:2.1.0-beta.5',
  116. // env: [
  117. // { name: 'WARTHOG_STARTER_DB_DATABASE', value: process.env.INDEXER_DB_NAME! },
  118. // { name: 'WARTHOG_STARTER_DB_HOST', value: 'postgres-db' },
  119. // { name: 'WARTHOG_STARTER_DB_PASSWORD', value: process.env.DB_PASS! },
  120. // { name: 'WARTHOG_STARTER_DB_PORT', value: process.env.DB_PORT! },
  121. // { name: 'WARTHOG_STARTER_DB_USERNAME', value: process.env.DB_USER! },
  122. // { name: 'WARTHOG_STARTER_REDIS_URI', value: 'redis://redis:6379/0' },
  123. // { name: 'WARTHOG_APP_PORT', value: process.env.WARTHOG_APP_PORT! },
  124. // { name: 'PORT', value: process.env.WARTHOG_APP_PORT! },
  125. // { name: 'DEBUG', value: '*' },
  126. // ],
  127. // ports: [{ containerPort: 4002 }],
  128. // },
  129. // {
  130. // name: 'processor',
  131. // image: joystreamAppsImage,
  132. // imagePullPolicy: 'Never',
  133. // env: [
  134. // {
  135. // name: 'INDEXER_ENDPOINT_URL',
  136. // value: `http://hydra-indexer-gateway:${process.env.WARTHOG_APP_PORT}/graphql`,
  137. // },
  138. // { name: 'TYPEORM_HOST', value: 'postgres-db' },
  139. // { name: 'TYPEORM_DATABASE', value: process.env.DB_NAME! },
  140. // { name: 'DEBUG', value: 'index-builder:*' },
  141. // { name: 'PROCESSOR_POLL_INTERVAL', value: '1000' },
  142. // ],
  143. // // volumeMounts: [
  144. // // {
  145. // // mountPath: '/joystream/query-node/mappings/lib/generated/types/typedefs.json',
  146. // // name: 'processor-volume',
  147. // // },
  148. // // ],
  149. // command: ['yarn', 'workspace', 'query-node-root', 'processor:start'],
  150. // },
  151. // {
  152. // name: 'graphql-server',
  153. // image: joystreamAppsImage,
  154. // imagePullPolicy: 'Never',
  155. // env: [
  156. // { name: 'DB_HOST', value: 'postgres-db' },
  157. // { name: 'DB_NAME', value: process.env.DB_NAME! },
  158. // ],
  159. // ports: [{ name: 'graph-ql-port', containerPort: Number(process.env.GRAPHQL_SERVER_PORT!) }],
  160. // command: ['yarn', 'workspace', 'query-node-root', 'query-node:start:prod'],
  161. // },
  162. ],
  163. // volumes: [
  164. // {
  165. // name: 'processor-volume',
  166. // hostPath: {
  167. // path: '/Users/anuj/Joystream/joystream/types/augment/all/defs.json',
  168. // type: 'FileOrCreate',
  169. // },
  170. // },
  171. // {
  172. // name: 'indexer-volume',
  173. // hostPath: {
  174. // path: '/Users/anuj/Joystream/joystream/types/augment/all/defs.json',
  175. // type: 'FileOrCreate',
  176. // },
  177. // },
  178. // ],
  179. },
  180. },
  181. },
  182. }
  183. // {
  184. // provider: cluster.provider,
  185. // }
  186. )
  187. // Export the Deployment name
  188. export const deploymentName = deployment.metadata.name
  189. // Create a LoadBalancer Service for the NGINX Deployment
  190. const service = new k8s.core.v1.Service(
  191. name,
  192. {
  193. metadata: {
  194. labels: appLabels,
  195. namespace: namespaceName,
  196. },
  197. spec: {
  198. type: 'NodePort',
  199. ports: [
  200. { name: 'port-1', port: 8081, targetPort: 'graph-ql-port' },
  201. { name: 'port-2', port: 4000, targetPort: 4002 },
  202. ],
  203. selector: appLabels,
  204. },
  205. }
  206. // {
  207. // provider: cluster.provider,
  208. // }
  209. )
  210. // Export the Service name and public LoadBalancer Endpoint
  211. export const serviceName = service.metadata.name
  212. // When "done", this will print the public IP.
  213. export let serviceHostname: pulumi.Output<string>
  214. serviceHostname = service.status.loadBalancer.ingress[0].hostname