Unverified Commit a36cca0c authored by Ivan Gabriele's avatar Ivan Gabriele Committed by GitHub
Browse files

ci(scripts): add full setup script (#1030)

parent e14b71ca
......@@ -7,6 +7,7 @@ help make it even better than it is today!
- [Prerequisites](#prerequisites)
- [Get Started](#get-started)
- [Test](#test)
- [Scripts](#scripts)
- [Recommended IDE Settings](#recommended-ide-settings)
- [VS Code](#vs-code)
- [Known Issues](#known-issues)
......@@ -71,6 +72,30 @@ The website should now be available at: http://localhost:3100.
- Unit Tests (watch): `yarn test:watch`
- E2E Tests: `yarn test:e2e`
to update Unite Tests snapshots, you can run `yarn test:update`.
### Scripts
This repository comes with multiple useful npm scripts (run via `yarn <script>`):
- `data:generate`: Generate (update) DILA-related data (Labor Code & Agreements).
- `db:backup`: Generate a database dump.
- `db:migrate` Migrate database schema.
- `db:migrate:make`: Create a new database migration file.
- `db:restore`: Restore a database dump.
- `db:seed`: Seed the database via a mix of dummy and real production data.
- `db:snapshot:restore`: Restore the dev database dump.
- `db:snapshot:update`: Update the dev database dump file.
- `dev`: Start a full development instance (including Docker images).
- `dev:docker`: Start dev-related Docker images (with a dev config).
- `dev:packages`: Sun the packages instance in dev (watch + live-reload) mode.
- `setup`: Setup (or refresh) a ready-to-use dev environment.
- `setup:env`: Reset the dev environment variables (via the `.env` file).
- `setup:full`: Setup (or refresh) a ready-to-use dev environment **with** a new seed.<br>
_This also updates the dev/test database snapshot._
- `start`: Start a full production instance (without Docker images).
- `start:prod`: Run the production build & run script.
### Recommended IDE Settings
### VS Code
......
No preview for this file type
......@@ -5,21 +5,21 @@
"license": "Apache-2.0",
"private": true,
"scripts": {
"build": "lerna run --scope \"@socialgouv/code-du-travail-backoffice__app\" build",
"data:generate": "node ./scripts/data/generateLaborCodeArticles.js && node ./scripts/data/generateIndex.js",
"db:backup": "node -r dotenv/config ./scripts/db/backup.js",
"db:migrate": "knex migrate:latest",
"db:migrate:make": "node ./scripts/db/generateMigration.js",
"db:restore": "node -r dotenv/config ./scripts/db/restore.js",
"db:seed": "knex seed:run",
"db:snapshot": "node -r dotenv/config ./scripts/db/backup.js --dev",
"db:snapshot:restore": "node -r dotenv/config ./scripts/db/restore.js --dev",
"db:snapshot:update": "node -r dotenv/config ./scripts/db/backup.js --dev",
"dev": "yarn dev:docker && yarn dev:packages",
"dev:docker": "docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d postgrest",
"dev:packages": "lerna run --parallel --scope \"@socialgouv/code-du-travail-backoffice__api\" --scope \"@socialgouv/code-du-travail-backoffice__app\" dev",
"preinstall": "node ./scripts/ci/removeWorkspaces.js && node ./scripts/ci/deleteYarnLock.js",
"setup": "yarn setup:env && node -r dotenv/config ./scripts/dev/setup.js",
"setup:env": "cpy --rename=\".env\" ./.env.example .",
"setup:full": "yarn setup:env && node -r dotenv/config ./scripts/dev/setup.js --full",
"start": "lerna run --scope \"@socialgouv/code-du-travail-backoffice__api\" --scope \"@socialgouv/code-du-travail-backoffice__app\" start",
"start:prod": "NODE_ENV=production ./scripts/prod/start.sh",
"test": "yarn test:lint && yarn test:type && yarn test:unit --silent",
......@@ -61,7 +61,8 @@
"postgrester": "1.4.0",
"prettier": "2.0.5",
"puppeteer": "3.0.2",
"typescript": "3.8.3"
"typescript": "3.8.3",
"yargs": "15.3.1"
},
"resolutions": {
"@babel/preset-react": "^7.9.4"
......
# Scripts du dépôt monolithique
```text
├── ci Travis CI scripts
│ ├── install_docker_compose.sh Install Docker Compose
│ ├── run_full_server_instance.sh Run a production-like instance
│ └── stop_postgre_service.sh Gracefully stop Postgre service
├── db PostgreSQL database scripts
│ ├── generateMigration.js Generate files for a new migration
│ └── getMigrationQuery.js Resolve SQL migration files up/down queries
└── prod Production scripts
└── start.sh Main script building and running the server instance
├── ci CI scripts
│ ├── deleteYarnLock.js Delete Yarn lock file
│ └── removeWorkspaces.js Remove Lerna workspaces list in packages.json
├── data Static data scripts
│ ├── code-du-travail-YYYYMMDD.js Last version of DILA Labor Code articles extract
│ ├── generateIndex.js Generate agreements ID <> articles ID index file
│ └── generateLaborCodeArticles.js Generate normalized Labor Code articles file
├── db PostgreSQL database scripts
│ ├── backup.js Generate a dump file from the current database
│ ├── generateMigration.js Generate files for a new migration
│ ├── getMigrationQuery.js Resolve SQL migration files up/down queries
│ └── restore.js Restore a dump file into the database
├── dev Development scripts
│ └── setup.js Fully setup (or reset) a fresh dev environment
└── prod Production scripts
└── start.sh Build and run a production server instance
```
## Notes
- `deleteYarnLock.js` & `removeWorkspaces.js` are used to avoid the useless packages dependencies
installation during the first `yarn install` call in production, which makes it faster.
......@@ -2,6 +2,7 @@ require("colors");
const fs = require("fs");
const knex = require("knex");
const shell = require("shelljs");
const { argv } = require("yargs");
const { DEV_DB_PORT, NODE_ENV, POSTGRES_DB, POSTGRES_PASSWORD, POSTGRES_USER } = process.env;
......@@ -53,7 +54,14 @@ async function waitForDb() {
shell.echo(`Waiting for db to be up and ready…`.blue);
await waitForDb();
run(`yarn db:migrate`);
run(`yarn db:snapshot:restore`);
if (argv.full) {
run(`yarn db:seed`);
run(`yarn db:snapshot:update`);
} else {
run(`yarn db:snapshot:restore`);
}
run(`yarn dev:docker`);
run(`docker-compose stop`);
shell.exit(0);
......
......@@ -14475,39 +14475,39 @@ yargs-parser@^18.1.1, yargs-parser@^18.1.3:
camelcase "^5.0.0"
decamelize "^1.2.0"
yargs@^14.2.2:
version "14.2.3"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-14.2.3.tgz#1a1c3edced1afb2a2fea33604bc6d1d8d688a414"
integrity sha512-ZbotRWhF+lkjijC/VhmOT9wSgyBQ7+zr13+YLkhfsSiTriYsMzkTUFP18pFhWwBeMa5gUc1MzbhrO6/VB7c9Xg==
yargs@15.3.1, yargs@^15.3.1:
version "15.3.1"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-15.3.1.tgz#9505b472763963e54afe60148ad27a330818e98b"
integrity sha512-92O1HWEjw27sBfgmXiixJWT5hRBp2eobqXicLtPBIDBhYB+1HpwZlXmbW2luivBJHBzki+7VyCLRtAkScbTBQA==
dependencies:
cliui "^5.0.0"
cliui "^6.0.0"
decamelize "^1.2.0"
find-up "^3.0.0"
find-up "^4.1.0"
get-caller-file "^2.0.1"
require-directory "^2.1.1"
require-main-filename "^2.0.0"
set-blocking "^2.0.0"
string-width "^3.0.0"
string-width "^4.2.0"
which-module "^2.0.0"
y18n "^4.0.0"
yargs-parser "^15.0.1"
yargs-parser "^18.1.1"
yargs@^15.3.1:
version "15.3.1"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-15.3.1.tgz#9505b472763963e54afe60148ad27a330818e98b"
integrity sha512-92O1HWEjw27sBfgmXiixJWT5hRBp2eobqXicLtPBIDBhYB+1HpwZlXmbW2luivBJHBzki+7VyCLRtAkScbTBQA==
yargs@^14.2.2:
version "14.2.3"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-14.2.3.tgz#1a1c3edced1afb2a2fea33604bc6d1d8d688a414"
integrity sha512-ZbotRWhF+lkjijC/VhmOT9wSgyBQ7+zr13+YLkhfsSiTriYsMzkTUFP18pFhWwBeMa5gUc1MzbhrO6/VB7c9Xg==
dependencies:
cliui "^6.0.0"
cliui "^5.0.0"
decamelize "^1.2.0"
find-up "^4.1.0"
find-up "^3.0.0"
get-caller-file "^2.0.1"
require-directory "^2.1.1"
require-main-filename "^2.0.0"
set-blocking "^2.0.0"
string-width "^4.2.0"
string-width "^3.0.0"
which-module "^2.0.0"
y18n "^4.0.0"
yargs-parser "^18.1.1"
yargs-parser "^15.0.1"
yauzl@^2.10.0:
version "2.10.0"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment