diff --git a/.dockerignore b/.dockerignore index 6be9e1f..3cea2a5 100644 --- a/.dockerignore +++ b/.dockerignore @@ -79,3 +79,8 @@ frontend/**/*.sw? # flyctl launch added from node_modules/tailwindcss/stubs/.gitignore !node_modules/tailwindcss/stubs/**/* fly.toml + +# workspace +landing-page +docs +.github \ No newline at end of file diff --git a/.github/near-rewards.yml b/.github/near-rewards.yml new file mode 100644 index 0000000..16ed2b3 --- /dev/null +++ b/.github/near-rewards.yml @@ -0,0 +1,28 @@ +name: NEAR Protocol Rewards Tracking +on: + schedule: + - cron: '0 */12 * * *' # Every 12 hours + workflow_dispatch: # Manual trigger + push: + branches: [ main ] # Start on main branch updates + +jobs: + calculate-rewards: + runs-on: ubuntu-latest + permissions: + contents: read + issues: read + pull-requests: read + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: '18' + + - name: Calculate Rewards + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_REPO: ${{ github.repository }} + run: | + npm install -g near-protocol-rewards@latest + near-protocol-rewards calculate \ No newline at end of file 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/.gitignore b/.gitignore index f0db091..84eca3e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # dependencies -/node_modules +**/node_modules /.pnp .pnp.js .yarn/install-state.gz @@ -45,3 +45,7 @@ next-env.d.ts .cache .db .turbo +landing-page/yarn.lock +package-lock.json +landing-page/bun.lockb +bun.lockb diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..383b291 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,6 @@ +build +coverage +node_modules +.turbo +.next +.docusaurus \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7aed4e3..eb228df 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,7 +20,7 @@ Please follow the existing code style and conventions used in the project. ## Testing -This repository uses playwright tests, which can be found in [/playwright-tests](./playwright-tests/). Ensure that your changes include appropriate tests and that existing tests pass. +This repository uses tests located in the backend's `src/__tests__` directory. Ensure that your changes include appropriate tests and that existing tests pass. ## Submitting Issues diff --git a/Dockerfile b/Dockerfile index cd28374..106ce23 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,52 +1,77 @@ -FROM oven/bun as deps +## NOTE +# This Dockerfile builds the frontend and backend separately, +# frontend uses npm and backend requires bun. +# This separation is a temporary solution for a Bun issue with rsbuild, +# see: https://github.com/oven-sh/bun/issues/11628 +# Frontend deps & build stage +FROM node:20 as frontend-builder WORKDIR /app -# Copy package files for all workspaces -COPY package.json bun.lockb turbo.json ./ +# Copy frontend package files COPY frontend/package.json ./frontend/ -COPY backend/package.json ./backend/ -# Install dependencies -RUN bun install +# Install frontend dependencies +RUN cd frontend && npm install + +# Copy frontend source code +COPY frontend ./frontend + +# Build frontend +RUN cd frontend && npm run build -# Build stage -FROM oven/bun as builder +# Backend deps & build stage +FROM oven/bun as backend-builder WORKDIR /app -# Set NODE_ENV for build process -ENV NODE_ENV="production" +# Copy backend package files +COPY package.json ./ +COPY backend/package.json ./backend/ +COPY backend/drizzle.config.ts ./backend/ -# Copy all files from deps stage including node_modules -COPY --from=deps /app ./ +# Install backend dependencies +RUN cd backend && bun install -# Copy source code -COPY . . +# Copy backend source code +COPY backend ./backend -# Build both frontend and backend -RUN bun run build +# Build backend +RUN cd backend && bun run build # Production stage FROM oven/bun as production WORKDIR /app -# Create directory for mount with correct permissions -RUN mkdir -p /.data/db /.data/cache && \ - chown -R bun:bun /.data +# Install LiteFS dependencies +RUN apt-get update -y && apt-get install -y ca-certificates fuse3 sqlite3 -# Copy only necessary files from builder -COPY --from=builder --chown=bun:bun /app/package.json /app/bun.lockb /app/turbo.json ./ -COPY --from=builder --chown=bun:bun /app/node_modules ./node_modules -COPY --from=builder --chown=bun:bun /app/frontend/dist ./frontend/dist -COPY --from=builder --chown=bun:bun /app/backend/dist ./backend/dist +# Copy LiteFS binary +COPY --from=flyio/litefs:0.5 /usr/local/bin/litefs /usr/local/bin/litefs + +# Create directories for mounts with correct permissions +RUN mkdir -p /litefs /var/lib/litefs && \ + chown -R bun:bun /litefs /var/lib/litefs + +# Create volume mount points +# Copy only necessary files from builders +COPY --from=backend-builder --chown=bun:bun /app/package.json ./ +COPY --chown=bun:bun curate.config.json ./ + +COPY --from=frontend-builder --chown=bun:bun /app/frontend/dist ./frontend/dist +COPY --from=backend-builder --chown=bun:bun /app/backend ./backend + +RUN cd backend && bun install # Set environment variables -ENV DATABASE_URL="file:/.data/db/sqlite.db" -ENV CACHE_DIR="/.data/cache" +ENV DATABASE_URL="file:/litefs/db" ENV NODE_ENV="production" +ENV FRONTEND_DIST_PATH="/app/frontend/dist" # Expose the port EXPOSE 3000 -# Start the application using the production start script -CMD ["bun", "run", "start"] +# Copy LiteFS configuration +COPY --chown=bun:bun litefs.yml /etc/litefs.yml + +# Start LiteFS (runs app with distributed file system for SQLite) +ENTRYPOINT ["litefs", "mount"] diff --git a/README.md b/README.md index 6f8504b..cc96158 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,10 @@
- Bot to curate and to streamline public goods news + Bot to curate and to streamline to different news feeds