-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DDEX publisher module scaffolding (#7381)
- Loading branch information
1 parent
6808b34
commit ab0ab02
Showing
15 changed files
with
365 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
NODE_ENV='stage' | ||
DDEX_KEY='49d5e13d355709b615b7cce7369174fb240b6b39' | ||
DDEX_SECRET='2b2c2b90d9a489234ae629a5284de84fb0633306257f17667aaebf2345d92152' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module.exports = { | ||
root: true, | ||
env: { node: true, es2020: true }, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'prettier', | ||
'plugin:prettier/recommended', | ||
], | ||
ignorePatterns: ['dist', '.eslintrc.cjs'], | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['prettier'], | ||
rules: { | ||
'@typescript-eslint/no-unsafe-call': 'off', | ||
'@typescript-eslint/no-unsafe-assignment': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
'@typescript-eslint/no-non-null-assertion': 'off', | ||
'@typescript-eslint/no-empty-function': 'off', | ||
'prettier/prettier': ['error', { | ||
singleQuote: true, | ||
semi: false, | ||
useTabs: false, | ||
tabWidth: 2, | ||
trailingComma: 'es5', | ||
printWidth: 80, | ||
bracketSpacing: true, | ||
arrowParens: 'always', | ||
}], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
FROM node:18-alpine AS base | ||
|
||
ARG TURBO_TEAM | ||
ENV TURBO_TEAM=$TURBO_TEAM | ||
|
||
ARG TURBO_TOKEN | ||
ENV TURBO_TOKEN=$TURBO_TOKEN | ||
|
||
# First stage: Set up a minimal monorepo | ||
FROM base AS turbo-builder | ||
|
||
RUN apk add --no-cache libc6-compat | ||
RUN apk update | ||
|
||
WORKDIR /app | ||
RUN npm install turbo --global | ||
|
||
COPY . . | ||
RUN turbo prune --scope=@audius/ddex-publisher --scope=@audius/ddex-publisher --docker | ||
|
||
# Second stage: Install and build client and server dists | ||
FROM base AS app-builder | ||
|
||
WORKDIR /app | ||
RUN apk add --no-cache python3 py3-pip make g++ curl bash libc6-compat git | ||
RUN apk update | ||
|
||
# First install dependencies (as they change less often) | ||
COPY .gitignore .gitignore | ||
COPY --from=turbo-builder /app/out/json/ . | ||
COPY --from=turbo-builder /app/out/package-lock.json ./package-lock.json | ||
COPY --from=turbo-builder /app/scripts ./scripts | ||
|
||
RUN CI=true npm i | ||
|
||
# Build the app and its dependencies | ||
COPY --from=turbo-builder /app/out/full/ . | ||
COPY svgr-template.js svgr-template.js | ||
COPY turbo.json turbo.json | ||
RUN npx turbo run build --filter=@audius/ddex-publisher --filter=@audius/ddex-publisher | ||
|
||
# Make a smaller image by removing all src directories (except for in node_modules) | ||
RUN find packages -path '*/node_modules/*' -prune -o -name 'src' -type d -exec rm -rf {} + | ||
|
||
# Final stage: Create a runnable image | ||
FROM node:18-alpine AS runner | ||
|
||
RUN apk add --no-cache python3 py3-pip make g++ curl bash libc6-compat | ||
RUN apk update | ||
|
||
RUN addgroup --system --gid 1001 nodejs | ||
RUN adduser --system --uid 1001 nodejs | ||
USER nodejs | ||
|
||
WORKDIR /app | ||
COPY --from=app-builder --chown=nodejs:nodejs /app . | ||
WORKDIR /app/packages/ddex/publisher | ||
|
||
EXPOSE 9001 | ||
CMD ["node", "dist/index.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Audius DDEX Publisher | ||
|
||
Server that publishes DDEX entities queued for release by the DDEX ingester. | ||
|
||
### Local Dev | ||
Run the server: | ||
1. Make sure you can connect to mongo at `mongodb://mongo:mongo@localhost:27017/ddex` by doing: `docker run --name ddex-mongo -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=mongo -e MONGO_INITDB_ROOT_PASSWORD=mongo -d mongo` | ||
2. At the monorepo root: `npm i` | ||
3. At packages/ddex/publisher: `npm run dev:[stage|prod]` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "@audius/ddex-publisher", | ||
"version": "0.0.1", | ||
"description": "Server that publishes DDEX entities queued for release", | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "tsc", | ||
"start:prod": "NODE_ENV=production node dist/index.js", | ||
"start": "nodemon src/index.ts", | ||
"dev:stage": "NODE_ENV=stage turbo run start --filter=@audius/ddex-publisher", | ||
"dev:prod": "NODE_ENV=production turbo run start --filter=@audius/ddex-publisher", | ||
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
"lint:fix": "eslint --fix src --ext ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
"verify": "concurrently \"npm:build\" \"npm:lint\"" | ||
}, | ||
"keywords": [], | ||
"author": "Audius", | ||
"dependencies": { | ||
"mongodb": "6.3.0", | ||
"mongoose": "8.1.0", | ||
"dotenv": "16.3.1" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "20.11.10", | ||
"typescript": "5.3.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import express, { Express, Request, Response } from 'express' | ||
|
||
export default function createApp() { | ||
/* | ||
* Setup app | ||
*/ | ||
const app: Express = express() | ||
|
||
/* | ||
* Define API routes | ||
*/ | ||
|
||
app.get('/api/health_check', (_req: Request, res: Response) => { | ||
res.status(200).send('DDEX publisher is alive!') | ||
}) | ||
|
||
return app | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import dotenv from 'dotenv' | ||
import path from 'path' | ||
|
||
// Load env vars based on NODE_ENV | ||
const envFile = process.env.NODE_ENV === 'stage' ? '.env.stage' : '.env' | ||
dotenv.config({ path: path.resolve(process.cwd(), envFile) }) | ||
|
||
import createApp from './app' | ||
import { dialDb } from './services/dbService' | ||
|
||
const port = process.env.DDEX_PORT || 9001 | ||
|
||
;(async () => { | ||
try { | ||
const dbUrl = | ||
process.env.DDEX_MONGODB_URL || | ||
'mongodb://mongo:mongo@localhost:27017/ddex?authSource=admin' | ||
await dialDb(dbUrl) | ||
|
||
const app = createApp() | ||
|
||
app.listen(port, () => { | ||
console.log(`[server]: Server is running at http://localhost:${port}`) | ||
}) | ||
} catch (error) { | ||
console.error('Failed to initialize:', error) | ||
process.exit(1) | ||
} | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import mongoose from 'mongoose' | ||
|
||
export const dialDb = async (dbUrl: string) => { | ||
await mongoose.connect(dbUrl) | ||
console.log('MongoDB connected...') | ||
} |
Oops, something went wrong.