Skip to content

Commit

Permalink
Merge pull request #8 from PFC-developer/dockerize
Browse files Browse the repository at this point in the history
build docker to enable you to run this
  • Loading branch information
ALPAC-4 authored Sep 12, 2024
2 parents 38cad68 + 846bf91 commit 6b22cad
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.idea
/.node_modules
/.gitignore
46 changes: 46 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: docker

on:
push:
branches:
- 'main'
# for testing
- 'dockerize'
tags:
- 'v*'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
docker:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/[email protected]
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest
type=semver,pattern=v{{version}}
- name: Build and push
uses: docker/[email protected]
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

node_modules/

config.json
config.json
/.idea
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM node:alpine

WORKDIR /usr/rapid-relayer
COPY package.json .
RUN npm install\
&& npm install typescript -g
COPY . .
RUN tsc


ENV CONFIGFILE=/config/config.json
ENV SYNC_INFO=/syncInfo/syncInfo
EXPOSE 3000
VOLUME /config
VOLUME /syncInfo

CMD ["npm", "start"]
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ npm install
```bash
npm start
```
## Install via docker
```bash
docker build -t your-tag .
```
mount a volume called '/config' which contains your config.json
and a /syncInfo volume which will contain the state
```bash
docker run -it -v/tmp/rr/config:/config -v/tmp/rr/syncInfo:/syncInfo -d rapid-relayer:latest
```
this should start the relayer in a docker container using your config, and placing the state in a separate volume

## SyncInfo

Expand Down
7 changes: 4 additions & 3 deletions src/chain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
} from './types'
import { metrics } from 'src/lib/metric'
import { Counter } from 'prom-client'
import { syncInfoFile } from '../lib/config'

export class Chain {
private syncInfo: {
Expand Down Expand Up @@ -79,9 +80,9 @@ export class Chain {

await chain.updateLatestHeight()
const syncInfo = fs.existsSync(chain.syncFilePath())
const dir = fs.existsSync('./.syncInfo')
const dir = fs.existsSync(syncInfoFile)
if (!dir) {
fs.mkdirSync('./.syncInfo')
fs.mkdirSync(syncInfoFile)
}
if (!syncInfo) {
chain.updatesyncInfo(config.syncInfo ?? { height: 1, txIndex: 0 })
Expand Down Expand Up @@ -553,7 +554,7 @@ export class Chain {
}

private syncFilePath(): string {
return `./.syncInfo/${this.lcd.config.chainId}_${this.connectionId}.json`
return `${syncInfoFile}/${this.lcd.config.chainId}_${this.connectionId}.json`
}

private chainId(): string {
Expand Down
5 changes: 4 additions & 1 deletion src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as fs from 'fs'
import { ConfigPair } from './chainPair'
import { env } from 'node:process'

export const config: Config = JSON.parse(
fs.readFileSync('./config.json').toString()
fs.readFileSync(env.CONFIGFILE || './config.json').toString()
) as Config // TODO: get path of config

export interface Config {
Expand All @@ -11,3 +12,5 @@ export interface Config {
logLevel: string
pairs: ConfigPair[]
}

export const syncInfoFile = env.SYNC_INFO || './.syncInfo'

0 comments on commit 6b22cad

Please sign in to comment.