Mise en place du projet
This commit is contained in:
parent
ba01f8340e
commit
bf3b56d242
17
Makefile
Normal file
17
Makefile
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
build:
|
||||||
|
docker-compose build
|
||||||
|
|
||||||
|
up: build
|
||||||
|
USER_ID=$(shell id -u) docker-compose up
|
||||||
|
|
||||||
|
sg:
|
||||||
|
docker-compose exec -u $(shell id -u) super-graph sh
|
||||||
|
|
||||||
|
sgr:
|
||||||
|
docker-compose run -u $(shell id -u) super-graph sh
|
||||||
|
|
||||||
|
down:
|
||||||
|
docker-compose down -v --remove-orphans
|
||||||
|
|
||||||
|
db-shell:
|
||||||
|
docker-compose exec postgres psql -Usupergraph
|
58
README.md
Normal file
58
README.md
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
# Daddy
|
||||||
|
|
||||||
|
Application de gestion des Dossiers d'Aide à la Décision (D.A.D.) à Cadoles.
|
||||||
|
|
||||||
|
## Démarrage
|
||||||
|
|
||||||
|
### Avec les sources
|
||||||
|
|
||||||
|
#### Dépendances
|
||||||
|
|
||||||
|
- docker
|
||||||
|
- docker-compose
|
||||||
|
- nodejs avec npm/yarn
|
||||||
|
|
||||||
|
#### Procédure
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://forge.cadoles.com/Cadoles/daddy.git # Cloner le projet
|
||||||
|
cd daddy # Se placer dans le répertoire
|
||||||
|
make up # Démarrer l'environnement de développement
|
||||||
|
```
|
||||||
|
|
||||||
|
Les services suivants devraient être disponibles après démarrage de l'environnement:
|
||||||
|
|
||||||
|
|Service|Type|Accès|Description|
|
||||||
|
|-------|----|-----|-----------|
|
||||||
|
|Application React|HTTP (UI)|http://localhost:8081/|Page d'accueil de l'application React (serveur Webpack)|
|
||||||
|
|Serveur GraphQL|HTTP (GraphQL)|http://localhost:8080/api/v1/graphql|Point d'entrée de l'API GraphQL|
|
||||||
|
|Interface Web GraphQL|HTTP (UI)|http://localhost:8080/|Interface Web de développement de l'API GraphQL|
|
||||||
|
|Serveur PostgreSQL|TCP/IP (PostgreSQL)|`127.0.0.1:5432`|Port de connexion à la base de données PostgreSQL de développement|
|
||||||
|
|
||||||
|
#### Fichiers/répertoires notables
|
||||||
|
|
||||||
|
|Répertoire/Fichier|Description|
|
||||||
|
|------------------|-----------|
|
||||||
|
|`docker-compose.yml`|Configuration de l'environnement Docker Compose|
|
||||||
|
|`frontend/src`|Sources du frontend ([React](https://reactjs.org))|
|
||||||
|
|`backend/config/migrations`|Migrations SQL pour le backend, voir [la documentation de SuperGraph à ce sujet](https://supergraph.dev/docs/start#migrations)|
|
||||||
|
|
||||||
|
#### Commandes utiles
|
||||||
|
|
||||||
|
##### `make up`
|
||||||
|
|
||||||
|
Démarrer l'environnement de développement
|
||||||
|
|
||||||
|
`Ctrl+C` pour stopper l'environnement.
|
||||||
|
|
||||||
|
##### `make down`
|
||||||
|
|
||||||
|
Stopper et supprimer l'environnement de développement
|
||||||
|
|
||||||
|
##### `make db-shell`
|
||||||
|
|
||||||
|
Ouvrir une console `psql` sur la base de données de développement.
|
||||||
|
|
||||||
|
## Licence
|
||||||
|
|
||||||
|
AGPL-3.0
|
0
backend/config/allow.list
Normal file
0
backend/config/allow.list
Normal file
203
backend/config/dev.yml
Normal file
203
backend/config/dev.yml
Normal file
@ -0,0 +1,203 @@
|
|||||||
|
app_name: "Test Development"
|
||||||
|
host_port: 0.0.0.0:8080
|
||||||
|
web_ui: true
|
||||||
|
|
||||||
|
# debug, error, warn, info
|
||||||
|
log_level: "info"
|
||||||
|
|
||||||
|
# enable or disable http compression (uses gzip)
|
||||||
|
http_compress: true
|
||||||
|
|
||||||
|
# When production mode is 'true' only queries
|
||||||
|
# from the allow list are permitted.
|
||||||
|
# When it's 'false' all queries are saved to the
|
||||||
|
# the allow list in ./config/allow.list
|
||||||
|
production: false
|
||||||
|
|
||||||
|
# Throw a 401 on auth failure for queries that need auth
|
||||||
|
auth_fail_block: false
|
||||||
|
|
||||||
|
# Latency tracing for database queries and remote joins
|
||||||
|
# the resulting latency information is returned with the
|
||||||
|
# response
|
||||||
|
enable_tracing: true
|
||||||
|
|
||||||
|
# Watch the config folder and reload Super Graph
|
||||||
|
# with the new configs when a change is detected
|
||||||
|
reload_on_config_change: true
|
||||||
|
|
||||||
|
# File that points to the database seeding script
|
||||||
|
# seed_file: seed.js
|
||||||
|
|
||||||
|
# Path pointing to where the migrations can be found
|
||||||
|
# this must be a relative path under the config path
|
||||||
|
migrations_path: ./migrations
|
||||||
|
|
||||||
|
# Secret key for general encryption operations like
|
||||||
|
# encrypting the cursor data
|
||||||
|
secret_key: supercalifajalistics
|
||||||
|
|
||||||
|
# CORS: A list of origins a cross-domain request can be executed from.
|
||||||
|
# If the special * value is present in the list, all origins will be allowed.
|
||||||
|
# An origin may contain a wildcard (*) to replace 0 or more
|
||||||
|
# characters (i.e.: http://*.domain.com).
|
||||||
|
cors_allowed_origins: ["*"]
|
||||||
|
|
||||||
|
# Debug Cross Origin Resource Sharing requests
|
||||||
|
cors_debug: false
|
||||||
|
|
||||||
|
# Postgres related environment Variables
|
||||||
|
# SG_DATABASE_HOST
|
||||||
|
# SG_DATABASE_PORT
|
||||||
|
# SG_DATABASE_USER
|
||||||
|
# SG_DATABASE_PASSWORD
|
||||||
|
|
||||||
|
# Auth related environment Variables
|
||||||
|
# SG_AUTH_RAILS_COOKIE_SECRET_KEY_BASE
|
||||||
|
# SG_AUTH_RAILS_REDIS_URL
|
||||||
|
# SG_AUTH_RAILS_REDIS_PASSWORD
|
||||||
|
# SG_AUTH_JWT_PUBLIC_KEY_FILE
|
||||||
|
|
||||||
|
# inflections:
|
||||||
|
# person: people
|
||||||
|
# sheep: sheep
|
||||||
|
|
||||||
|
auth:
|
||||||
|
# Can be 'rails', 'jwt' or 'header'
|
||||||
|
type: jwt
|
||||||
|
cookie: _supergraph_session
|
||||||
|
|
||||||
|
# Comment this out if you want to disable setting
|
||||||
|
# the user_id via a header for testing.
|
||||||
|
# Disable in production
|
||||||
|
creds_in_header: true
|
||||||
|
|
||||||
|
# jwt:
|
||||||
|
# provider: auth0
|
||||||
|
# secret: abc335bfcfdb04e50db5bb0a4d67ab9
|
||||||
|
# public_key_file: /secrets/public_key.pem
|
||||||
|
# public_key_type: ecdsa #rsa
|
||||||
|
|
||||||
|
# header:
|
||||||
|
# name: dnt
|
||||||
|
# exists: true
|
||||||
|
# value: localhost:8080
|
||||||
|
|
||||||
|
# You can add additional named auths to use with actions
|
||||||
|
# In this example actions using this auth can only be
|
||||||
|
# called from the Google Appengine Cron service that
|
||||||
|
# sets a special header to all it's requests
|
||||||
|
auths:
|
||||||
|
- name: from_taskqueue
|
||||||
|
type: header
|
||||||
|
header:
|
||||||
|
name: X-Appengine-Cron
|
||||||
|
exists: true
|
||||||
|
|
||||||
|
database:
|
||||||
|
type: postgres
|
||||||
|
host: db
|
||||||
|
port: 5432
|
||||||
|
dbname: daddy
|
||||||
|
user: daddy
|
||||||
|
password: daddy
|
||||||
|
|
||||||
|
#schema: "public"
|
||||||
|
#pool_size: 10
|
||||||
|
#max_retries: 0
|
||||||
|
#log_level: "debug"
|
||||||
|
|
||||||
|
# Set session variable "user.id" to the user id
|
||||||
|
# Enable this if you need the user id in triggers, etc
|
||||||
|
set_user_id: false
|
||||||
|
|
||||||
|
# database ping timeout is used for db health checking
|
||||||
|
ping_timeout: 1m
|
||||||
|
|
||||||
|
# Define additional variables here to be used with filters
|
||||||
|
variables:
|
||||||
|
#admin_account_id: "5"
|
||||||
|
admin_account_id: "sql:select id from users where admin = true limit 1"
|
||||||
|
|
||||||
|
|
||||||
|
# Field and table names that you wish to block
|
||||||
|
blocklist:
|
||||||
|
- ar_internal_metadata
|
||||||
|
- schema_migrations
|
||||||
|
- secret
|
||||||
|
- password
|
||||||
|
- encrypted
|
||||||
|
- token
|
||||||
|
|
||||||
|
# Create custom actions with their own api endpoints
|
||||||
|
# For example the below action will be available at /api/v1/actions/refresh_leaderboard_users
|
||||||
|
# A request to this url will execute the configured SQL query
|
||||||
|
# which in this case refreshes a materialized view in the database.
|
||||||
|
# The auth_name is from one of the configured auths
|
||||||
|
actions:
|
||||||
|
- name: refresh_leaderboard_users
|
||||||
|
sql: REFRESH MATERIALIZED VIEW CONCURRENTLY "leaderboard_users"
|
||||||
|
auth_name: from_taskqueue
|
||||||
|
|
||||||
|
tables:
|
||||||
|
- name: customers
|
||||||
|
remotes:
|
||||||
|
- name: payments
|
||||||
|
id: stripe_id
|
||||||
|
url: http://rails_app:3000/stripe/$id
|
||||||
|
path: data
|
||||||
|
# debug: true
|
||||||
|
pass_headers:
|
||||||
|
- cookie
|
||||||
|
set_headers:
|
||||||
|
- name: Host
|
||||||
|
value: 0.0.0.0
|
||||||
|
# - name: Authorization
|
||||||
|
# value: Bearer <stripe_api_key>
|
||||||
|
|
||||||
|
- # You can create new fields that have a
|
||||||
|
# real db table backing them
|
||||||
|
name: me
|
||||||
|
table: users
|
||||||
|
|
||||||
|
|
||||||
|
#roles_query: "SELECT * FROM users WHERE id = $user_id"
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- name: anon
|
||||||
|
tables:
|
||||||
|
- name: users
|
||||||
|
query:
|
||||||
|
limit: 10
|
||||||
|
|
||||||
|
- name: user
|
||||||
|
tables:
|
||||||
|
- name: users
|
||||||
|
query:
|
||||||
|
filters: ["{ id: { _eq: $user_id } }"]
|
||||||
|
|
||||||
|
- name: products
|
||||||
|
query:
|
||||||
|
limit: 50
|
||||||
|
filters: ["{ user_id: { eq: $user_id } }"]
|
||||||
|
disable_functions: false
|
||||||
|
|
||||||
|
insert:
|
||||||
|
filters: ["{ user_id: { eq: $user_id } }"]
|
||||||
|
presets:
|
||||||
|
- user_id: "$user_id"
|
||||||
|
- created_at: "now"
|
||||||
|
|
||||||
|
update:
|
||||||
|
filters: ["{ user_id: { eq: $user_id } }"]
|
||||||
|
presets:
|
||||||
|
- updated_at: "now"
|
||||||
|
|
||||||
|
delete:
|
||||||
|
block: true
|
||||||
|
|
||||||
|
# - name: admin
|
||||||
|
# match: id = 1000
|
||||||
|
# tables:
|
||||||
|
# - name: users
|
||||||
|
# filters: []
|
17
backend/config/migrations/0_init.sql
Normal file
17
backend/config/migrations/0_init.sql
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
-- Write your migrate up statements here
|
||||||
|
|
||||||
|
CREATE TABLE public.users (
|
||||||
|
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||||
|
full_name text,
|
||||||
|
email text UNIQUE NOT NULL CHECK (length(email) < 255),
|
||||||
|
created_at timestamptz NOT NULL NOT NULL DEFAULT NOW(),
|
||||||
|
updated_at timestamptz NOT NULL NOT NULL DEFAULT NOW()
|
||||||
|
);
|
||||||
|
|
||||||
|
---- create above / drop below ----
|
||||||
|
|
||||||
|
-- Write your down migrate statements here. If this migration is irreversible
|
||||||
|
-- then delete the separator line above.
|
||||||
|
|
||||||
|
DROP TABLE public.users
|
||||||
|
|
67
backend/config/prod.yml
Normal file
67
backend/config/prod.yml
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
# Inherit config from this other config file
|
||||||
|
# so I only need to overwrite some values
|
||||||
|
inherits: dev
|
||||||
|
|
||||||
|
app_name: "Backend Production"
|
||||||
|
host_port: 0.0.0.0:8080
|
||||||
|
web_ui: false
|
||||||
|
|
||||||
|
# debug, info, warn, error, fatal, panic, disable
|
||||||
|
log_level: "warn"
|
||||||
|
|
||||||
|
# enable or disable http compression (uses gzip)
|
||||||
|
http_compress: true
|
||||||
|
|
||||||
|
# When production mode is 'true' only queries
|
||||||
|
# from the allow list are permitted.
|
||||||
|
# When it's 'false' all queries are saved to the
|
||||||
|
# the allow list in ./config/allow.list
|
||||||
|
production: true
|
||||||
|
|
||||||
|
# Throw a 401 on auth failure for queries that need auth
|
||||||
|
auth_fail_block: true
|
||||||
|
|
||||||
|
# Latency tracing for database queries and remote joins
|
||||||
|
# the resulting latency information is returned with the
|
||||||
|
# response
|
||||||
|
enable_tracing: true
|
||||||
|
|
||||||
|
# File that points to the database seeding script
|
||||||
|
# seed_file: seed.js
|
||||||
|
|
||||||
|
# Path pointing to where the migrations can be found
|
||||||
|
# migrations_path: migrations
|
||||||
|
|
||||||
|
# Secret key for general encryption operations like
|
||||||
|
# encrypting the cursor data
|
||||||
|
# secret_key: supercalifajalistics
|
||||||
|
|
||||||
|
# Postgres related environment Variables
|
||||||
|
# SG_DATABASE_HOST
|
||||||
|
# SG_DATABASE_PORT
|
||||||
|
# SG_DATABASE_USER
|
||||||
|
# SG_DATABASE_PASSWORD
|
||||||
|
|
||||||
|
# Auth related environment Variables
|
||||||
|
# SG_AUTH_RAILS_COOKIE_SECRET_KEY_BASE
|
||||||
|
# SG_AUTH_RAILS_REDIS_URL
|
||||||
|
# SG_AUTH_RAILS_REDIS_PASSWORD
|
||||||
|
# SG_AUTH_JWT_PUBLIC_KEY_FILE
|
||||||
|
|
||||||
|
database:
|
||||||
|
type: postgres
|
||||||
|
host: db
|
||||||
|
port: 5432
|
||||||
|
dbname: backend_development
|
||||||
|
user: postgres
|
||||||
|
password: postgres
|
||||||
|
#pool_size: 10
|
||||||
|
#max_retries: 0
|
||||||
|
#log_level: "debug"
|
||||||
|
|
||||||
|
# Set session variable "user.id" to the user id
|
||||||
|
# Enable this if you need the user id in triggers, etc
|
||||||
|
set_user_id: false
|
||||||
|
|
||||||
|
# database ping timeout is used for db health checking
|
||||||
|
ping_timeout: 5m
|
19
backend/config/seed.js
Normal file
19
backend/config/seed.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Example script to seed database
|
||||||
|
|
||||||
|
var users = [];
|
||||||
|
|
||||||
|
for (i = 0; i < 10; i++) {
|
||||||
|
var data = {
|
||||||
|
full_name: fake.name(),
|
||||||
|
email: fake.email()
|
||||||
|
}
|
||||||
|
|
||||||
|
var res = graphql(" \
|
||||||
|
mutation { \
|
||||||
|
user(insert: $data) { \
|
||||||
|
id \
|
||||||
|
} \
|
||||||
|
}", { data: data })
|
||||||
|
|
||||||
|
users.push(res.user)
|
||||||
|
}
|
30
docker-compose.yml
Normal file
30
docker-compose.yml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
version: '2.4'
|
||||||
|
services:
|
||||||
|
super-graph:
|
||||||
|
build:
|
||||||
|
context: ./misc/containers/super-graph
|
||||||
|
args:
|
||||||
|
- HTTP_PROXY=${HTTP_PROXY}
|
||||||
|
- HTTPS_PROXY=${HTTPS_PROXY}
|
||||||
|
- http_proxy=${http_proxy}
|
||||||
|
- https_proxy=${https_proxy}
|
||||||
|
environment:
|
||||||
|
- SG_DATABASE_HOST=postgres
|
||||||
|
- SG_DATABASE_USER=daddy
|
||||||
|
- SG_DATABASE_PASSWORD=daddy
|
||||||
|
- USER_ID=${USER_ID}
|
||||||
|
- GO_ENV=dev
|
||||||
|
volumes:
|
||||||
|
- ./backend:/app
|
||||||
|
links:
|
||||||
|
- postgres
|
||||||
|
ports:
|
||||||
|
- 8080:8080
|
||||||
|
postgres:
|
||||||
|
image: postgres:12-alpine
|
||||||
|
environment:
|
||||||
|
- POSTGRES_PASSWORD=daddy
|
||||||
|
- POSTGRES_USER=daddy
|
||||||
|
- POSTGRES_DB=daddy
|
||||||
|
ports:
|
||||||
|
- 5432:5432
|
36
misc/containers/super-graph/Dockerfile
Normal file
36
misc/containers/super-graph/Dockerfile
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
FROM alpine:edge AS build
|
||||||
|
|
||||||
|
ARG HTTP_PROXY=
|
||||||
|
ARG HTTPS_PROXY=
|
||||||
|
ARG http_proxy=
|
||||||
|
ARG https_proxy=
|
||||||
|
|
||||||
|
ARG SUPERGRAPH_VERSION=v0.14.17
|
||||||
|
ARG WAITFORIT_VERSION=v2.4.1
|
||||||
|
|
||||||
|
RUN apk add --no-cache go make git curl bash ca-certificates
|
||||||
|
|
||||||
|
RUN git clone https://github.com/dosco/super-graph \
|
||||||
|
&& export PATH="$PATH:/root/go/bin" \
|
||||||
|
&& export CGO_ENABLED=0 \
|
||||||
|
&& cd super-graph \
|
||||||
|
&& git checkout ${SUPERGRAPH_VERSION} \
|
||||||
|
&& make SHELL='bash -x' build
|
||||||
|
|
||||||
|
RUN curl -sL \
|
||||||
|
-o /usr/local/bin/waitforit \
|
||||||
|
https://github.com/maxcnunes/waitforit/releases/download/${WAITFORIT_VERSION}/waitforit-linux_amd64
|
||||||
|
|
||||||
|
FROM alpine:3.11
|
||||||
|
|
||||||
|
COPY --from=build /super-graph/super-graph /usr/local/bin/super-graph
|
||||||
|
COPY --from=build /usr/local/bin/waitforit /usr/local/bin/waitforit
|
||||||
|
|
||||||
|
RUN chmod +x /usr/local/bin/waitforit
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint
|
||||||
|
RUN chmod +x /usr/local/bin/docker-entrypoint
|
||||||
|
|
||||||
|
CMD ["/usr/local/bin/docker-entrypoint"]
|
13
misc/containers/super-graph/docker-entrypoint.sh
Normal file
13
misc/containers/super-graph/docker-entrypoint.sh
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -eo pipefail
|
||||||
|
|
||||||
|
if [ ! -f /container-lifecycle/first_run ]; then
|
||||||
|
waitforit -debug -host $SG_DATABASE_HOST -port 5432
|
||||||
|
super-graph db:migrate up
|
||||||
|
super-graph db:seed
|
||||||
|
mkdir /container-lifecycle
|
||||||
|
touch /container-lifecycle/first_run
|
||||||
|
fi
|
||||||
|
|
||||||
|
super-graph serv
|
Loading…
Reference in New Issue
Block a user