topheman / docker-experiments Goto Github PK
View Code? Open in Web Editor NEWDiscover docker with a simple use case in development, production (local kubernetes) and CI
Discover docker with a simple use case in development, production (local kubernetes) and CI
This issue aims to describe how if you setup docker on a fullstack project, you may loose some developer experience like in-editor linting / formating + git hooks and propose a solution.
Here is an example of how you would make an advanced setup of eslint/prettier (with husky for precommit hooks) on a regular frontend project without docker topheman/my-react-app-starter@9c0fa1b :
The husky/precommit hooks part will be addressed on an other issue.
First install prettier, eslint and a few eslint plugins because we want some advanced rules:
docker-compose run --rm front npm install --save-dev --save-exact prettier
docker-compose run --rm front npm install --save-dev cross-env eslint-config-airbnb eslint-config-prettier eslint-plugin-cypress eslint-plugin-prettier
Note: We need to docker-compose run --rm front
to run the npm install
command inside the docker container, which is a Linux environment, because we are making the call from our host machine which could be a MacOS or a Windows (which means that some native node_modules
might differ and will need to be compiled on the right platform to run inside the docker container AND to save the proper versions on the package-lock.json
).
Then we'll have to create a few files:
front/.eslintignore
:
/build/**
/coverage/**
/docs/**
/tmp/**
/src/libs/**
front/.eslintrc
:
{
"extends": ["react-app", "airbnb", "prettier"],
"plugins": ["prettier", "cypress"],
"rules": {
"prettier/prettier": "error",
"no-console": "off",
"react/jsx-filename-extension": "off",
"react/forbid-prop-types": [2, { "forbid": ["any"] }],
"react/no-did-mount-set-state": "off",
"import/prefer-default-export": "off",
"prefer-template": "off",
"no-underscore-dangle": ["error", { "allowAfterThis": true }],
"global-require": "off",
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": true,
"optionalDependencies": false,
"peerDependencies": false
}
]
},
"globals": {
"cy": true
},
"env": {
"mocha": true,
"cypress/globals": true
}
}
front/.prettierignore
:
.git
package-lock.json
package.json
.eslintignore
.gitignore
.prettierignore
.gitignore
*.fixtures.json
src/libs/**
front/.prettierrc
:
{}
Add the following scripts to the front/package.json
:
"lint": "npx eslint .",
"pretty": "npx prettier --write '**/*.{js,jsx,json,css,scss}'",
That way, we will be able to run eslint and prettier from inside the docker container like this:
docker-compose run --rm front npm run lint
docker-compose run --rm front npm run pretty
For example, the lint
task will be run from inside the docker container (NOT from the host):
But this is not enough.
The things described above:
node_modules
are installed on the host, they are installed on the container (see docker-compose.override.yml where the front-deps
modules is declared)eslint
of your working directory (and needed eslint plugins), same for prettierThis means that we also need to install the node_modules
on the host and not alter package-lock.json
file while installing.
npm install
based on package-lock.json
, but ensure that it won't be updated in any way ?npm install
on package-lock.json
, because host platform and container platform may differ (if your on a Mac for example, you will have to install some optional modules like fsevents
)This is the same kind of problem for cypress and husky:
.git
at the rootA declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.