Skip to content

Commit

Permalink
Merge pull request #4 from Sivanwol/user_profile
Browse files Browse the repository at this point in the history
User profile
  • Loading branch information
Sivanwol authored Sep 16, 2024
2 parents b1e6897 + 8a5d591 commit 905784a
Show file tree
Hide file tree
Showing 175 changed files with 7,192 additions and 1,524 deletions.
22 changes: 22 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.env

dockerfile
./**/*/dockerfile

.dockerignore

node_modules
./**/*/node_modules

pnpm-debug.log
./**/*/pnpm-debug.log
.next
./**/*/.next
dist
./**/*/dist
.turbo
./**/*/.turbo
.output
./**/*/.output
README.md
.git
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ NEXT_PUBLIC_AUTH_DESCOPE_ID=""
AUTH_DESCOPE_SECRET=""
AUTH_DESCOPE_ISSUER=""
AUTH_DESCOPE_MGT_KEY=""
AUTH_DESCOPE_MAIN_TENANT_ID=""
# In case you're using the Auth Proxy (apps/auth-proxy)
# AUTH_REDIRECT_PROXY_URL='https://auth.your-server.com/r'
NEXT_PUBLIC_BETTER_LOGS_TOKEN=""
3 changes: 3 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
node-linker=hoisted
strict-peer-dependencies=false
save-workspace-protocol=false
prefer-workspace-packages=true
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/*/next.config.cjs
**/*/next.config.mjs
17 changes: 3 additions & 14 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,7 @@
"next/dist/client/router.d.ts"
],
"typescript.tsdk": "node_modules/typescript/lib",
"sqltools.connections": [
{
"pgOptions": {
"ssl": {
"rejectUnauthorized": true
}
},
"previewLimit": 50,
"server": "localhost",
"driver": "PostgreSQL",
"connectString": "postgres://default:tUW0yLFZHVh7@ep-cool-dew-a2z4kc7y-pooler.eu-central-1.aws.neon.tech:5432/verceldb?sslmode=require",
"name": "Remote Local PDB"
}
]
"[jsonc]": {
"editor.defaultFormatter": "svipas.prettier-plus"
}
}
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ packages
├─ validators
| └─ all validators both platform and backoffice
└─ ui
└─ Start of a UI package for the webapp using shadcn-ui(will be removed later) , flowbite-react and mui (some element not existed in the first so use both)
└─ Start of a UI package for the webapp using shadcn-ui(will be removed later) , tailwind and mui (some element not existed in the first so use both)
tooling
├─ eslint
| └─ shared, fine-grained, eslint presets
Expand All @@ -75,7 +75,44 @@ tooling
```

> In this template, we use `@app` as a placeholder for package names. As a user, you might want to replace it with your own organization or project name. You can use find-and-replace to change all the instances of `@app` to something like `@my-company` or `@project-name`.
## Docker

To get it running with docker, follow the steps below:

Inside `next.config.mjs` set, you can read more about why we need to set this here: https://nextjs.org/docs/advanced-features/output-file-tracing

```diff
output: "standalone",
```

Option 1:

1. Build and run the images with:

```bash
docker compose up --build
# You can specify a specific service: docker compose up nextjs --build
```

2. Visit `http://localhost:3000` to see your app.

Option 2:

1. Build the images

```bash
docker compose build
# You can specify a specific service: docker compose build nextjs
```

2. Run the images

```bash
docker compose up
# You can specify a specific service: docker compose up nextjs
```

3. Visit `http://localhost:3000` to see your app.
## Quick Start

