Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrations automatiques de base de données #1046

Merged
merged 6 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/node-export.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Node `export` application

on:
push:
branches:
- master
paths:
- 'export/**'
- '.github/workflows/node*.yml'
pull_request:
paths:
- 'export/**'
- '.github/workflows/node*.yml'

jobs:
build:
uses: EcrituresNumeriques/stylo/.github/workflows/node.yml@feat/migrate-db
with:
app-dir: export
19 changes: 19 additions & 0 deletions .github/workflows/node-front.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Node `front` application

on:
push:
branches:
- master
paths:
- 'front/**'
- '.github/workflows/node*.yml'
pull_request:
paths:
- 'front/**'
- '.github/workflows/node*.yml'

jobs:
build:
uses: EcrituresNumeriques/stylo/.github/workflows/node.yml@feat/migrate-db
with:
app-dir: front
19 changes: 19 additions & 0 deletions .github/workflows/node-graphql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Node `graphql` application

on:
push:
branches:
- master
paths:
- 'graphql/**'
- '.github/workflows/node*.yml'
pull_request:
paths:
- 'graphql/**'
- '.github/workflows/node*.yml'

jobs:
build:
uses: EcrituresNumeriques/stylo/.github/workflows/node.yml@feat/migrate-db
with:
app-dir: graphql
49 changes: 24 additions & 25 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
name: Node applications

on:
push:
branches:
- master
paths:
- 'graphql/**'
- 'front/**'
- 'export/**'
- '.github/workflows/node.yml'
pull_request:
paths:
- 'graphql/**'
- 'front/**'
- 'export/**'
- '.github/workflows/node.yml'
workflow_call:
inputs:
app-dir:
type: string
required: true

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
app: [front, graphql, export]

services:
mongodb:
image: mongo:4.4
ports:
- 27017/tcp

steps:
- uses: actions/checkout@v4
Expand All @@ -31,22 +24,28 @@ jobs:
node-version-file: .nvmrc
cache: npm

- name: Install and test
working-directory: ${{ matrix.app }}
run: npm clean-install-test --no-audit --no-fund
- name: Install
working-directory: ${{ inputs.app-dir }}
run: npm clean-install --no-audit --no-fund

- name: Test
working-directory: ${{ inputs.app-dir }}
run: npm test
env:
DATABASE_URL: mongodb://127.0.0.1:${{ job.services.mongodb.ports[27017] }}/stylo
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

je n'ai jamais vu cette syntaxe job.services.mongodb.ports[27017], entre crochets c'est la valeur par défaut ? Si c'est une reference ce n'est pas plutôt le premier élément de ports ?

Copy link
Member Author

@thom4parisot thom4parisot Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


- name: Coveralls
uses: coverallsapp/github-action@v2
with:
base-path: ${{ matrix.app }}
base-path: ${{ inputs.app-dir }}
parallel: true
flag-name: run-${{ join(matrix.*, ' - ') }}
flag-name: run-${{ inputs.app-dir }}

- name: Build (if necessary)
working-directory: ${{ matrix.app }}
working-directory: ${{ inputs.app-dir }}
run: npm run build --if-present

finish:
publish-coverage-report:
needs: build
if: ${{ always() }}
runs-on: ubuntu-latest
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/data
dataProd
node_modules/
graphql/nodemon.dev.json
sails/.tmp
/stylo.env
/.env
/.env.local
nodemon.dev.json
/.idea/
/.run/

Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ services:
env_file:
- .env
environment:
- MONGO_SERVER=mongodb-stylo
- MONGO_SERVER_PORT=27017
- DATABASE_URL=mongodb://mongodb-stylo:27017/stylo-dev
ports:
- 127.0.0.1:3030:3030

Expand All @@ -46,6 +45,7 @@ services:
env_file:
- .env
environment:
- DATABASE_URL=mongodb://mongodb-stylo:27017/stylo-dev
- MONGO_SERVER=mongodb-stylo
- MONGO_SERVER_PORT=27017
ports:
Expand Down
8 changes: 0 additions & 8 deletions export/nodemon.json

This file was deleted.

