Skip to content
Trouver rapidement le bon professionnel pour les majeurs à protéger
JavaScript CSS TypeScript Shell Other
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/ISSUE_TEMPLATE
.gitlab-ci
.k8s
docker/postgres
optional/e2e
packages
scripts
.dockerignore
.editorconfig
.env.sample
.env.test
.gitignore
.gitlab-ci.yml
.travis.yml
CHANGELOG.md
Dockerfile
LICENSE
README.md
codecov.yml
commitlint.config.js
docker-compose.override.yaml.sample
docker-compose.test.yaml
docker-compose.yaml
lerna.json
package.json
yarn.lock

README.md

eMJPM

Build Status Codacy Badge codecov

Installation

Make sure you're using NodeJS 10.15

# Install all the packages
$ yarn
# This will trigger some build on the `postinstall` script

Build

# Build all the packages
$ yarn build

# Build the "<package-name>"
$ yarn workspace <package-name> build

# For example for "@emjpm/api"
$ yarn workspace @emjpm/api build

Test

# Build all the packages
$ yarn test

# Build the "<package-name>"
$ yarn workspace <package-name> test

# For example for "@emjpm/api"
$ yarn workspace @emjpm/api test

# executing the test in the same condition than the ci
$ yarn workspace @emjpm/api test --maxWorkers=2 --coverage

E2E tests

The e2e tests are using the latest deployed socialgouv/emjpm-* images by default. To run the tests with

$ yarn lerna --scope @optional/e2e exec yarn
$ docker-compose -f ./docker-compose.yaml -f ./docker-compose.test.yaml up --build

$ NODE_ENV=test yarn workspace @emjpm/knex run migrate
$ NODE_ENV=test yarn workspace @emjpm/knex run seeds

$ yarn run -- lerna --scope @optional/e2e run cypress:run -- --headed

Manual deployment

To build and deploy manually some version :

# checkout your target branch
git pull

# edit docker-compose.override.yaml and .env

# build locally main docker image as emjpm-base
# you can override API_URL and SENTRY_PUBLIC_DSN env vars here
docker build . -t emjpm-base

# rebuild and launch instance using locally built image
BASE_IMAGE=emjpm-base docker-compose up --build -d

# run migrations and seeds
BASE_IMAGE=emjpm-base docker-compose run knex yarn workspace @emjpm/knex run migrate
BASE_IMAGE=emjpm-base docker-compose run knex yarn workspace @emjpm/knex run seeds

Maintenance

Database

dump production database

connect to PG pod

kubectl exec -it emjpm-postgres-prod-0 sh

dump database

DUMP_FILE=emjpm_prod_`date +%d-%m-%Y"_"%H_%M_%S`.dump
pg_dump emjpm -U postgres -Fc > /tmp/$DUMP_FILE

copy dump on loca

kubectl cp emjpm-postgres-prod-0:/tmp/$DUMP_FILE ./$DUMP_FILE

restore production dump on local

export PGUSER=postgres
export PGPASSWORD=test

cat <<EOF > reset-database.sql
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid <> pg_backend_pid() AND datname = 'emjpm';
DROP DATABASE IF EXISTS emjpm;
CREATE DATABASE emjpm WITH OWNER = emjpm;
EOF

# drop / create database emjpm
cat reset-database.sql | psql -h localhost -p 5434 -U $PGUSER

# restore production dump
pg_restore -h localhost -p 5434 --if-exists --clean -e -Fc -d emjpm ./$DUMP_FILE

psql -h localhost -p 5434 -c "ALTER SCHEMA public OWNER TO emjpm" -U $PGUSER emjpm

rm reset-database.sql

restore production dump on k8s pod

connect to PG pod

kubectl exec -it emjpm-postgres-your-feature sh

restore production dump

# drop database emjpm
cat <<EOF > reset-database.sql
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid <> pg_backend_pid() AND datname = 'emjpm';
DROP DATABASE IF EXISTS emjpm;
CREATE DATABASE emjpm WITH OWNER = emjpm;
EOF

cat reset-database.sql | psql -h localhost -U postgres

# restore production dump
pg_restore -h localhost --if-exists --clean -e -Fc -U postgres -d emjpm ./$DUMP_FILE

psql -h localhost -c "ALTER SCHEMA public OWNER TO emjpm" -U postgres emjpm

FAQ

  • If you have the Can't take lock to run migrations: Migration table is already locked error
$ docker-compose exec db psql -U postgres -d emjpm_test -c 'UPDATE knex_migrations_v2_lock set is_locked=0;'
UPDATE 1
  • If you have migration error
$ docker-compose -f ./docker-compose.yaml -f ./docker-compose.dev.yaml exec api yarn knex migrate:rollback

Release policy

One click semantic release !

On a successful master branch pipeline click on trigger the Release job.

Auto

Trigger a custom build on Travis (in the "More options" right menu) on the master branch with a custom config:

env:
  global:
    - RELEASE=true

You can change the lerna arguments though the LERNA_ARGS variable.

env:
  global:
    - LERNA_ARGS="--force-publish --yes"
    - RELEASE=true

Manual

You need an Github token to release.

#
# Bump, push to git and publish to npm
$ yarn lerna version

#
# Publish the tag change log on the Github Release
$ CONVENTIONAL_GITHUB_RELEASER_TOKEN==************ npx conventional-github-releaser -p angular

#
# You might want to add a Gif to your release to make it groovy ;)

Deployment policy

All branches and tags are automatically deployed See https://github.com/SocialGouv/emjpm/deployments

One click tag release !

On a successful tag branch pipeline click on trigger the Put to production job.

Auto

Trigger a custom build on Travis (in the "More options" right menu) on the tag v* you with a custom config:

env:
  global:
    - PRODUCTION=true

Manual

# Run the k8s files
$ kubectl apply -f ./.k8s/frontend/deployment.yml
$ kubectl apply -f ./.k8s/frontend/service.yml
$ kubectl apply -f ./.k8s/frontend/ingress.yml

Branch name

You need to name your branch with the commit lint convention

branch name template:

type/***-***

Type

Must be one of the following:

  • build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
  • ci: Changes to our CI configuration files and scripts (example scopes: Circle, BrowserStack, SauceLabs)
  • docs: Documentation only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that neither fixes a bug nor adds a feature
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • test: Adding missing tests or correcting existing tests

as a reference see https://github.com/conventional-changelog/commitlint/tree/master/@commitlint/config-angular

You can’t perform that action at this time.