Skip to content

Commit

Permalink
feat: Microservice for handling Auth0 actions requests (#264)
Browse files Browse the repository at this point in the history
* feat: Microservice for handling Auth0 actions requests (#263)

* feat(ci): Update github actions for auth0-actions microservice

---------

Co-authored-by: Abhinav M M <[email protected]>
  • Loading branch information
alllenshibu and Abhinavmohanan authored Feb 4, 2024
1 parent fa5861a commit 82e8917
Show file tree
Hide file tree
Showing 13 changed files with 264 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ updates:
directory: "/apps/core-admin"
schedule:
interval: "weekly"
- package-ecosystem: "npm"
directory: "/apps/core-auth0-actions"
schedule:
interval: "weekly"
- package-ecosystem: "npm"
directory: "/apps/web-admin"
schedule:
Expand Down
30 changes: 26 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- main

jobs:
build-and-push:
build-and-push-core-admin:
runs-on: ubuntu-latest

steps:
Expand All @@ -20,10 +20,32 @@ jobs:
docker tag techno-event-core-admin ${{ secrets.DOCKER_USER }}/techno-event-core-admin:latest
docker push ${{ secrets.DOCKER_USER }}/techno-event-core-admin:latest
redeploy-backend:
needs: build-and-push
redeploy-core-admin:
needs: build-and-push-core-admin
runs-on: ubuntu-latest
steps:
- name: Call deploy hook
run: |
curl -X GET ${{ secrets.BACKEND_DEPLOY_HOOK }}
curl -X GET ${{ secrets.CORE_ADMIN_DEPLOY_HOOK }}
build-and-push-core-auth0-actions:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- run: |
docker build -t techno-event-core-auth0-actions -f apps/core-auth0-actions/Dockerfile .
- run: |
docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }}
- run: |
docker tag techno-event-core-auth0-actions ${{ secrets.DOCKER_USER }}/techno-event-core-auth0-actions:latest
docker push ${{ secrets.DOCKER_USER }}/techno-event-core-auth0-actions:latest
redeploy-core-auth0-actions:
needs: build-and-push-core-auth0-actions
runs-on: ubuntu-latest
steps:
- name: Call deploy hook
run: |
curl -X GET ${{ secrets.CORE_AUTH0_ACTIONS_DEPLOY_HOOK }}
4 changes: 0 additions & 4 deletions apps/core-admin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ const jwtCheck = auth({
tokenSigningAlg: 'RS256',
});

import { addNewUserToDatabaseOnRegister } from './controllers/newuser';

app.get('/', (req: Request, res: Response) => {
return res.send('Techno Event Server');
});
Expand All @@ -48,8 +46,6 @@ app.get('/health', (req: Request, res: Response) => {
}
});

app.post('/api/auth/newuser', addNewUserToDatabaseOnRegister);

app.use(jwtCheck);

import router from './routes';
Expand Down
2 changes: 2 additions & 0 deletions apps/core-auth0-actions/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
build
4 changes: 4 additions & 0 deletions apps/core-auth0-actions/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ['custom'],
};
22 changes: 22 additions & 0 deletions apps/core-auth0-actions/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM node:16-alpine AS builder
RUN apk update && apk add --no-cache libc6-compat
RUN corepack enable && corepack prepare [email protected] --activate

WORKDIR /app

RUN npm install turbo

COPY ../../. .

RUN pnpm install

RUN pnpm run build --filter=core-auth0-actions...

FROM node:18-alpine

COPY --from=builder /app/apps/core-auth0-actions/dist .
COPY --from=builder /app/node_modules/.pnpm/@prisma+client*/node_modules/.prisma/client/*.node .

ENV PORT=80

CMD ["app.js"]
46 changes: 46 additions & 0 deletions apps/core-auth0-actions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "core-auth0-actions",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "npm run clean & webpack --config webpack.config.js",
"clean": "rimraf dist & rimraf build",
"dev": "concurrently \"npx tsc --watch\" \"nodemon -q build/index.js\"",
"start": "node dist/app.js",
"lint": "eslint --ext .ts src"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^16.0.3",
"express": "^4.18.2",
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"database": "workspace:*"
},
"devDependencies": {
"@types/chai": "^4.3.5",
"@types/express": "^4.17.17",
"@types/node": "^20.10.5",
"@types/pg": "^8.10.1",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"concurrently": "^8.0.1",
"eslint": "^8.56.0",
"eslint-config-custom": "*",
"eslint-config-standard-with-typescript": "^43.0.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^16.5.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-promise": "^6.1.1",
"nodemon": "^3.0.1",
"prettier": "3.1.1",
"rimraf": "^5.0.1",
"ts-loader": "^9.5.1",
"tsconfig": "workspace:*",
"typescript": "^5.0.4",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4"
}
}
File renamed without changes.
39 changes: 39 additions & 0 deletions apps/core-auth0-actions/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import express, { Request, Response } from 'express';
import dotenv from 'dotenv';
import { addNewUserToDatabaseOnRegister } from './controllers/newuser';

const bodyParser = require('body-parser');
const cors = require('cors');
dotenv.config();

const port = process.env.PORT || 80;

const app = express();
app.use(
cors({
origin: '*',
}),
);
app.use(bodyParser.json());

app.get('/health', (req: Request, res: Response) => {
const healthcheck: any = {
resource: 'Techno Auth0 Actions Server',
uptime: process.uptime(),
responseTime: process.hrtime(),
message: 'OK',
timestamp: Date.now(),
};
try {
res.send(healthcheck);
} catch (error) {
healthcheck.message = error;
res.status(503).send();
}
});

app.post('/api/auth/newuser', addNewUserToDatabaseOnRegister);

app.listen(port, () => {
console.log(`Server is running at http://localhost:${port}`);
});
7 changes: 7 additions & 0 deletions apps/core-auth0-actions/src/utils/database.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { PrismaClient } = require('database');

const prisma = new PrismaClient({
datasourceUrl: process.env.DATABASE_URL,
});

export default prisma;
9 changes: 9 additions & 0 deletions apps/core-auth0-actions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "tsconfig/tsconfig.json",
"compilerOptions": {
"outDir": "./build/",
"esModuleInterop": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
23 changes: 23 additions & 0 deletions apps/core-auth0-actions/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const path = require('path');

module.exports = {
target: 'node',
entry: './src/index.ts',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'app.js',
},
mode: 'production',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
};
82 changes: 82 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit 82e8917

Please sign in to comment.