Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
.circleci
.drone.yml
.editorconfig
.env*
.git*
.github/
.prettie*
*.md
*.MD
*ignore
0x_mesh_test/
docker-compose*
Dockerfile
node_modules
postgres
0x_mesh
.circleci
37 changes: 37 additions & 0 deletions .env_prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Required
CHAIN_ID=
ETHEREUM_RPC_URL=

# Optional
MESH_WEBSOCKET_URI=
MESH_HTTP_URI=
POSTGRES_URI=
FEE_RECIPIENT_ADDRESS=
MAKER_FEE_ASSET_DATA=
MAKER_FEE_UNIT_AMOUNT=
MAKER_FEE_ASSET_DATA=
TAKER_FEE_UNIT_AMOUNT=
# POSTGRES_URI=postgresql://api:api@qa-pgsql/api
WHITELIST_ALL_TOKENS=true
LIQUIDITY_POOL_REGISTRY_ADDRESS=
MESH_IGNORED_ADDRESSES=
SWAP_IGNORED_ADDRESSES=
HTTP_KEEP_ALIVE_TIMEOUT=
HTTP_HEADERS_TIMEOUT=
SRA_ORDER_EXPIRATION_BUFFER_SECONDS=
MAX_EXPIRATION_ALERT_THRESHOLD_SECONDS=
PINNED_POOL_IDS=
PINNED_MM_ADDRESSES=
WHITELISTED_API_KEYS_META_TXN_SUBMIT=
META_TXN_RELAY_PRIVATE_KEYS=
META_TXN_RELAY_EXPECTED_MINED_SEC=
ENABLE_PROMETHEUS_METRICS=
PROMETHEUS_PORT=
RFQT_API_KEY_WHITELIST=
PLP_API_KEY_WHITELIST=*

# For release
GITHUB_TOKEN=

INDICATIVE_PRICE_AWARE_RFQ_ENABLED=
FIRM_PRICE_AWARE_RFQ_ENABLED=
22 changes: 5 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
# Stage 1
FROM node:12-alpine as yarn-install
FROM node:14-alpine as yarn-install
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json yarn.lock ./
RUN apk update && \
apk upgrade && \
apk add --no-cache --virtual build-dependencies bash git openssh python make g++ && \
yarn --frozen-lockfile --no-cache && \
apk del build-dependencies && \
yarn cache clean

RUN apk add -U --virtual build-dependencies bash git openssh python make g++
RUN yarn --frozen-lockfile --no-cache
# Runtime container with minimal dependencies
FROM node:12-alpine

RUN apk update && \
apk upgrade && \
apk add ca-certificates

FROM node:14-alpine
WORKDIR /usr/src/app
COPY --from=yarn-install /usr/src/app/node_modules /usr/src/app/node_modules
# Bundle app source
COPY . .

RUN yarn build

EXPOSE 3000
CMD [ "node", "lib/src/index.js" ]
CMD [ "yarn", "start:db_migrate"]
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,25 @@ ETHEREUM_RPC_URL=http://ganache:8545
Then run

```
$ docker-compose up
$ docker-compose -f docker-compose-test-ganache.yml
$ yarn dev
```
#### Developing on Ropsten

export env vars to point to Chain id and ethereum rpc url:
```sh
export CHAIN_ID=123
export ETHEREUM_RPC_URL=https://example.com/id
```

Run deployment with existing `0xapi:latest` docker image
```sh
docker-compose -f docker-compose.yml up -d
```
Alternatively it is possible to specify `--build` argument to rebuild the image from local foler and then run/update the deployment
```sh
docker-compose -f docker-compose.yml up -d --build
```

## Testing

