This repository was archived by the owner on Sep 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Meta-Txn] New relayer service (#2292)
* Initial checkin * Prod configs * prettier * Review feedback
- Loading branch information
Franck
authored
May 17, 2019
1 parent
51618e9
commit b89a591
Showing
21 changed files
with
40,213 additions
and
4,998 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
FROM node:10 as build | ||
|
||
WORKDIR /app | ||
|
||
ENV NODE_ENV=production | ||
|
||
# Install envkey-source to make environment available for sequelize migration | ||
RUN curl -s -L -o envkey-source.tar.gz https://github.com/envkey/envkey-source/releases/download/v1.2.5/envkey-source_1.2.5_linux_amd64.tar.gz | ||
RUN tar -zxf envkey-source.tar.gz 2> /dev/null | ||
RUN rm envkey-source.tar.gz | ||
RUN mv envkey-source /usr/local/bin | ||
|
||
COPY package*.json ./ | ||
COPY lerna.json ./ | ||
COPY ./packages/contracts ./packages/contracts | ||
COPY ./infra/bridge ./infra/bridge | ||
COPY ./infra/relayer ./infra/relayer | ||
|
||
RUN npm install --unsafe-perm | ||
|
||
CMD eval $(envkey-source) && npm run start --prefix infra/relayer |
This file contains 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
52 changes: 52 additions & 0 deletions
52
devops/kubernetes/charts/origin/templates/relayer.deployment.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: {{ template "relayer.fullname" . }} | ||
labels: | ||
app: {{ template "relayer.fullname" . }} | ||
app.kubernetes.io/name: origin | ||
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion }} | ||
app.kubernetes.io/component: frontend | ||
app.kubernetes.io/part-of: origin-relayer | ||
spec: | ||
replicas: {{ default 1 .Values.relayerReplicas }} | ||
selector: | ||
matchLabels: | ||
app: {{ template "relayer.fullname" . }} | ||
template: | ||
metadata: | ||
labels: | ||
app: {{ template "relayer.fullname" . }} | ||
release: "{{ .Release.Name }}" | ||
spec: | ||
containers: | ||
- name: origin-relayer | ||
image: "{{ .Values.containerRegistry }}/{{ .Release.Namespace }}/{{ .Values.relayerImage }}:{{ .Values.relayerImageTag }}" | ||
imagePullPolicy: Always | ||
env: | ||
- name: ENVKEY | ||
valueFrom: | ||
secretKeyRef: | ||
name: {{ template "relayer.fullname" . }} | ||
key: ENVKEY | ||
ports: | ||
- containerPort: 4001 | ||
- name: cloudsql-proxy | ||
image: gcr.io/cloudsql-docker/gce-proxy:1.11 | ||
command: ["/cloud_sql_proxy", | ||
"-instances={{ .Values.databaseInstance }}=tcp:5432", | ||
"-credential_file=/secrets/cloudsql/credentials.json"] | ||
securityContext: | ||
runAsUser: 2 # non-root user | ||
allowPrivilegeEscalation: false | ||
volumeMounts: | ||
- name: cloudsql-instance-credentials | ||
mountPath: /secrets/cloudsql | ||
readOnly: true | ||
volumes: | ||
- name: cloudsql-instance-credentials | ||
secret: | ||
secretName: cloudsql-instance-credentials |
36 changes: 36 additions & 0 deletions
36
devops/kubernetes/charts/origin/templates/relayer.ingress.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
apiVersion: extensions/v1beta1 | ||
kind: Ingress | ||
metadata: | ||
name: {{ template "relayer.fullname" . }} | ||
labels: | ||
app: {{ template "relayer.fullname" . }} | ||
app.kubernetes.io/name: origin | ||
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion }} | ||
app.kubernetes.io/component: frontend | ||
app.kubernetes.io/part-of: origin-relayer | ||
annotations: | ||
kubernetes.io/ingress.class: {{ .Release.Namespace }}-ingress | ||
kubernetes.io/tls-acme: "true" | ||
certmanager.k8s.io/cluster-issuer: {{ .Values.clusterIssuer }} | ||
nginx.ingress.kubernetes.io/force-ssl-redirect: "true" | ||
nginx.ingress.kubernetes.io/enable-cors: "true" | ||
nginx.ingress.kubernetes.io/cors-allow-headers: "DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type" | ||
nginx.ingress.kubernetes.io/cors-allow-methods: "GET, POST" | ||
nginx.ingress.kubernetes.io/cors-allow-origin: "*" | ||
nginx.ingress.kubernetes.io/limit-rps: "10" | ||
spec: | ||
tls: | ||
- secretName: {{ template "relayer.host" . }} | ||
hosts: | ||
- {{ template "relayer.host" . }} | ||
rules: | ||
- host: {{ template "relayer.host" . }} | ||
http: | ||
paths: | ||
- path: / | ||
backend: | ||
serviceName: {{ template "relayer.fullname" . }} | ||
servicePort: 5100 |
16 changes: 16 additions & 0 deletions
16
devops/kubernetes/charts/origin/templates/relayer.secret.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: {{ template "relayer.fullname" . }} | ||
labels: | ||
app: {{ template "relayer.fullname" . }} | ||
app.kubernetes.io/name: origin | ||
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion }} | ||
app.kubernetes.io/component: frontend | ||
app.kubernetes.io/part-of: origin-relayer | ||
type: Opaque | ||
data: | ||
ENVKEY: {{ required "Set a .Values.relayerEnvKey" .Values.relayerEnvKey | b64enc | quote}} |
20 changes: 20 additions & 0 deletions
20
devops/kubernetes/charts/origin/templates/relayer.service.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: {{ template "relayer.fullname" . }} | ||
labels: | ||
app: {{ template "relayer.fullname" . }} | ||
app.kubernetes.io/name: origin | ||
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion }} | ||
app.kubernetes.io/component: backend | ||
app.kubernetes.io/part-of: origin-relayer | ||
spec: | ||
type: NodePort | ||
selector: | ||
app: {{ template "relayer.fullname" . }} | ||
ports: | ||
- name: http | ||
port: 5100 |
This file contains 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const baseConfig = require('../../.eslintrc.js') | ||
|
||
module.exports = { | ||
...baseConfig, | ||
rules: { | ||
...baseConfig.rules, | ||
camelcase: ['error', { properties: 'never' }] | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Meta-txn relayer service. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "@origin/relayer", | ||
"description": "Origin relayer service", | ||
"version": "0.1.0", | ||
"engines": { | ||
"node": "10.x" | ||
}, | ||
"author": "Origin Protocol Inc", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/OriginProtocol/origin/issues" | ||
}, | ||
"dependencies": { | ||
"@origin/contracts": "^0.8.6", | ||
"cors": "^2.8.5", | ||
"dotenv": "^6.2.0", | ||
"envkey": "^1.2.4", | ||
"ethereumjs-util": "^6.1.0", | ||
"express": "^4.16.4", | ||
"express-prom-bundle": "^4.2.1", | ||
"logplease": "^1.2.15", | ||
"per-env": "^1.0.2", | ||
"pg": "^7.7.1", | ||
"sequelize": "^5.0.0-beta.14", | ||
"sequelize-cli": "^5.4.0", | ||
"web3": "1.0.0-beta.34" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^5.2.0", | ||
"nodemon": "^1.18.7" | ||
}, | ||
"scripts": { | ||
"lint": "eslint . && npm run prettier:check", | ||
"prettier": "prettier --write *.js \"src/**/*.js\"", | ||
"prettier:check": "prettier -c *.js \"src/**/*.js\"", | ||
"migrate": "sequelize db:migrate", | ||
"start": "per-env", | ||
"start:development": "nodemon src/app.js", | ||
"start:production": "node src/app.js", | ||
"test": "NODE_ENV=test mocha --timeout 10000 --exit" | ||
}, | ||
"prettier": { | ||
"semi": false, | ||
"singleQuote": true | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict' | ||
|
||
require('dotenv').config() | ||
try { | ||
require('envkey') | ||
} catch (error) { | ||
console.log('EnvKey not configured') | ||
} | ||
|
||
const bodyParser = require('body-parser') | ||
const cors = require('cors') | ||
const express = require('express') | ||
const promBundle = require('express-prom-bundle') | ||
const { relayTx } = require('./relayer') | ||
|
||
// For Prometheus metrics collection. | ||
const bundle = promBundle({ | ||
promClient: { | ||
collectDefaultMetrics: { | ||
timeout: 1000 | ||
} | ||
} | ||
}) | ||
|
||
const app = express() | ||
app.use(express.json()) | ||
app.use(cors({ origin: true, credentials: true })) | ||
app.use(bodyParser.json()) | ||
app.use(bodyParser.urlencoded({ extended: true })) | ||
app.use(bundle) | ||
|
||
// Register the /relay route for relaying transactions. | ||
app.post('/relay', relayTx) | ||
|
||
const port = process.env.PORT || 5100 | ||
app.listen(port, () => { | ||
console.log(`Relayer listening on port ${port}...`) | ||
}) | ||
|
||
module.exports = app |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict' | ||
|
||
const Logger = require('logplease') | ||
|
||
Logger.setLogLevel(process.env.LOG_LEVEL || 'INFO') | ||
|
||
module.exports = Logger.create('relayer', { showTimestamp: false }) |
Oops, something went wrong.