Skip to content

Commit

Permalink
test: use helm
Browse files Browse the repository at this point in the history
  • Loading branch information
RoRu committed Aug 25, 2022
1 parent 5fcb2af commit c0a4d17
Show file tree
Hide file tree
Showing 12 changed files with 489 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
IMAGE: ${{ needs.build.outputs.image_name }}
COMMIT_SHA: "${{ github.sha }}"
NAMESPACE: cache-${{ matrix.CHAIN_ID }}
ENV_NAME: production
ENV_NAME: 'cache-production-${{ matrix.CHAIN_ID }}'
run: |
cd k8s/
kubectl config set-context --current --namespace=${{ env.NAMESPACE }}
Expand Down
42 changes: 22 additions & 20 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,47 +33,49 @@ jobs:
environment: preview
needs: build
container:
image: qwolphin/kdsl:1.21.8
image: ghcr.io/helmfile/helmfile-ubuntu:v0.145.3
strategy:
fail-fast: false
matrix:
CHAIN_ID: ["1", "137", "43114"]
steps:
- uses: actions/checkout@v2

- name: 'Debug: check user'
shell: bash
run: |
id
which helm
ls -la /root/.local/share/helm/plugins/
helm plugin list
- name: Set k8s namespace
shell: bash
run: |
echo -e "NAMESPACE=cache-${NS_SUFFIX,,}\nENV_NAME=${{ github.head_ref }}" | tr -c '[:alnum:]-=\n_' '-' >> ${GITHUB_ENV}
cat <<EOF | tr -c '[:alnum:]-=\n_' '-' >> ${GITHUB_ENV}
NAMESPACE=cache-${NS_SUFFIX,,}
ENV_NAME=${{ github.head_ref }}
env:
NS_SUFFIX: "${{ github.head_ref }}-${{ matrix.CHAIN_ID }}"

- name: Render kdsl resources into yaml
env:
MAINNET_RPC: "${{ secrets.MAINNET_RPC }}"
POLYGON_RPC: "${{ secrets.POLYGON_RPC }}"
RECIPE: "chain${{ matrix.CHAIN_ID }}"
DOMAIN: "${{ env.NAMESPACE }}.aaw.fi"
CHAIN_ID: "${{ matrix.CHAIN_ID }}"
IMAGE: "${{ needs.build.outputs.image_name }}"
COMMIT_SHA: "${{ github.sha }}"
run: |
cd k8s/
python3 main.py > ../rendered.yml
- name: Set up kubeconfig
run: |
mkdir -p ~/.kube
echo "${{ secrets.DEV_KUBECONFIG }}" > ~/.kube/config
kubectl config set-context --current --namespace="${{ env.NAMESPACE }}"
- name: Apply k8s resources
shell: bash
env:
MAINNET_RPC: "${{ secrets.MAINNET_RPC }}"
POLYGON_RPC: "${{ secrets.POLYGON_RPC }}"
DOMAIN: "${{ env.NAMESPACE }}.aaw.fi"
CHAIN_ID: "${{ matrix.CHAIN_ID }}"
IMAGE: "${{ needs.build.outputs.image_name }}"
COMMIT_SHA: "${{ github.sha }}"
run: |
kubectl apply -f rendered.yml
sleep 3
kubectl wait --for condition=ready --timeout 90s pods -l "commit_sha=${{ github.sha }}" || \
{ kubectl get pods && exit 1; }
helmfile apply --suppress-diff || \
{ helmfile template | kubectl -n '${{ env.NAMESPACE }}' delete -f- && \
helmfile apply --suppress-diff; }
- uses: actions/github-script@v5
if: ${{ github.event.action == 'opened' || github.event.action == 'reopened' }}
Expand Down
23 changes: 23 additions & 0 deletions helm/chart/.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/
18 changes: 18 additions & 0 deletions helm/chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v2
name: aave-caching-server
description: A Helm chart for Kubernetes

# 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.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0
56 changes: 56 additions & 0 deletions helm/chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "chart.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 "chart.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 "chart.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{- define "common.env" -}}
{{- with .Values.common.env }}
{{ toYaml . }}
{{- end }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "common.labels" -}}
{{- with .Values.common.labels }}
{{- toYaml . }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Common annotations
*/}}
{{- define "common.annotations" -}}
{{- with .Values.common.annotations }}
{{- toYaml . }}
{{- end }}
{{- end }}
87 changes: 87 additions & 0 deletions helm/chart/templates/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: api
labels:
{{- include "common.labels" . | nindent 4 }}
component: api
annotations:
{{- include "common.annotations" . | nindent 4 }}
spec:
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
replicas: 1
selector:
matchLabels:
component: api
template:
metadata:
annotations:
{{- with .Values.api.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- include "common.annotations" . | nindent 8 }}
labels:
{{- include "common.labels" . | nindent 8 }}
component: api
spec:
automountServiceAccountToken: false
enableServiceLinks: false
containers:
- name: api
env:
- name: REDIS_HOST
value: redis
{{- include "common.env" . | nindent 12 }}
image: "{{ .Values.common.image }}"
imagePullPolicy: Always
ports:
- name: http
containerPort: 3000
protocol: TCP
livenessProbe:
httpGet:
path: '/.well-known/apollo/server-health'
port: http
initialDelaySeconds: 5
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 3
failureThreshold: 5
readinessProbe:
httpGet:
path: '/.well-known/apollo/server-health'
port: http
initialDelaySeconds: 5
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 3
failureThreshold: 5
resources:
{{- toYaml .Values.api.resources | nindent 12 }}
securityContext:
capabilities:
drop:
- ALL
---
apiVersion: v1
kind: Service
metadata:
name: api
labels:
{{- include "common.labels" . | nindent 4 }}
component: api
annotations:
{{- include "common.annotations" . | nindent 4 }}
spec:
type: ClusterIP
ports:
- port: 3000
targetPort: http
protocol: TCP
name: http-3000
selector:
component: api
27 changes: 27 additions & 0 deletions helm/chart/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: main
labels:
{{- include "common.labels" . | nindent 4 }}
annotations:
{{- with .Values.ingress.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- include "common.annotations" . | nindent 4 }}
spec:
ingressClassName: nginx
tls:
- hosts:
- {{ .Values.ingress.domain | quote }}
rules:
- host: {{ .Values.ingress.domain | quote }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: api
port:
name: http-3000
56 changes: 56 additions & 0 deletions helm/chart/templates/redis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
labels:
{{- include "common.labels" . | nindent 4 }}
component: redis
annotations:
{{- include "common.annotations" . | nindent 4 }}
spec:
replicas: 1
selector:
matchLabels:
component: redis
template:
metadata:
annotations:
{{- with .Values.redis.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- include "common.annotations" . | nindent 8 }}
labels:
{{- include "common.labels" . | nindent 8 }}
component: redis
spec:
automountServiceAccountToken: false
enableServiceLinks: false
containers:
- name: redis
image: "{{ .Values.redis.image }}"
imagePullPolicy: Always
ports:
- name: redis
containerPort: 6379
protocol: TCP
resources:
{{- toYaml .Values.redis.resources | nindent 12 }}
---
apiVersion: v1
kind: Service
metadata:
name: redis
labels:
{{- include "common.labels" . | nindent 4 }}
component: redis
annotations:
{{- include "common.annotations" . | nindent 4 }}
spec:
type: ClusterIP
ports:
- port: 6379
targetPort: redis
protocol: TCP
name: redis
selector:
component: redis
Loading

0 comments on commit c0a4d17

Please sign in to comment.