1 change: 0 additions & 1 deletion graphql/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
node_modules
npm-debug.log
nodemon.dev.json
ydata
2 changes: 1 addition & 1 deletion graphql/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
rules: {},
overrides: [
{
files: '**/*.test.js',
files: ['**/*.test.js', './tests/*.js'],
plugins: ['jest'],
env: {
'jest/globals': true
Expand Down
1 change: 1 addition & 0 deletions graphql/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/coverage
/ydata
globalConfig.json
6 changes: 1 addition & 5 deletions graphql/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@

const app = express()

const mongoServer = config.get('mongo.host')
const mongoServerPort = config.get('mongo.port')
const mongoServerDB = config.get('mongo.db')

const listenPort = config.get('port')
const origin = config.get('security.cors.origin')
const jwtSecret = config.get('security.jwt.secret')
Expand Down Expand Up @@ -71,7 +67,7 @@
// When we have a single origin (most likely when running in a production environment) then we are using a secure/strict value for cookies `sameSite` attribute ('strict').
// When using 'strict' value, cookies will not be sent along with requests initiated by third-party websites.
// Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite
const allowedOrigins = (origin ?? '').split(' ').filter(v => v).map(o => new RegExp('^' + o))

Check warning on line 70 in graphql/app.js

View workflow job for this annotation

GitHub Actions / build / build

Found non-literal argument to RegExp Constructor
// SameSite should be None on cross-site response.
// Please note that "SameSite=None" must also specify the Secure attribute (they require a secure context/HTTPS).
const sameSiteCookies = allowedOrigins.length > 1 && secureCookie ? 'none' : 'lax'
Expand Down Expand Up @@ -320,7 +316,7 @@
mongoose.set('useFindAndModify', false)

mongoose
.connect(`mongodb://${mongoServer}:${mongoServerPort}/${mongoServerDB}`)
.connect(config.get('mongo.databaseUrl'))
.then(() => {
logger.info('Listening on http://localhost:%s', listenPort)
const server = app.listen(listenPort)
Expand Down
36 changes: 17 additions & 19 deletions graphql/config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
const convict = require('convict')
const assert = require('node:assert/strict')
require('dotenv').config({ path: ['.env', '../.env'] })

const isURL = require('validator/lib/isURL')

convict.addFormat(require('convict-format-with-validator').url)
convict.addFormat({
name: 'mongodb-url',
coerce: (v) => v.toString(),
validate: (val) => assert.ok(isURL(val, { require_tld: false, protocols: ['mongodb', 'mongodb+srv'] }), 'must be a mongodb protocol URL')

})
/**
* @type {convict.Config<{
*
Expand All @@ -22,32 +30,22 @@ module.exports = convict({
}
},
mongo: {
db: {
format: String,
env: 'MONGO_SERVER_DB',
default: 'stylo-dev'
},
host: {
format: String,
env: 'MONGO_SERVER',
default: '127.0.0.1'
},
port: {
format: 'port',
env: 'MONGO_SERVER_PORT',
default: '27017'
databaseUrl: {
default: 'mongodb://127.0.0.1:27017/stylo-dev',
format: 'mongodb-url',
env: 'DATABASE_URL'
}
},
oauthProvider: {
name: {
format: String,
env: 'OPENID_CONNECT_NAME',
default: null,
default: null
},
issuer: {
format: 'url',
env: 'OPENID_CONNECT_ISSUER',
default: null,
default: null
},
callbackUrl: {
format: 'url',
Expand Down Expand Up @@ -76,12 +74,12 @@ module.exports = convict({
tokenUrl: {
format: 'url',
env: 'OPENID_CONNECT_TOKEN_URL',
default: null,
default: null
},
userInfo: {
format: 'url',
env: 'OPENID_CONNECT_USER_INFO_URL',
default: null,
default: null
},
url: {
format: 'url',
Expand Down Expand Up @@ -113,7 +111,7 @@ module.exports = convict({
format: String,
sensitive: true,
env: 'JWT_SECRET_SESSION_COOKIE',
default: null,
default: null
}
},
session: {
Expand Down
36 changes: 0 additions & 36 deletions graphql/data/20211118-working-version.js

This file was deleted.

Loading
Loading