Skip to content

Commit

Permalink
Adjust config code & Add CI/CD files
Browse files Browse the repository at this point in the history
Signed-off-by: KayleCoder <[email protected]>
  • Loading branch information
KayleCoder committed Jul 30, 2024
1 parent 066dc32 commit 8154704
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
TON_BAG_ADDRESS=kQD8ntXDohGn8GPVfxX5BF6zfgl7A_fks-8QoVcmKx5TE5M-
TON_BAG_ADDRESS=EQBOOMNqG0rvNm6vFGfR4qZl48BTDw_gYefVI4DQ70t9GoPC
TASK_PROVIDER_MNEMONIC=xxx ...
58 changes: 58 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Build tonbags-manager (main)

on:
workflow_dispatch:
push:
branches: [ "main" ]
jobs:
build:
if: github.repository == 'crustio/tonbags-manager'
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- uses: actions/cache@v3
with:
path: |
.yarn/cache
./node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn install

- name: Build
run: yarn build

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

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Get current date
id: date
run: echo "date=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV

- name: Build and push
id: docker_build
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
push: true
tags: |
crustio/tonbags-manager:latest
crustio/tonbags-manager:${{ env.date }}
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# base image for local development
FROM node:20
WORKDIR /app
COPY dist ./dist
COPY node_modules ./node_modules
CMD ["node", "./dist/index.js"]
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
# tonbags-manager

tonbags-manager is a file picking bot which continuously picking and handling files from tonbags-contract.
## Description

tonbags-manager is a file picking bot which continuously picking and handling files from tonbags-contract.

## Configuration

tonbags-manager is configured using environment variables. You can define them using export or with an .env file.

We provide a .env.example file as reference which you can use as starting point.

```bash
cp .env.example .env
```

## Running locally

Install dependencies

```bash
yarn install
```

Run

```bash
yarn dev
```
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
version: "3.7"

services:
manager:
container_name: tonbags-manager
image: crustio/tonbags-manager:latest
restart: always
env_file:
- ".env"
volumes:
- ./data:/app/data
- ./log:/app/log
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
"author": "KayleCoder <[email protected]>",
"license": "MIT",
"scripts": {
"build": "gts clean && tsc"
"build": "gts clean && tsc",
"dev": "node --require ts-node/register src/index.ts"
},
"dependencies": {
"@orbs-network/ton-access": "^2.3.3",
"@ton/core": "^0.56.3",
"@ton/crypto": "^3.2.0",
"@ton/ton": "^13.11.2",
"axios": "^1.7.2",
"dotenv": "^16.4.5",
"js-sha256": "^0.11.0",
"sequelize": "^6.35.2",
"sqlite3": "^5.1.7",
Expand Down
4 changes: 2 additions & 2 deletions src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {getEnvOrExit} from "../util/common";
import {ENV} from "../type/common";

require('dotenv').config();
export const env = getEnvOrExit("ENV", "dev") as ENV;

export const isDev = env === "dev";
Expand All @@ -10,7 +10,7 @@ export const configs = {
dbPath: getEnvOrExit("DB_PATH", "./data"),
// TON Archive server host
ton: {
host: getEnvOrExit("TON_ARCHIVE_NODE_HOST", "", !isDev),
host: getEnvOrExit("TON_RPC_URL", "", !isDev),
tonbag_address: getEnvOrExit("TON_BAG_ADDRESS", "EQBOOMNqG0rvNm6vFGfR4qZl48BTDw_gYefVI4DQ70t9GoPC"),
},
task: {
Expand Down
4 changes: 2 additions & 2 deletions src/util/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const defaultLogger = createLogger({
// - Write all logs error (and below) to `crust-api-error.log`.
//
new transports.Console(),
new transports.File({ filename: 'tonbags-manager-error.log', level: 'error' }),
new transports.File({ filename: 'tonbags-manager.log' }),
new transports.File({ filename: 'tonbags-manager-error.log', dirname: 'log', level: 'error' }),
new transports.File({ filename: 'tonbags-manager.log', dirname: 'log' }),
],
});

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,11 @@ doctrine@^3.0.0:
dependencies:
esutils "^2.0.2"

dotenv@^16.4.5:
version "16.4.5"
resolved "https://registry.npmmirror.com/dotenv/-/dotenv-16.4.5.tgz#cdd3b3b604cb327e286b4762e13502f717cb099f"
integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==

dottie@^2.0.6:
version "2.0.6"
resolved "https://registry.npmmirror.com/dottie/-/dottie-2.0.6.tgz#34564ebfc6ec5e5772272d466424ad5b696484d4"
Expand Down

0 comments on commit 8154704

Please sign in to comment.