Skip to content
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
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }}
35 changes: 33 additions & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ RUN bun install --frozen-lockfile --production
# Build stage
FROM base AS builder

ARG SENTRY_AUTH_TOKEN
ENV SENTRY_AUTH_TOKEN=${SENTRY_AUTH_TOKEN}

# Copy package files
COPY package.json bun.lock* ./

Expand Down Expand Up @@ -52,6 +55,9 @@ RUN apt-get update && \
COPY src ./src
COPY tsconfig.json ./tsconfig.json

# Build bundle
RUN bun run server:build

# Production stage
FROM base AS runner

Expand All @@ -67,10 +73,9 @@ COPY --from=builder /app/prisma/generated ./prisma/generated
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/prisma.config.ts ./prisma.config.ts

# Copy source code
COPY --from=builder /app/src ./src
# Copy built bundle
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/tsconfig.json ./tsconfig.json

# Create non-root user for security
RUN groupadd -r metorial && useradd -r -g metorial metorial && \
Expand All @@ -86,4 +91,4 @@ HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
CMD curl -f http://localhost:52030/ping && curl -f http://localhost:12121/ || exit 1

# Start command: push schema and start service
CMD ["sh", "-c", "bun prisma db push --accept-data-loss && bun src/server.ts"]
CMD ["sh", "-c", "bun prisma db push --accept-data-loss && bun ./dist/index.js"]
9 changes: 7 additions & 2 deletions service/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"name": "function-bay-service",
"module": "index.ts",
"type": "module",
"type": "commonjs",
"private": true,
"scripts": {
"start": "bun ./src/server.ts",
"start": "bun run server:start",
"server:build": "ncc build ./src/server.ts -o ./dist --source-map --transpile-only && bun run sentry:sourcemaps",
"sentry:sourcemaps": "sentry-cli sourcemaps inject --org metorial --project mte-function-bay ./dist && sentry-cli sourcemaps upload --org metorial --project mte-function-bay ./dist",
"server:start": "bun ./dist/index.js",
"dev": "bun --watch ./src/server.ts",
"infra:up": "docker compose -p function-bay -f ./docker-compose.dev.yml --profile infra up -d --pull always",
"infra:down": "docker compose -p function-bay -f ./docker-compose.dev.yml --profile infra down",
Expand All @@ -21,6 +24,7 @@
"@lowerdeck/testing-tools": "^1.0.1",
"@types/bun": "latest",
"@types/lodash": "^4.17.23",
"@vercel/ncc": "^0.38.1",
"vitest": "4.0.17"
},
"peerDependencies": {
Expand Down Expand Up @@ -54,6 +58,7 @@
"@prisma/adapter-pg": "^7.2.0",
"@prisma/client": "^7.2.0",
"@sentry/bun": "^10.38.0",
"@sentry/cli": "^3.2.0",
"date-fns": "^4.1.0",
"jszip": "^3.10.1",
"lodash": "4.17.21",
Expand Down
22 changes: 18 additions & 4 deletions service/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
await import('./init');
await import('./instrument');
await import('./endpoints');
await import('./worker');
import { createRequire } from 'module';

// Provide CommonJS `require` in ESM runtime for bundled deps.
const require = createRequire(import.meta.url);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(globalThis as any).require = require;

async function main() {
await import('./init');
await import('./instrument');
await import('./endpoints');
await import('./worker');
}

main().catch(err => {
console.error(err);
process.exit(1);
});
1 change: 0 additions & 1 deletion service/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

Expand Down