Created
April 5, 2019 22:55
-
-
Save timmyers/5e9bcd5716f0515fe17f1bb7fcb94083 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as fs from 'fs'; | |
| import * as path from 'path'; | |
| import * as pulumi from '@pulumi/pulumi'; | |
| import * as k8s from '@pulumi/kubernetes'; | |
| import { sha1hash } from '@pulumi/aws'; | |
| class K8SEthNode extends pulumi.ComponentResource { | |
| public constructor(name: string, settings: {}, opts?: pulumi.ComponentResourceOptions) { | |
| super('project:k8s-eth-node', name, { }, opts); | |
| const defaultOpts = { parent: this }; | |
| const namespace = 'project'; | |
| const entrypointString = fs.readFileSync(path.relative(process.cwd(), `${__dirname}/entrypoint.sh`)).toString(); | |
| const configMap = new k8s.core.v1.ConfigMap(name, { | |
| metadata: { | |
| name, | |
| namespace, | |
| }, | |
| data: { | |
| 'entrypoint.sh': entrypointString, | |
| }, | |
| }, defaultOpts); | |
| const statefulSet = new k8s.apps.v1.StatefulSet(name, { | |
| metadata: { | |
| name, | |
| namespace, | |
| }, | |
| spec: { | |
| selector: { | |
| matchLabels: { | |
| app: name, | |
| }, | |
| }, | |
| serviceName: name, | |
| replicas: 3, | |
| template: { | |
| metadata: { | |
| labels: { | |
| app: name, | |
| }, | |
| }, | |
| spec: { | |
| initContainers: [{ | |
| name: 'init-config', | |
| image: 'busybox:1.30', | |
| command: ['sh', '-c', | |
| 'chown -R root:root /parity && chmod -R 777 /parity', | |
| ], | |
| volumeMounts: [{ | |
| name: 'db', | |
| mountPath: '/parity', | |
| readOnly: false | |
| }], | |
| }], | |
| containers: [{ | |
| name: 'parity', | |
| image: 'parity/parity:nightly', | |
| command: ['/scripts/entrypoint.sh'], | |
| env: [{ | |
| name: 'NETWORK', | |
| value: network, | |
| }, { | |
| name: 'ENTRYPOINT_SHA', | |
| // value: sha1hash(entrypointString), | |
| value: configMap.data.apply(data => { | |
| const entrypoint = data['entrypoint.sh'] as unknown as string; | |
| return sha1hash(entrypoint); | |
| }), | |
| }], | |
| resources: { | |
| requests: { | |
| memory: '2Gi', | |
| cpu: '1' | |
| }, | |
| limits: { | |
| memory: '4Gi', | |
| cpu: '2', | |
| }, | |
| }, | |
| ports: [{ | |
| containerPort: 8545, | |
| protocol: 'TCP', | |
| }], | |
| volumeMounts: [{ | |
| name: 'db', | |
| mountPath: '/home/parity/.local/share/io.parity.ethereum/', | |
| readOnly: false | |
| }, { | |
| name: 'entrypoint', | |
| mountPath: '/scripts' | |
| }], | |
| livenessProbe: { | |
| initialDelaySeconds: 5, | |
| periodSeconds: 5, | |
| exec: { | |
| command: [ | |
| 'curl', | |
| 'localhost:8545', | |
| ] | |
| } | |
| }, | |
| readinessProbe: { | |
| initialDelaySeconds: 5, | |
| periodSeconds: 5, | |
| exec: { | |
| command: [ | |
| 'curl', | |
| 'localhost:8545', | |
| ] | |
| } | |
| } | |
| }], | |
| volumes: [{ | |
| name: 'entrypoint', | |
| configMap: { | |
| name: name, | |
| defaultMode: 0o777, | |
| }, | |
| }], | |
| }, | |
| }, | |
| volumeClaimTemplates: [{ | |
| metadata: { | |
| name: 'db', | |
| }, | |
| spec: { | |
| accessModes: [ 'ReadWriteOnce' ], | |
| resources: { | |
| requests: { | |
| storage: '20Gi' | |
| } | |
| }, | |
| storageClassName: 'gp2', | |
| } | |
| }], | |
| }, | |
| }, { | |
| ...defaultOpts, | |
| protect: false, | |
| }); | |
| } | |
| } | |
| export default K8SEthNode; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment