Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-chart-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
quangdz1704 committed Jan 26, 2024
2 parents 638c53f + 31ba11f commit b4c96ff
Show file tree
Hide file tree
Showing 180 changed files with 3,845 additions and 3,123 deletions.
43 changes: 43 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
node_modules/

# build
**/dist/
**/build/

.git/
.github/
.vscode/


**/coverage/
npm-debug.log
.coverage
.coverage.*
.aws
.husky
.nx
**/target
**/pkg
**/tests
*.md

# docker
Dockerfile*

# env variables
**/.env.*
**/.env

# config
config*.{yaml,yml}

# database file
**/*.db
**/*.wal
oraidex-sync-data*
**/*.csv
**/*.txt


# prettier
.prettierc.json
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PORT=2024
RPC_URL=https://rpc.orai.io
LIMIT=1000
MAX_THREAD_LEVEL=3
DUCKDB_PROD_FILENAME="db_name"
DUCKDB_FILENAME="db_name_only_sync"
INITIAL_SYNC_HEIGHT=14612180
ORDERBOOK_API_ENDPOINT=https://server.oraidex.io
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"@typescript-eslint/no-explicit-any": [
"warn"
],
"@typescript-eslint/no-unused-vars": "warn"
"@typescript-eslint/no-unused-vars": "warn",
"security/detect-object-injection": "off"
}
},
{
Expand Down
61 changes: 61 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Check the test before merge

on:
# When Release Pull Request is merged
pull_request:
types: [opened, synchronize]
branches:
- main
- staging

env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

jobs:
test:
strategy:
matrix:
node: ["18.18.0"]
os: ["ubuntu-latest"]
runs-on: ${{ matrix.os }}
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]

- name: Checkout
uses: actions/checkout@v4

- name: Setup Nodejs
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}

- run: npm install -g yarn

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- uses: actions/cache@v3
id: yarn-cache
with:
path: |
${{ steps.yarn-cache-dir-path.outputs.dir }}
./node_modules/
key: ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn

- name: Run nx reset workspace
run: yarn nx reset

- name: Run build
run: yarn build

- name: Run test
run: |
yarn test
118 changes: 118 additions & 0 deletions .github/workflows/publish_backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: Build and push executor to Docker Hub

on:
workflow_dispatch:
branches:
- main
- staging

push:
tags:
- "v*"
- "v*-beta"

env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

jobs:
docker:
strategy:
matrix:
node: ["18.18.0"]
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
oraichain/defi_oraidex-backend
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,enable=true,priority=100,prefix=,suffix=,format=short
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
build-args: |
GIT_COMMIT=${{ env.GIT_COMMIT }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
context: .
cache-from: type=registry,ref=oraichain/defi_oraidex-backend:buildcache
cache-to: type=registry,ref=oraichain/defi_oraidex-backend:buildcache,mode=max
platforms: linux/amd64,linux/arm64

swarm:
runs-on: ubuntu-20.04
needs: docker
steps:
- name: Extract SHA
id: extract_sha
run: echo "short_sha=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_OUTPUT

- name: Check outputs
run: echo ${{ steps.extract_sha.outputs.short_sha}}

- name: Set environment
id: set_environment
env:
GITHUB_REF_NAME: ${{ github.ref_name }}
run: |
set -e
if [[ $GITHUB_REF_NAME == 'main' || ! $GITHUB_REF_NAME =~ 'beta' ]]
then
echo deploy_environment='production' >> $GITHUB_OUTPUT
else
echo deploy_environment='staging' >> $GITHUB_OUTPUT;
fi
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Check exist images
run: |
docker manifest inspect oraichain/defi_oraidex-backend:${{ steps.extract_sha.outputs.short_sha }}
- name: Deploy to Swarm (staging)
if: ${{ steps.set_environment.outputs.deploy_environment == 'staging'}}
run: |
curl -X POST \
${{ secrets.STAGING_WEBHOOK_SERVICE }}?tag=${{ steps.extract_sha.outputs.short_sha }}
- name: Deploy to Swarm
if: ${{ steps.set_environment.outputs.deploy_environment == 'production'}}
run: |
curl -X POST \
${{ secrets.WEBHOOK_SERVICE }}?tag=${{ steps.extract_sha.outputs.short_sha }}
- name: Send discord message
uses: appleboy/discord-action@master
with:
webhook_id: ${{ secrets.WEBHOOK_ID }}
webhook_token: ${{ secrets.WEBHOOK_TOKEN }}
username: "GitBot"
message: "[${{ steps.set_environment.outputs.deploy_environment }}] Repo oraidex-backend has just deployed to swarm with tag: ${{ steps.extract_sha.outputs.short_sha }}"
28 changes: 9 additions & 19 deletions .github/workflows/publish_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,10 @@ jobs:
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn
- name: Build
run: yarn build && yarn build-tsc packages/oraidex-sync && yarn --cwd packages/oraidex-server/ build
run: yarn build
- name: Authenticate with private NPM package
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
- name: Publish Oraidex Server
id: publish
continue-on-error: true
run: yarn deploy packages/oraidex-server
env:
CI: false
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish Oraidex Common
id: publish-common
continue-on-error: true
Expand All @@ -69,22 +63,18 @@ jobs:
env:
CI: false
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Install latest version
id: install
if: steps.publish.outcome != 'failure'
- name: Publish Oraidex contracts-sdk
id: publish-oraidex-contracts-sdk
continue-on-error: true
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DOCKER_SWARM_MANAGER_ONE }}
username: root
key: ${{ secrets.DOCKER_SWARM_MANAGER_ONE_KEY }}
script: docker exec ${{ secrets.DOCKER_SWARM_MANAGER_ONE_NODE_16_ID}} sh -c 'yarn global add @oraichain/oraidex-server@latest --ignore-scripts'
run: yarn deploy packages/contracts-sdk
env:
CI: false
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: send result via discord
uses: appleboy/discord-action@master
with:
webhook_id: ${{ secrets.WEBHOOK_ID }}
webhook_token: ${{ secrets.WEBHOOK_TOKEN }}
username: "GitBot"
message: "Repo oraidex-sdk has just published oraidex-server. result: ${{ steps.publish.outcome }}. install result: ${{ steps.install.outcome }}"
message: "Repo oraidex-sdk has just published. result: ${{ steps.publish.outcome }}."
80 changes: 0 additions & 80 deletions .github/workflows/publish_staging_package.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ build
dist
.DS_Store
cache/

packages/contract-state-simulate/public/
10 changes: 8 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{
"prettier.singleQuote": false,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.formatOnPaste": false,
"prettier.useEditorConfig": false,
"prettier.useTabs": false,
"prettier.trailingComma": "none",
"prettier.jsxSingleQuote": false,
"prettier.tabWidth": 2,
"prettier.printWidth": 120,
"prettier.semi": true,
"prettier.singleQuote": true,
"typescript.tsdk": "node_modules/typescript/lib"
}
Loading

0 comments on commit b4c96ff

Please sign in to comment.