> **Note**
Expand Down
8 changes: 5 additions & 3 deletions apps/auth-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
"scripts": {
"build": "nitro build",
"clean": "rm -rf .turbo .output .nitro node_modules",
"lint": "eslint",
"format": "prettier --check . --ignore-path ../../.gitignore",
"lint": "eslint",
"sort:packages": "sort-package-json",
"typecheck": "tsc --noEmit"
},
"prettier": "@app/prettier-config",
"dependencies": {
"@auth/core": "0.32.0"
},
Expand All @@ -22,7 +24,7 @@
"h3": "^1.12.0",
"nitropack": "^2.9.7",
"prettier": "catalog:",
"sort-package-json": "catalog:",
"typescript": "catalog:"
},
"prettier": "@app/prettier-config"
}
}
8 changes: 5 additions & 3 deletions apps/backoffice-auth-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
"scripts": {
"build": "nitro build",
"clean": "rm -rf .turbo .output .nitro node_modules",
"lint": "eslint",
"format": "prettier --check . --ignore-path ../../.gitignore",
"lint": "eslint",
"sort:packages": "sort-package-json",
"typecheck": "tsc --noEmit"
},
"prettier": "@app/prettier-config",
"dependencies": {
"@auth/core": "0.32.0"
},
Expand All @@ -22,7 +24,7 @@
"h3": "^1.12.0",
"nitropack": "^2.9.7",
"prettier": "catalog:",
"sort-package-json": "catalog:",
"typescript": "catalog:"
},
"prettier": "@app/prettier-config"
}
}
17 changes: 17 additions & 0 deletions apps/backoffice/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.env

Dockerfile
./**/*/Dockerfile

.dockerignore

node_modules
./**/*/node_modules

pnpm-debug.log
./**/*/pnpm-debug.log
./**/*/dist

README.md
.next
.git
96 changes: 96 additions & 0 deletions apps/backoffice/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
FROM node:20-alpine AS base
RUN apk add python3 make g++ gcc libc-dev linux-headers libc6-compat
RUN npm install -g turbo
RUN corepack enable
RUN corepack prepare [email protected] --activate

FROM base AS builder
WORKDIR /app
RUN echo -e "\e[1;33mInstall globally packages for application backoffice\e[0m"
COPY . .
RUN turbo prune --scope=@app/backoffice --docker

FROM base AS installer
WORKDIR /app
RUN echo -e "\e[1;33mWired environment variables for application backoffice\e[0m"
ARG TURBO_TEAM
ARG TURBO_TOKEN

ENV TURBO_TEAM $TURBO_TEAM
ENV TURBO_TOKEN $TURBO_TOKEN
ENV CI true
ENV SKIP_ENV_VALIDATION true

# Set environment variables for application

ARG POSTGRES_URL
ARG BLOB_STORAGE_URL
ARG BLOB_READ_WRITE_TOKEN
ARG KV_URL
ARG KV_REST_API_URL
ARG BLOB_READ_WRITE_TOKEN
ARG KV_REST_API_READ_ONLY_TOKEN
ARG EDGE_CONFIG
ARG AUTH_SECRET
ARG NEXT_PUBLIC_AUTH_DESCOPE_ID
ARG AUTH_DESCOPE_SECRET
ARG AUTH_DESCOPE_ISSUER
ARG AUTH_DESCOPE_MGT_KEY
ARG AUTH_DESCOPE_MAIN_TENANT_ID
ARG NEXT_PUBLIC_BETTER_LOGS_TOKEN

ENV POSTGRES_URL ${POSTGRES_URL}
ENV BLOB_STORAGE_URL ${BLOB_STORAGE_URL}
ENV KV_URL ${KV_URL}
ENV KV_REST_API_URL ${KV_REST_API_URL}
ENV KV_REST_API_TOKEN ${KV_REST_API_TOKEN}
ENV KV_REST_API_READ_ONLY_TOKEN ${KV_REST_API_READ_ONLY_TOKEN}
ENV EDGE_CONFIG ${EDGE_CONFIG}
ENV AUTH_SECRET ${AUTH_SECRET}
ENV NEXT_PUBLIC_AUTH_DESCOPE_ID ${NEXT_PUBLIC_AUTH_DESCOPE_ID}
ENV AUTH_DESCOPE_SECRET ${AUTH_DESCOPE_SECRET}
ENV AUTH_DESCOPE_ISSUER ${AUTH_DESCOPE_ISSUER}
ENV AUTH_DESCOPE_MGT_KEY ${AUTH_DESCOPE_MGT_KEY}
ENV AUTH_DESCOPE_MAIN_TENANT_ID ${AUTH_DESCOPE_MAIN_TENANT_ID}
ENV NEXT_PUBLIC_BETTER_LOGS_TOKEN ${NEXT_PUBLIC_BETTER_LOGS_TOKEN}

