Skip to content

Commit

Permalink
feat(user): add login / logout
Browse files Browse the repository at this point in the history
  • Loading branch information
lionelB committed May 21, 2020
1 parent 07604c4 commit 1c46109
Show file tree
Hide file tree
Showing 89 changed files with 13,505 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["next/babel"]
}
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.git
.github
.k8s
*.md
**/node_modules
**/.next/cache
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Editor configuration, see http://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false
19 changes: 19 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
##
## Frontend env
##

# Hasura endpoint
GRAPHQL_ENDPOINT=http://localhost:8080/v1/graphql

# JWT lifetime (15min)
JWT_TOKEN_EXPIRES=15

# Refresh token lifetime (30 days in minutes)
REFRESH_TOKEN_EXPIRES=43200

# Activation token lifetime (7 days in minutes)
ACTIVATION_TOKEN_EXPIRES=10080

# Email
ACCOUNT_MAIL_SENDER=contact@fabrique.social.gouv.fr
NEXT_PUBLIC_FRONTEND_URL=http://localhost:3000
25 changes: 25 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
##
## Hasura
##
ACCOUNT_EMAIL_WEBHOOK_URL=http://host.docker.internal:3000/api/webhooks/account

##
## frontend secrets
##

# Mail
SMTP_URL=smtp.url
SMTP_EMAIL_USER=email
SMTP_EMAIL_PASSWORD=pass


##
## Shared secret between hasura and frontend
##

# Hasura
HASURA_GRAPHQL_ADMIN_SECRET=admin1
HASURA_GRAPHQL_JWT_SECRET={"type": "HS256", "key": "a_pretty_long_secret_key_that_should_be_at_least_32_char"}

# webhook
ACCOUNT_EMAIL_SECRET=a random string that will be verify when calling the webhook
17 changes: 17 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": [
"@socialgouv/eslint-config-recommended",
"@socialgouv/eslint-config-react"
],
"settings": {
"import/resolver": {
"node": {
"moduleDirectory": ["node_modules", "."]
}
}
},
"rules": {
"jsx-a11y/anchor-is-valid": "warn",
"react/prop-types": "warn"
}
}
3 changes: 3 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["github>SocialGouv/renovate-config", ":automergeAll"]
}
24 changes: 24 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 60

# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7

# Issues with these labels will never be considered stale
exemptLabels:
- help wanted

# Label to use when marking an issue as stale
staleLabel: wontfix

# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs.
Mark it with `help wanted` label if don't want it to be considered stale.
Thank you for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: >
This issue has been automatically closed because no further activity occurs...
Feel free to re-open it :robot:
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.next
*.DS_Store
node_modules
60 changes: 60 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
include:
- project: SocialGouv/gitlab-ci-yml
file: /autodevops_simple_app.yml
ref: v15.6.0

variables:
PORT: 3000
PROJECT: "cdtn-admin"
ENABLE_AZURE_POSTGRES: 1
VALUES_FILE: ./.k8s/app.values.yml

Create namespace:
extends:
- .autodevops_create_namespace
after_script:
# Copy namespace default creds
- kubectl get secret cdtn-admin-secrets --namespace=cdtn-admin-secret --export -o yaml |
kubectl apply --namespace=${K8S_NAMESPACE} -f -

Create Azure DB (dev):
extends: .autodevops_create_azure_db_dev
variables:
NEW_DB_EXTENSIONS: "pgcrypto hstore citext"

Register image Hasura:
extends: .autodevops_register_image
dependencies: []
needs: []
variables:
CONTEXT: ./hasura
DOCKERFILE_PATH: Dockerfile
IMAGE_NAME: $CI_REGISTRY_IMAGE/hasura

Deploy app (dev):
extends: .autodevops_deploy_app_dev

.deploy_hasura:
extends:
- .deploy_app_stage
variables:
PORT: 80
CONTEXT: hasura
VALUES_FILE: ./.k8s/hasura.values.yml

Deploy app Hasura (dev):
extends:
- .autodevops_deploy_app_dev
- .deploy_hasura
variables:
PG_HOST: cdtnadmin.postgres.database.azure.com
HELM_RENDER_ARGS: >-
--set deployment.env[7].name=HASURA_GRAPHQL_DATABASE_URL
--set deployment.env[7].value=postgresql://user_${CI_COMMIT_SHORT_SHA}%40${PG_HOST}:pass_${CI_COMMIT_SHORT_SHA}@${PG_HOST}:5432/db_${CI_COMMIT_SHORT_SHA}?sslmode=require
Deploy app Hasura (prod):
extends:
- .autodevops_deploy_app_prod
- .deploy_hasura
variables:
PRODUCTION: "true"
46 changes: 46 additions & 0 deletions .k8s/app.values.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Default values for Mas webapp. https://github.com/SocialGouv/helm-charts/blob/master/charts/webapp/values.yaml
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

# See https://github.com/SocialGouv/helm-charts/tree/master/charts/app
---
image:
repository: $CI_REGISTRY_IMAGE
tag: master

# nameOverride: app

deployment:
resources:
requests:
cpu: 5m
memory: 128Mi
limits:
cpu: 1000m
memory: 256Mi

livenessProbe:
initialDelaySeconds: 30
path: /health
periodSeconds: 15
readinessProbe:
initialDelaySeconds: 30
path: /health
periodSeconds: 15

