From dea37a0bc0a13ed330ac3c4e7cbeb76da95a2820 Mon Sep 17 00:00:00 2001 From: PFC <81114960+PFC-developer@users.noreply.github.com> Date: Mon, 9 Sep 2024 13:04:59 -0500 Subject: [PATCH 1/5] dockerize it --- .dockerignore | 3 +++ .github/workflows/docker.yml | 46 ++++++++++++++++++++++++++++++++++++ .gitignore | 3 ++- Dockerfile | 14 +++++++++++ README.md | 9 +++++++ src/lib/config.ts | 3 ++- 6 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4264f88 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +/.idea +/.node_modules +/.gitignore diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..085c7ab --- /dev/null +++ b/.github/workflows/docker.yml @@ -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/metadata-action@v5.5.1 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=latest + type=semver,pattern=v{{version}} + - name: Build and push + uses: docker/build-push-action@v=6.7.0 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.gitignore b/.gitignore index e7d661f..2f54cb9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ node_modules/ -config.json \ No newline at end of file +config.json +/.idea \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..53acee7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +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 +VOLUME /config + +CMD ["npm", "start"] \ No newline at end of file diff --git a/README.md b/README.md index e628282..73bf2be 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,15 @@ npm install ```bash npm start ``` +## Install via docker +```bash +docker build -t your-tag . +``` +mount a volume called '/config' which contains your config.json +```bash +docker run -it -v/tmp/rr/config:/config -d test +``` +this should start the relayer in a docker container using your config. ## SyncInfo diff --git a/src/lib/config.ts b/src/lib/config.ts index 002c4f1..bbd0ca3 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -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 { From fbff5c1b2ece461bf7c790d52afedc808adca041 Mon Sep 17 00:00:00 2001 From: PFC <81114960+PFC-developer@users.noreply.github.com> Date: Mon, 9 Sep 2024 13:07:06 -0500 Subject: [PATCH 2/5] dockerize it - fix action version --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 085c7ab..a4ae576 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -38,7 +38,7 @@ jobs: type=raw,value=latest type=semver,pattern=v{{version}} - name: Build and push - uses: docker/build-push-action@v=6.7.0 + uses: docker/build-push-action@v6.7.0 with: context: . push: ${{ github.event_name != 'pull_request' }} From d6ef08b2f5fac9a86472efaf0a01e6960a177bf2 Mon Sep 17 00:00:00 2001 From: PFC <81114960+PFC-developer@users.noreply.github.com> Date: Mon, 9 Sep 2024 13:10:21 -0500 Subject: [PATCH 3/5] dockerize it - fix readme. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 73bf2be..1b1acf0 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ docker build -t your-tag . ``` mount a volume called '/config' which contains your config.json ```bash -docker run -it -v/tmp/rr/config:/config -d test +docker run -it -v/tmp/rr/config:/config -d rapid-relayer:latest ``` this should start the relayer in a docker container using your config. From 151578dfb27cac338737fd7b9b7592e98fb6608c Mon Sep 17 00:00:00 2001 From: PFC <81114960+PFC-developer@users.noreply.github.com> Date: Mon, 9 Sep 2024 13:20:01 -0500 Subject: [PATCH 4/5] dockerize it - add syncInfo volume --- Dockerfile | 2 ++ README.md | 7 ++++--- src/chain/index.ts | 7 ++++--- src/lib/config.ts | 2 ++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 53acee7..aef1ca4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,8 @@ RUN tsc ENV CONFIGFILE=/config/config.json +ENV SYNC_INFO=/syncInfo/syncInfo VOLUME /config +VOLUME /syncInfo CMD ["npm", "start"] \ No newline at end of file diff --git a/README.md b/README.md index 1b1acf0..265a934 100644 --- a/README.md +++ b/README.md @@ -85,11 +85,12 @@ npm start ```bash docker build -t your-tag . ``` -mount a volume called '/config' which contains your config.json +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 -d rapid-relayer:latest +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. +this should start the relayer in a docker container using your config, and placing the state in a separate volume ## SyncInfo diff --git a/src/chain/index.ts b/src/chain/index.ts index afc1436..a8e0b46 100644 --- a/src/chain/index.ts +++ b/src/chain/index.ts @@ -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: { @@ -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 }) @@ -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 { diff --git a/src/lib/config.ts b/src/lib/config.ts index bbd0ca3..1edd34a 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -12,3 +12,5 @@ export interface Config { logLevel: string pairs: ConfigPair[] } + +export const syncInfoFile = env.SYNC_INFO || './.syncInfo' From 846bf91c9d166a470c8df10a9908fc780b1660c1 Mon Sep 17 00:00:00 2001 From: PFC <81114960+PFC-developer@users.noreply.github.com> Date: Mon, 9 Sep 2024 13:21:00 -0500 Subject: [PATCH 5/5] dockerize it - add port --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index aef1ca4..fc30abd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,7 @@ RUN tsc ENV CONFIGFILE=/config/config.json ENV SYNC_INFO=/syncInfo/syncInfo +EXPOSE 3000 VOLUME /config VOLUME /syncInfo