diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..c9ae559 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,21 @@ +name: Check Code + +on: + push: + branches: [main] + pull_request: + branches: [main] + + +jobs: + check-code: + name: Check Code + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Install deps + run: yarn install + + - name: Build + run: yarn build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..d7e4f09 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,54 @@ +name: Release + +on: + push: + tags: + - "v*" + pull_request: + branches: [main] + workflow_dispatch: + +env: + DOCKER_REGISTRY: ghcr.io + +jobs: + release-docker-image: + name: Publish docker image + runs-on: ubuntu-latest + strategy: + matrix: + package: + - reporter + - publisher + steps: + - uses: actions/checkout@v2 + + - name: Docker login + uses: docker/login-action@v1 + with: + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + registry: ${{ env.DOCKER_REGISTRY }} + + - name: Tag + uses: olegtarasov/get-tag@v2.1 + - name: Sha + uses: benjlevesque/short-sha@v1.2 + + - name: Publish docker image + uses: docker/build-push-action@v6 + with: + push: true + context: . + file: packages/${{ matrix.package }}-client/Dockerfile + tags: ${{ env.DOCKER_REGISTRY }}/${{ github.repository }}/${{ matrix.package }}:sha-${{ env.SHA }} + + - name: Publish docker image with tag + uses: docker/build-push-action@v6 + if: startsWith(github.ref, 'refs/tags/v') + with: + push: true + context: . + file: packages/${{ matrix.package }}-client/Dockerfile + tags: ${{ env.DOCKER_REGISTRY }}/${{ github.repository }}/${{ matrix.package }}:${{ env.GIT_TAG_NAME }} + diff --git a/package.json b/package.json index ba00fc0..7c79042 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "url": "git+https://github.com/ringecosystem/xapi-offchain.git" }, "scripts": { - "build:all": "lerna run build", + "build": "lerna run build", "build:indexer": "lerna run build --scope=@ringdao/xapi-indexer-evm --scope=@ringdao/xapi-indexer-near", "build:offchain": "lerna run build --scope=@ringdao/xapi-reporter-client --scope=@ringdao/xapi-publisher-client --scope=@ringdao/xapi-common", "test": "lerna run test", diff --git a/packages/publisher-client/Dockerfile b/packages/publisher-client/Dockerfile new file mode 100644 index 0000000..3d94b65 --- /dev/null +++ b/packages/publisher-client/Dockerfile @@ -0,0 +1,10 @@ +FROM node:20-alpine as builder +ADD . /build +RUN cd /build \ + && yarn install \ + && yarn build:offchain + +FROM node:20-alpine +COPY --from=builder /build /app + +ENTRYPOINT ["/app/scripts/publisher.entrypoint.sh"] diff --git a/packages/reporter-client/Dockerfile b/packages/reporter-client/Dockerfile new file mode 100644 index 0000000..c341c44 --- /dev/null +++ b/packages/reporter-client/Dockerfile @@ -0,0 +1,10 @@ +FROM node:20-alpine as builder +ADD . /build +RUN cd /build \ + && yarn install \ + && yarn build:offchain + +FROM node:20-alpine +COPY --from=builder /build /app + +ENTRYPOINT ["/app/scripts/reporter.entrypoint.sh"] diff --git a/scripts/publisher.entrypoint.sh b/scripts/publisher.entrypoint.sh new file mode 100755 index 0000000..12359d8 --- /dev/null +++ b/scripts/publisher.entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# + +set -e + +BIN_PATH=$(cd "$(dirname "$0")"; pwd -P) +WORK_PATH=${BIN_PATH}/../ + +node ${WORK_PATH}/packages/publisher-client/dist/main.js $@ diff --git a/scripts/reporter.entrypoint.sh b/scripts/reporter.entrypoint.sh new file mode 100755 index 0000000..f9f55ff --- /dev/null +++ b/scripts/reporter.entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# + +set -e + +BIN_PATH=$(cd "$(dirname "$0")"; pwd -P) +WORK_PATH=${BIN_PATH}/../ + +node ${WORK_PATH}/packages/reporter-client/dist/main.js $@ diff --git a/scripts/start-publisher-client.sh b/scripts/start-publisher-client.sh index dbd3b10..8b1cbd3 100755 --- a/scripts/start-publisher-client.sh +++ b/scripts/start-publisher-client.sh @@ -12,6 +12,6 @@ npm run build:offchain cd ${WORK_PATH}/packages/publisher-client -export XPI_LOG_LEVEL=debug +# export XPI_LOG_LEVEL=info node dist/main.js $@ diff --git a/scripts/start-reporter-client.sh b/scripts/start-reporter-client.sh index 879fb33..91414b9 100755 --- a/scripts/start-reporter-client.sh +++ b/scripts/start-reporter-client.sh @@ -12,7 +12,7 @@ npm run build:offchain cd ${WORK_PATH}/packages/reporter-client -export XAPI_LOG_FULL=0 -export XAPI_LOG_LEVEL=debug +# export XAPI_LOG_FULL=0 +# export XAPI_LOG_LEVEL=info node dist/main.js $@