env:
- name: PRODUCTION
value: "${PRODUCTION}"
- name: NEXT_PUBLIC_FRONTEND_URL
value: https://${HOST}
- name: GRAPHQL_ENDPOINT
value: "http://hasura-cdtn-admin/v1/graphql"
- name: ACCOUNT_MAIL_SENDER
value: "contact@fabrique.social.gouv.fr"
- name: NEXT_PUBLIC_FRONTEND_URL
value: "${PORT}"
envFrom:
- secretRef:
name:cdtn-admin-secrets
ingress:
enabled: true
43 changes: 43 additions & 0 deletions .k8s/hasura.values.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
image:
repository: $CI_REGISTRY_IMAGE/hasura
tag: master

deployment:
livenessProbe:
path: /healthz
initialDelaySeconds: 30
periodSeconds: 20
readinessProbe:
path: /healthz
initialDelaySeconds: 30
periodSeconds: 20

resources:
requests:
cpu: 5m
memory: 256Mi
limits:
cpu: 1000m
memory: 1024Mi

env:
- name: NODE_ENV
value: "production"
- name: HASURA_GRAPHQL_ENABLE_CONSOLE
value: "false"
- name: HASURA_GRAPHQL_SERVER_PORT
value: "80"
- name: HASURA_GRAPHQL_ENABLED_LOG_TYPES
value: "startup, http-log, webhook-log, websocket-log, query-log"
- name: HASURA_GRAPHQL_NO_OF_RETRIES
value: "5"
- name: HASURA_GRAPHQL_UNAUTHORIZED_ROLE
value: "anonymous"
- name: ACCOUNT_EMAIL_WEBHOOK_URL
value: http://cdtn-admin:3000/api/webhooks/account

envFrom:
- secretRef:
name: cdtn-admin-secrets
ingress:
enabled: false
9 changes: 9 additions & 0 deletions .releaserc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins:
- "@semantic-release/commit-analyzer"
- "@semantic-release/release-notes-generator"
- "@semantic-release/changelog"
- - "@semantic-release/git"
- assets:
- CHANGELOG.md
message: "chore(release): version ${nextRelease.version}\n\n${nextRelease.notes}"
- "@semantic-release/github"
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM node:12.16.2-alpine

WORKDIR /app

COPY package.json yarn.lock ./

RUN yarn --production --frozen-lockfile

COPY next.config.js server.js ./
COPY src/sentry.js ./src/sentry.js
COPY .next/ ./.next

USER node

ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1

CMD ["yarn", "start"]
81 changes: 81 additions & 0 deletions README 2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# sample next.js app [![pipeline status](https://gitlab.factory.social.gouv.fr/SocialGouv/sample-next-app/badges/master/pipeline.svg)](https://gitlab.factory.social.gouv.fr/SocialGouv/sample-next-app/commits/master)

https://sample-next-app.fabrique.social.gouv.Fr

A sample SSR Next.js app with :

- ✅ sentry
- ✅ matomo
- ✅ jest tests
-[@SocialGouv linters](https://github.com/SocialGouv/linters/)
-[@SocialGouv bootstrap](https://github.com/SocialGouv/bootstrap)
-@SocialGouv polyfill.io
- ✅ precommit hooks
- ✅ docker build
- ✅ gitlab-ci
- ✅ quality
- ✅ docker build+push
- ✅ releases + changelog
- ✅ features-branches envs
- ✅ prod env

## Development

Start hasura and local postgres using

```sh
docker-compose up
```

Hasura migrations and metadata will be automatically applied.

to launch the Hasura console, you can run the command

```sh
hasura console --envfile ../.env --project hasura
```

And then launch the frontend (next.js app) using

```sh
yarn dev
```

## Production

### Env vars

⚠ You need to set client-side browser `process.env` variables **at build time**.

In docker this is done with `--build-arg`.

| Var | desc | build time | run time |
| -------------- | -------------------------- | :--------: | :------: |
| PORT | port to run the server on | ||
| SENTRY_DSN | DSN of your sentry project ||
| SENTRY_TOKEN | token to allow sourcemaps ||
| MATOMO_URL | URL to your piwik instance ||
| MATOMO_SITE_ID | site id on piwik instance ||

### Docker build

```sh
docker build \
--build-arg SENTRY_DSN="https://[hash]@url.sentry.com/42" \
--build-arg SENTRY_TOKEN="1234" \
--build-arg MATOMO_URL="https://url.matomo.com" \
--build-arg MATOMO_SITE_ID=42 \
. -t sample-next-app
```

### Docker run

```sh
docker run -it --init --rm -p 3000:3000 sample-next-app
```

## Tips

- 3rd party libs (ex: some of @sindresorhus modules) may not be ES3 compatible (breaks IE11) and wont be babelified by Next.js. You can locally import the code, make a PR to the upstream project to [publish babelified version](https://github.com/elijahmanor/cross-var/pull/7/files) or use [next-transpile-modules](https://github.com/martpie/next-transpile-modules)
- 3rd party libs may needs to be fixed to handle SSR correctly
- Follow https://github.com/zeit/next.js/tree/canary/examples/
Loading

0 comments on commit 1c46109

Please sign in to comment.