Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
feat(directory): Basic directory for psychologists (#27)
Browse files Browse the repository at this point in the history
* Add a basic psychologists pages

* Add a healthz route

* Change type directory

* Add env variables

* Add ts-node

* Test .env

* Add a nice geolocation

* Use proper field

* feat(ci): add seeds command (#28)

* Test .env

* feat: add db deploy

* Use proper DB URL

* fix: use devInitContainerCommand

* Do a db migration in docker

* run db:migrate

* Fix build

Co-authored-by: Desoindx <[email protected]>

* Review

* Update Readme

* Manage 2A and 2B departments

Co-authored-by: Julien Bouquillon <[email protected]>
  • Loading branch information
desoindx and Julien Bouquillon authored Jan 24, 2022
1 parent 5454cc8 commit 3ffcbd8
Show file tree
Hide file tree
Showing 46 changed files with 3,205 additions and 1,549 deletions.
5 changes: 5 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
NEXT_TELEMETRY_DISABLED=1
DATABASE_URL=postgres://monpsysante:monpsysante@localhost:5432/monpsysante
DB_LOGGING_ENABLE=true

DEMARCHES_SIMPLIFIEES_TOKEN=api-token
DEMARCHES_SIMPLIFIEES_ID=52209
DEMARCHES_SIMPLIFIEES_CHAMPS=[["Q2hhbXAtMTYwMzgwNQ==", "phone"], ["Q2hhbXAtMTYyNzkzOQ==", "address"], ["Q2hhbXAtMTYzOTUyNA==", "teleconsultation"], ["Q2hhbXAtMTY2MDM0Nw==", "languages"], ["Q2hhbXAtMTYzOTQwMQ==", "website"], ["Q2hhbXAtMjI0NzExMg==", "cdsmsp"], ["Q2hhbXAtMjIyMjcwMg==", "withChildren"]]
8 changes: 8 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
NEXT_PUBLIC_MATOMO_URL=https://matomo.fabrique.social.gouv.fr
NEXT_PUBLIC_MATOMO_SITE_ID="59"
NEXT_PUBLIC_SENTRY_DSN=https://[email protected]/61

NEXT_TELEMETRY_DISABLED=1
DB_LOGGING_ENABLE=false

DEMARCHES_SIMPLIFIEES_TOKEN=api-token
DEMARCHES_SIMPLIFIEES_ID=52209
DEMARCHES_SIMPLIFIEES_CHAMPS=[["Q2hhbXAtMTYwMzgwNQ==", "phone"], ["Q2hhbXAtMTYyNzkzOQ==", "address"], ["Q2hhbXAtMTYzOTUyNA==", "teleconsultation"], ["Q2hhbXAtMTY2MDM0Nw==", "languages"], ["Q2hhbXAtMTYzOTQwMQ==", "website"], ["Q2hhbXAtMjI0NzExMg==", "cdsmsp"], ["Q2hhbXAtMjIyMjcwMg==", "withChildren"]]

NEXT_PUBLIC_DISPLAY_DIRECTORY=false
8 changes: 8 additions & 0 deletions .env.staging
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
NEXT_TELEMETRY_DISABLED=1
DB_LOGGING_ENABLE=false

DEMARCHES_SIMPLIFIEES_TOKEN=api-token
DEMARCHES_SIMPLIFIEES_ID=52209
DEMARCHES_SIMPLIFIEES_CHAMPS=[["Q2hhbXAtMTYwMzgwNQ==", "phone"], ["Q2hhbXAtMTYyNzkzOQ==", "address"], ["Q2hhbXAtMTYzOTUyNA==", "teleconsultation"], ["Q2hhbXAtMTY2MDM0Nw==", "languages"], ["Q2hhbXAtMTYzOTQwMQ==", "website"], ["Q2hhbXAtMjI0NzExMg==", "cdsmsp"], ["Q2hhbXAtMjIyMjcwMg==", "withChildren"]]

NEXT_PUBLIC_DISPLAY_DIRECTORY=true
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/db/migrations/
src/db/config/
6 changes: 4 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
".js",
".jsx",
".ts",
".tsx"
".tsx",
".d.ts"
]
}
}
Expand All @@ -20,7 +21,8 @@
"jsx-a11y/anchor-is-valid": "off",
"react/prop-types": "off",
"jsx-a11y/label-has-for": "off",
"import/no-unresolved": [2, {"caseSensitive": false}]
"import/no-unresolved": [2, {"caseSensitive": false}],
"react/display-name": "off"
},
"overrides": [
{
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
.eslintcache
coverage
node_modules

.env

out/

.DS_Store
7 changes: 7 additions & 0 deletions .sequelizerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require('path');

module.exports = {
'config': path.resolve('./src/db/config', 'config.js'),
'models-path': path.resolve('./src/db', 'models'),
'migrations-path': path.resolve('./src/db', 'migrations'),
}
9 changes: 3 additions & 6 deletions .socialgouv/config.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{
"name": "app",
"type": "static",
"type": "app",
"subdomain": "monpsy",
"registry": "ghcr",
"project": "mon-psy-sante",
"ingress": {
"annotations": {
"nginx.ingress.kubernetes.io/configuration-snippet": "more_set_headers \"Content-Security-Policy: default-src 'none'; connect-src 'self' https://*.gouv.fr https://services.sarbacane.com; font-src 'self' data:; img-src 'self' data: https://forms.sbc08.com; prefetch-src 'self' https://*.gouv.fr; script-src 'self' https://*.gouv.fr https://*.sbc08.com; frame-src 'self' https://*.gouv.fr; style-src 'self' 'unsafe-inline'\";\nmore_set_headers \"X-Frame-Options: deny\";\nmore_set_headers \"X-XSS-Protection: 1; mode=block\";\nmore_set_headers \"X-Content-Type-Options: nosniff\";"
}
}
"azurepg": true,
"devInitContainerCommand": ["yarn", "db:init"]
}
34 changes: 25 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
ARG PRODUCTION
# from https://nextjs.org/docs/deployment

FROM node:14-alpine as builder
# Builder
FROM node:14-alpine AS builder
RUN apk add --no-cache libc6-compat
WORKDIR /app

COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
COPY . .

RUN yarn install --frozen-lockfile
RUN if [ -z "$PRODUCTION" ]; then cp .env.staging .env.production; cp ./public/robots.staging.txt ./public/robots.txt; fi
RUN yarn build && yarn install --production --ignore-scripts --prefer-offline
RUN yarn export

FROM ghcr.io/socialgouv/docker/nginx:6.64.2
# Production image, copy all the files and run next
FROM node:14-alpine AS runner
WORKDIR /app

ARG PRODUCTION
ENV NODE_ENV production

COPY --from=builder /out /usr/share/nginx/html
# You only need to copy next.config.js if you are NOT using the default configuration
COPY --from=builder /app/next.config.js .
COPY --from=builder /app/sentry.client.config.js .
COPY --from=builder /app/sentry.server.config.js .
COPY --from=builder /app/.sequelizerc .
COPY --from=builder /app/.env.production .
COPY --from=builder /app/package.json .
COPY --from=builder /app/src ./src
COPY --from=builder /app/public ./public
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder --chown=node:node /app/.next ./.next

# Create a robots.txt based on PRODUCTION build argument
RUN if [ ! -z "$PRODUCTION" ]; then echo -e "User-agent: *\nAllow: /">/usr/share/nginx/html/robots.txt; else echo -e "User-agent: *\nDisallow: /">/usr/share/nginx/html/robots.txt; fi
USER node

CMD ["yarn", "start"]
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@ https://monpsy.sante.gouv.fr

# Run locally

First you need to run a docker with a postgre DB
```
docker-compose up
```

then you need to prepare the project
```
yarn
yarn build
npm run dev
yarn run db:init
```

and finally you can run the project locally with
```
yarn run dev
```

17 changes: 17 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "3.6"

services:
db:
image: postgis/postgis:14-master
volumes:
- db_data:/var/lib/postgresql/data
ports:
- "5432:5432"
environment:
POSTGRES_DB: monpsysante
POSTGRES_USER: monpsysante
POSTGRES_PASSWORD: monpsysante
restart: always

volumes:
db_data:
5 changes: 0 additions & 5 deletions jsconfig.json

This file was deleted.

33 changes: 32 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
const nextSourceMaps = require("@zeit/next-source-maps");
const { withSentryConfig } = require("@sentry/nextjs");

const csp = {
'default-src': ["'none'"],
'connect-src': ["'self'", "https://*.gouv.fr", "https://services.sarbacane.com"],
'font-src': ["'self'", "data:"],
'img-src': ["'self'", "data:", "https://forms.sbc08.com"],
'prefetch-src': ["'self'", "https://*.gouv.fr"],
'script-src': ["'self'", "https://*.gouv.fr", "https://*.sbc08.com"],
'frame-src': ["'self'", "https://*.gouv.fr"],
'style-src': ["'self'", "'unsafe-inline'"]
}

// In dev we allow 'unsafe-eval', so HMR doesn't trigger the CSP
if (process.env.NODE_ENV !== 'production') {
csp['script-src'].push("'unsafe-eval'");
}

module.exports = withSentryConfig(
nextSourceMaps({
// by default, sentry tries to upload sourcemaps at build time
Expand All @@ -12,8 +28,23 @@ module.exports = withSentryConfig(
webpack: (config, { isServer /*, buildId */ }) => {
if (!isServer) {
config.resolve.alias["@sentry/node"] = "@sentry/browser";
config.resolve.fallback = {
fs: false,
path: false,
os: false,
};
}
return config;
},
})
async headers() {
return [
{
source: '/:path*',
headers: [{
key: "Content-Security-Policy",
value: Object.keys(csp).map(key => `${key} ${csp[key].join(" ")}`).join(";")
}],
},
]
}, })
);
33 changes: 26 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,42 @@
"url": "git+https://github.com/SocialGouv/mon-psy-sante"
},
"dependencies": {
"@dataesr/react-dsfr": "^0.9.7",
"@dataesr/react-dsfr": "^0.9.8",
"@sentry/nextjs": "^6.16.1",
"@socialgouv/bootstrap.core": "^0.2.1",
"@socialgouv/matomo-next": "^1.2.2",
"@typescript-eslint/eslint-plugin": "^5.9.0",
"@types/faker": "^5.5.9",
"@types/sequelize": "^4.28.11",
"@typescript-eslint/eslint-plugin": "^5.9.1",
"@zeit/next-source-maps": "^0.0.3",
"axios": "^0.24.0",
"cron": "^1.8.2",
"dotenv": "^11.0.0",
"faker": "^5.5.3",
"graphql": "^16.2.0",
"graphql-request": "^3.7.0",
"helmet": "^5.0.1",
"next": "^12.0.7",
"pg": "^8.7.1",
"pg-hstore": "^2.3.4",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"sequelize": "^6.13.0",
"sequelize-cli": "^6.3.0",
"ts-node": "^10.4.0",
"typescript-eslint": "^0.0.1-alpha.0"
},
"devDependencies": {
"@commitlint/cli": "^16.0.1",
"@commitlint/cli": "^16.0.2",
"@commitlint/config-conventional": "^16.0.0",
"@socialgouv/eslint-config-react": "^1.101.0",
"@socialgouv/eslint-config-recommended": "^1.101.0",
"@types/react": "^17.0.38",
"eslint": "^8.6.0",
"eslint-config-next": "^12.0.7",
"eslint-plugin-import": "^2.25.4",
"jest": "^27.4.5",
"lint-staged": "^12.1.5",
"jest": "^27.4.7",
"lint-staged": "^12.1.7",
"prettier": "^2.5.1",
"typescript": "^4.5.4"
},
Expand All @@ -46,7 +60,12 @@
"lint": "eslint ./src",
"lint:fix": "eslint ./src --fix",
"precommit": "lint-staged",
"start": "NODE_ENV=production next start",
"export": "next export"
"start": "yarn run db:migrate && NODE_ENV=production next start",
"export": "next export",
"db:init": "yarn run db:migrate && yarn run db:seed",
"db:seed": "ts-node --transpile-only src/db/seeds/index.ts",
"db:migrate": "npx sequelize-cli db:migrate",
"db:migrate:undo": "npx sequelize-cli db:migrate:undo",
"db:migrate:create": "npx sequelize migration:create --name"
}
}
2 changes: 2 additions & 0 deletions public/robots.staging.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
User-agent: *
Disallow: /
2 changes: 2 additions & 0 deletions public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
User-agent: *
Allow: /
Loading

0 comments on commit 3ffcbd8

Please sign in to comment.