Skip to content

Commit

Permalink
Merge pull request #5 from ralph-pichler/geth-swap
Browse files Browse the repository at this point in the history
add a chart for single-node PoA geth with swap contract deployment
  • Loading branch information
Svetomir Smiljkovic authored Feb 18, 2020
2 parents 2cda572 + cd90486 commit 3dd9ae8
Show file tree
Hide file tree
Showing 11 changed files with 428 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/geth-swap/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
26 changes: 26 additions & 0 deletions charts/geth-swap/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: v1
name: geth-swap
description: A Helm chart for Kubernetes
home: https://swarm.ethereum.org

maintainers:
- name: ralph-pichler
email: [email protected]

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
version: 0.1.3

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application.
appVersion: 1.16.0
63 changes: 63 additions & 0 deletions charts/geth-swap/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "geth-swap.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "geth-swap.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "geth-swap.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "geth-swap.labels" -}}
helm.sh/chart: {{ include "geth-swap.chart" . }}
{{ include "geth-swap.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

{{/*
Selector labels
*/}}
{{- define "geth-swap.selectorLabels" -}}
app.kubernetes.io/name: {{ include "geth-swap.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

{{/*
Create the name of the service account to use
*/}}
{{- define "geth-swap.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "geth-swap.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
87 changes: 87 additions & 0 deletions charts/geth-swap/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "geth-swap.fullname" . }}
labels:
{{- include "geth-swap.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "geth-swap.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "geth-swap.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "geth-swap.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
volumes:
- name: geth-config
configMap:
name: {{ include "geth-swap.fullname" . }}-config
- name: datadir
emptyDir: {}
initContainers:
- name: geth-setup
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- sh
- -ac
- >
set -xe;
geth account import --password /dev/null /etc/config/validatorKey;
geth init /etc/config/genesis.json;
volumeMounts:
- name: geth-config
mountPath: /etc/config
- name: datadir
mountPath: /root/.ethereum
containers:
- name: geth
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: rpc
containerPort: 8545
protocol: TCP
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
- name: geth-config
mountPath: /etc/config
- name: datadir
mountPath: /root/.ethereum
command:
- geth
- --rpc
- --rpcaddr
- "0.0.0.0"
- --rpcvhosts
- "*"
- --allow-insecure-unlock
- --unlock
- {{ .Values.geth.genesis.validatorAddress }}
- --password
- /dev/null
- --mine
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
48 changes: 48 additions & 0 deletions charts/geth-swap/templates/genesis.configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "geth-swap.fullname" . }}-config
data:
networkid: {{ .Values.geth.genesis.networkid | quote }}
validatorKey: {{ .Values.geth.genesis.validatorKey | quote }}
genesis.json: |-
{
"config": {
"chainId": {{ .Values.geth.genesis.networkid }},
"homesteadBlock": 0,
"eip150Block": 0,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"clique": {
"period": {{ .Values.geth.genesis.clique.period }},
"epoch": {{ .Values.geth.genesis.clique.epoch }}
}
},
"nonce": "0x0",
"timestamp": "0x5e4bc3a6",
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000{{ .Values.geth.genesis.validatorAddress }}0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x47b760",
"difficulty": "0x1",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": {
{{- range $i := until 256 }}
{{ $i | printf "%040x" | quote }}: {
"balance": "0x1"
},
{{- end}}
{{- range $i, $account := .Values.geth.genesis.accounts }}
{{if $i}},{{end}}{{ $account.addr | quote }}: {
"balance": {{ $account.wei | quote }}
}
{{- end }}
},
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
41 changes: 41 additions & 0 deletions charts/geth-swap/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "geth-swap.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "geth-swap.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ . }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
15 changes: 15 additions & 0 deletions charts/geth-swap/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "geth-swap.fullname" . }}
labels:
{{- include "geth-swap.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: rpc
protocol: TCP
name: rpc
selector:
{{- include "geth-swap.selectorLabels" . | nindent 4 }}
12 changes: 12 additions & 0 deletions charts/geth-swap/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "geth-swap.serviceAccountName" . }}
labels:
{{- include "geth-swap.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end -}}
27 changes: 27 additions & 0 deletions charts/geth-swap/templates/setupcontracts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "geth-swap.fullname" . }}-setupcontracts
labels:
{{- include "geth-swap.labels" . | nindent 4 }}
spec:
template:
spec:
containers:
- name: setup
image: bash:3.2
env:
- name: BACKEND
value: "http://{{ include "geth-swap.fullname" . }}:8545"
- name: BZZACCOUNTS
value: {{ .Values.swap.bzzaccounts | join " " }}
command:
- sh
- -ac
- >
apk add --no-cache jq curl;
curl https://gist.githubusercontent.com/ralph-pichler/dc0386f81ffa09c220271d4389b4a139/raw -o deploy.sh;
while curl $BACKEND; do sleep 1; done;
bash deploy.sh
restartPolicy: Never
backoffLimit: 1
15 changes: 15 additions & 0 deletions charts/geth-swap/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "geth-swap.fullname" . }}-test-connection"
labels:
{{- include "geth-swap.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test-success
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "geth-swap.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
Loading

0 comments on commit 3dd9ae8

Please sign in to comment.