Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Successful deploy #10

Merged
merged 3 commits into from
Jan 16, 2025
Merged
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
28 changes: 28 additions & 0 deletions .github/near-rewards.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ WORKDIR /app
# Copy backend package files
COPY package.json ./
COPY backend/package.json ./backend/
COPY backend/drizzle.config.ts ./backend/

# Install backend dependencies
RUN cd backend && bun install
Expand Down Expand Up @@ -57,11 +58,14 @@ 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/dist ./backend/dist
COPY --from=backend-builder --chown=bun:bun /app/backend ./backend

RUN cd backend && bun install

# Set environment variables
ENV DATABASE_URL="file:/litefs/db"
ENV NODE_ENV="production"
ENV FRONTEND_DIST_PATH="/app/frontend/dist"

# Expose the port
EXPOSE 3000
Expand Down
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},
"dependencies": {
"@elysiajs/cors": "^1.2.0",
"@elysiajs/static": "^1.2.0",
"@elysiajs/swagger": "^1.2.0",
"@libsql/client": "^0.14.0",
"@types/cors": "^2.8.17",
Expand Down
40 changes: 23 additions & 17 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from "path";
import { Elysia } from "elysia";
import { cors } from "@elysiajs/cors";
import { swagger } from "@elysiajs/swagger";
import { staticPlugin } from "@elysiajs/static";
import { DistributionService } from "services/distribution/distribution.service";
import configService, { validateEnv } from "./config/config";
import { db } from "./services/db";
Expand Down Expand Up @@ -210,23 +211,28 @@ export async function main() {

return { processed };
})
// Static file serving in production
.get("/*", async ({ request }) => {
if (process.env.NODE_ENV === "production") {
const url = new URL(request.url);
const filePath = url.pathname === "/" ? "/index.html" : url.pathname;
const file = Bun.file(
path.join(__dirname, "../../frontend/dist", filePath),
);
if (await file.exists()) {
return new Response(file);
}
// Fallback to index.html for client-side routing
return new Response(
Bun.file(path.join(__dirname, "../../frontend/dist/index.html")),
);
}
throw new Error("Not found");
// Serve static files in production
.use(
staticPlugin({
assets:
process.env.FRONTEND_DIST_PATH ||
path.join(process.cwd(), "../frontend/dist"),
prefix: "/",
indexHTML: true, // Enable SPA routing
}),
)
.get("/debug/env", () => {
return {
cwd: process.cwd(),
frontendPath:
process.env.FRONTEND_DIST_PATH ||
path.join(process.cwd(), "../frontend/dist"),
resolvedPath: path.resolve(
process.env.FRONTEND_DIST_PATH ||
path.join(process.cwd(), "../frontend/dist"),
),
env: process.env.NODE_ENV,
};
})
.onError(({ error }) => {
logger.error("Request error:", error);
Expand Down
Binary file modified bun.lockb
Binary file not shown.
1 change: 0 additions & 1 deletion fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ primary_region = 'den'
memory = '1gb'
cpu_kind = 'shared'
cpus = 1

1 change: 1 addition & 0 deletions litefs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ proxy:
# the last command to be long-running (e.g. an application server). When the
# last command exits, LiteFS is shut down.
exec:
- cmd: "bun run db:push"
- cmd: "bun run start"

# The lease section specifies how the cluster will be managed. We're using the
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dev": "bunx turbo run dev",
"build": "bunx turbo run build",
"start": "NODE_ENV=production cd backend && bun run dist/index.js",
"db:push": "cd backend && bun run db:push",
"lint": "bunx turbo run lint",
"deploy:init": "fly launch && fly consul attach",
"deploy": "fly deploy",
Expand Down
Loading