diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..65aca75 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,40 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. +# build +dist/ + +# dependencies +/node_modules +/.pnp +.pnp.js +.yarn/install-state.gz + +# testing +/coverage + +# next.js +/.next/ +/out/ + +# production +/build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# local env files +.env*.local + +# vercel +.vercel + +# typescript +*.tsbuildinfo +next-env.d.ts + +.env diff --git a/.github/workflows/fly-deploy.yml b/.github/workflows/fly-deploy.yml new file mode 100644 index 0000000..b0c246e --- /dev/null +++ b/.github/workflows/fly-deploy.yml @@ -0,0 +1,18 @@ +# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/ + +name: Fly Deploy +on: + push: + branches: + - main +jobs: + deploy: + name: Deploy app + runs-on: ubuntu-latest + concurrency: deploy-group # optional: ensure only one action runs at a time + steps: + - uses: actions/checkout@v4 + - uses: superfly/flyctl-actions/setup-flyctl@master + - run: flyctl deploy --remote-only + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2e8a3a0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,45 @@ +# syntax = docker/dockerfile:1 + +# Adjust BUN_VERSION as desired +ARG BUN_VERSION=1.1.29 +FROM oven/bun:${BUN_VERSION}-slim as base + +LABEL fly_launch_runtime="Bun" + +# Bun app lives here +WORKDIR /app + +# Set production environment +ENV NODE_ENV="production" + +# Throw-away build stage to reduce size of final image +FROM base as build + +# Install packages needed to build node modules +RUN apt-get update -qq && \ + apt-get install --no-install-recommends -y build-essential pkg-config python-is-python3 + +# Install node modules +COPY bun.lockb package.json ./ +RUN bun install + +# Copy application code +COPY . . + +# Build application +RUN bun --bun run build + +# Remove development dependencies +RUN rm -rf node_modules && \ + bun install --ci + + +# Final stage for app image +FROM base + +# Copy built application +COPY --from=build /app /app + +# Start the server by default, this can be overwritten at runtime +EXPOSE 10000 +CMD [ "bun", "run", "start" ] diff --git a/bun.lockb b/bun.lockb index 2fecd74..db5c1a2 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..416df71 --- /dev/null +++ b/fly.toml @@ -0,0 +1,22 @@ +# fly.toml app configuration file generated for near-uniswap-agent on 2024-12-18T10:52:52Z +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# + +app = 'near-uniswap-agent' +primary_region = 'cdg' + +[build] + +[http_service] + internal_port = 10000 + force_https = true + auto_stop_machines = 'stop' + auto_start_machines = true + min_machines_running = 0 + processes = ['app'] + +[[vm]] + memory = '1gb' + cpu_kind = 'shared' + cpus = 1 diff --git a/package.json b/package.json index 925530a..fb4f902 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,11 @@ "private": true, "type": "module", "scripts": { - "dev": "concurrently \"tsx src/server.ts\" \"make-agent dev -p 3000\"", - "dev-testnet": "concurrently \"tsx src/server.ts\" \"make-agent dev -p 3000 -t\"", + "dev": "concurrently \"bun run src/server.ts\" \"make-agent dev -p 10000\"", + "dev-testnet": "concurrently \"bun run src/server.ts\" \"make-agent dev -p 10000 -t\"", "build": "tsc", - "start": "tsx src/server.ts", - "serve": "bun dist/server.js", + "start": "bun run src/server.ts", + "serve": "bun run src/server.ts", "lint": "eslint '{src,tests}/**/*.{js,jsx,ts,tsx}'", "fmt": "eslint --fix '{src,tests}/**/*.{js,jsx,ts,tsx}' && prettier --write '{src,tests}/**/*.{js,jsx,ts,tsx}'", "test": "jest --config jest.config.ts" @@ -26,6 +26,7 @@ "zerion-sdk": "^0.0.13" }, "devDependencies": { + "@flydotio/dockerfile": "^0.5.9", "@types/cors": "^2.8.17", "@types/express": "^4.17.21", "@types/jest": "^29.5.14", diff --git a/src/server.ts b/src/server.ts index ca4d7f2..6dfa19e 100644 --- a/src/server.ts +++ b/src/server.ts @@ -5,15 +5,37 @@ import swaggerUi from "swagger-ui-express"; import { healthRouter } from "./routes/health"; import { uniswapRouter } from "./routes/uniswap"; import { pluginData } from "./plugin"; +import path from "path"; +import { fileURLToPath } from "url"; config(); // Load .env file const app = express(); -const port = process.env.PORT || 3000; +const port = process.env.PORT || 10000; app.use(cors()); app.use(express.json()); +// Serve static files from public directory +app.use(express.static('public')); + +// Root route with API info +app.get("/", (_, res) => { + res.send(` +
Welcome to the Bitte Uniswap Agent API server.
+ +/api/health
- Health check endpoint/api/tools/uniswap
- Uniswap integration endpoints