Expand All @@ -152,6 +168,7 @@ Tip: Test suites set up and teardown sandboxed environments, so using `.only` on
- `yarn test` - Test the code
- `yarn lint` - Lint the code
- `yarn start` - Starts the API
- `yarn start:db_migrate` - to be used in containers, runs migrations and starts the API
- `yarn dev` - Starts the API in dev-mode
- `yarn watch` - Watch the source code and rebuild on change
- `yarn prettier` - Auto-format the code
Expand Down
45 changes: 45 additions & 0 deletions docker-compose-services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
version: '3'
services:
ganache:
image: '0xorg/ganache-cli:6.5.10'
ports:
- '8545:8545'
environment:
VERSION: 8.0.1
CHAIN_ID: 1337
NETWORK_ID: 1337
postgres:
image: postgres:9.6
environment:
- POSTGRES_USER=api
- POSTGRES_PASSWORD=api
- POSTGRES_DB=api
# persist the postgres data to disk so we don't lose it
# on rebuilds.
volumes:
- ./postgres:/var/lib/postgresql/data
ports:
- '5432:5432'
mesh:
image: 0xorg/mesh:11.0.1
depends_on:
- ganache
restart: on-failure
environment:
ETHEREUM_RPC_URL: '${ETHEREUM_RPC_URL}'
ETHEREUM_CHAIN_ID: '${CHAIN_ID}'
USE_BOOTSTRAP_LIST: 'false'
VERBOSITY: 4
PRIVATE_KEY_PATH: ''
ENABLE_GRAPHQL_SERVER: 'true'
ENABLE_GRAPHQL_PLAYGROUND: 'true'
BLOCK_POLLING_INTERVAL: '2s'
ETHEREUM_RPC_MAX_REQUESTS_PER_24_HR_UTC: '150000'
volumes:
- ./0x_mesh_test:/usr/mesh/0x_mesh
ports:
- '60557:60557'
- '60558:60558'
- '60559:60559'
command: |
sh -c "waitForGanache () { until printf 'POST /\r\nContent-Length: 26\r\n\r\n{\"method\":\"net_listening\"}' | nc localhost 8545 | grep true; do continue; done }; waitForGanache && ./mesh"
File renamed without changes.
52 changes: 26 additions & 26 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
version: '3'
services:
ganache:
image: '0xorg/ganache-cli:6.5.10'
ports:
- '8545:8545'
environment:
VERSION: 8.0.1
CHAIN_ID: 1337
NETWORK_ID: 1337
postgres:
image: postgres:9.6
environment:
- POSTGRES_USER=api
- POSTGRES_PASSWORD=api
- POSTGRES_DB=api
# persist the postgres data to disk so we don't lose it
# on rebuilds.
volumes:
- ./postgres:/var/lib/postgresql/data
ports:
- '5432:5432'
mesh:
image: 0xorg/mesh:11.0.1
depends_on:
- ganache
image: 0xorg/mesh:11.0.3
restart: on-failure
environment:
ETHEREUM_RPC_URL: '${ETHEREUM_RPC_URL}'
ETHEREUM_CHAIN_ID: '${CHAIN_ID}'
USE_BOOTSTRAP_LIST: 'false'
VERBOSITY: 4
PRIVATE_KEY_PATH: ''
ENABLE_GRAPHQL_SERVER: 'true'
ENABLE_GRAPHQL_PLAYGROUND: 'true'
BLOCK_POLLING_INTERVAL: '2s'
ETHEREUM_RPC_MAX_REQUESTS_PER_24_HR_UTC: '150000'
VERBOSITY: 3
volumes:
- ./0x_mesh_test:/usr/mesh/0x_mesh
ports:
- '60557:60557'
- '60558:60558'
- '60559:60559'
command: |
sh -c "waitForGanache () { until printf 'POST /\r\nContent-Length: 26\r\n\r\n{\"method\":\"net_listening\"}' | nc localhost 8545 | grep true; do continue; done }; waitForGanache && ./mesh"
- '127.0.0.1:60557:60557'
- '127.0.0.1:60558:60558'
- '127.0.0.1:60559:60559'
0xapi:
image: 0xapi:latest
build:
context: ./
dockerfile: Dockerfile
command: ["yarn", "start:db_migrate"]
depends_on:
- postgres
- mesh
labels:
- "com.centurylinklabs.watchtower.enable=false"
volumes:
- .env_prod:/usr/src/app/.env
ports:
- 3000:3000
environment:
ETHEREUM_RPC_URL: '${ETHEREUM_RPC_URL}'
ETHEREUM_CHAIN_ID: '${CHAIN_ID}'
POSTGRES_URI: 'postgresql://api:api@postgres/api'
MESH_WEBSOCKET_URI: http://mesh:60557
MESH_HTTP_URI: http://mesh:60557
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"prettier": "prettier --write ${npm_package_config_prettier_target} --config .prettierrc",
"prettier:ci": "prettier --list-different ${npm_package_config_prettier_target} --config .prettierrc",
"start": "node -r dotenv/config lib/src/index.js",
"start:db_migrate": "yarn db:migrate && node -r dotenv/config lib/src/index.js",
"start:service:http": "node -r dotenv/config lib/src/runners/http_service_runner.js",
"start:service:sra_http": "node -r dotenv/config lib/src/runners/http_sra_service_runner.js",
"start:service:swap_http": "node -r dotenv/config lib/src/runners/http_swap_service_runner.js",
Expand Down