RUN echo -e "\e[1;33mENVIRONMENT VARIABLES\e[0m";
# Create a .env file with all the environment variables but CI
RUN env >> .env
RUN cat .env

RUN echo -e "\e[1;33mBuilding application backoffice\e[0m"
# First install dependencies (as they change less often)
COPY --from=builder /app/out/json .
COPY --from=builder /app/out/pnpm-lock.yaml ./
COPY --from=builder /app/out/full .
RUN pnpm install
RUN pnpm build --filter=@app/backoffice

FROM base AS runner
WORKDIR /app

ENV NEXT_TELEMETRY_DISABLED 1
# Don't run production as root
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
USER nextjs
# COPY --from=installer --chown=nextjs:nodejs /app/apps/backoffice/.next/standalone /app/apps/backoffice
COPY --from=installer /app/apps/backoffice/next.config.mjs .
COPY --from=installer /app/apps/backoffice/package.json .

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing

COPY --from=installer --chown=nextjs:nodejs /app/apps/backoffice/.next ./
COPY --from=installer --chown=nextjs:nodejs /app/apps/backoffice/.next/standalone ./
COPY --from=installer --chown=nextjs:nodejs /app/apps/backoffice/.next/static ./standalone/apps/backoffice/.next/static
COPY --from=installer --chown=nextjs:nodejs /app/apps/backoffice/public ./standalone/apps/backoffice/public
COPY --from=installer /app/.env .
RUN ls -la ./standalone/apps/backoffice

RUN echo -e "\e[1;33mRunning application backoffice\e[0m"
EXPOSE 3000
ENV PORT 3000
CMD ["sh", "-c", "node --experimental-modules ./standalone/apps/backoffice/server.js"]
RUN echo -e "\e[1;33mApplication backoffice is running deployment done\e[0m"
19 changes: 19 additions & 0 deletions apps/backoffice/ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
apps: [
{
name: "backoffice",
script: "npm",
args: "run start:docker",
env: {
PORT: 3001,
},
// Additional settings
instances: 1, // Number of instances to run
autorestart: true, // Automatically restart the app if it crashes
watch: false, // Disable watching file changes
max_restarts: 5, // Limit the number of restart attempts
restart_delay: 1000, // Delay between restart attempts in milliseconds
max_memory_restart: "300M", // Restart the app if it exceeds 300MB memory usage
},
],
};
33 changes: 26 additions & 7 deletions apps/backoffice/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
// @ts-nocheck
import path from "path";
import { fileURLToPath } from "url";
import createJiti from "jiti";

/**
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation.
* This is especially useful for Docker builds and Linting.
*/
console.log("process.env.SKIP_ENV_VALIDATION", process.env.SKIP_ENV_VALIDATION);
console.log("process.env.NODE_ENV", process.env.NODE_ENV);
console.log("pwd", process.cwd());

// Import env files to validate at build time. Use jiti so we can load .ts files in here.
createJiti(fileURLToPath(import.meta.url))("./src/env");
!process.env.SKIP_ENV_VALIDATION &&
createJiti(fileURLToPath(import.meta.url))("./src/env");
/** @type {import("next").NextConfig} */
const config = {
reactStrictMode: true,

productionBrowserSourceMaps: true,
webpack(config) {
config.module.rules.push({
test: /\.svg$/,
use: ["@svgr/webpack"],
});
config.resolve.fallback = {
...config.resolve.fallback, // if you miss it, all the other options in fallback, specified
// by next.js will be dropped. Doesn't make much sense, but how it is
fs: false, // the solution
};
return config;
},
optimization: {
minimize: false,
},

async headers() {
return [
Expand Down Expand Up @@ -57,6 +66,8 @@ const config = {
// 'next-intl/config': './src/i18n.ts',
// },
// },

esmExternals: true,
instrumentationHook: true,
},
images: {
Expand All @@ -67,9 +78,17 @@ const config = {
},
],
},

logging: {
fetches: {
fullUrl: true,
},
},
/** We already do linting and typechecking as separate tasks in CI */
eslint: { ignoreDuringBuilds: true },
typescript: { ignoreBuildErrors: true },
// output: "standalone",
};

// export default withTm(config);
export default config;
Loading

0 comments on commit 905784a

Please sign in to comment.