GithubHelp home page GithubHelp logo

topheman / docker-experiments Goto Github PK

View Code? Open in Web Editor NEW
97.0 97.0 11.0 1.56 MB

Discover docker with a simple use case in development, production (local kubernetes) and CI

Shell 7.31% Makefile 21.52% Dockerfile 8.42% Go 17.77% HTML 6.90% CSS 3.69% JavaScript 34.39%
docker docker-compose kubernetes

docker-experiments's Introduction

My name is Christophe Rosset, I live in ๐Ÿ‡ซ๐Ÿ‡ท Paris, France.

Iโ€™ve been working in Web Development for a long time now, I still really enjoy it and keep learning new things. What I like the most is sharing my knowledge with others, not only in my job but also through my personal projects.

@topheman on twitter @topheman on LinkedIn @topheman on stackoverflow

My projects My talks

Click for GitHub Stats

GitHub Stats

docker-experiments's People

Contributors

topheman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

docker-experiments's Issues

Setup eslint/prettier on docker + host

TL;DR

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.

Without docker

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.

With docker

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):

  • on CircleCI
  • on precommit hooks

Developer Experience

But this is not enough.

  • I want to have my lint errors highlighted in my IDE/editor
  • I want prettier to format my code when I save a file
  • I don't want to use any global modules (can't make any assumption about the computer of the developer, only that he/she may have docker, npm and node)

The things described above:

  • need to happen on the host machine - NOT on the docker container
    • for the moment, no 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)
  • they are tied with IDE/editor implementation specific plugin. For example, the VS Code ESLint extension will use the version of eslint of your working directory (and needed eslint plugins), same for prettier

Solution

This means that we also need to install the node_modules on the host and not alter package-lock.json file while installing.

  • How to run npm install based on package-lock.json, but ensure that it won't be updated in any way ?
  • On the other hand, we can't fully base the 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)

Further notes about Cypress and Husky

This is the same kind of problem for cypress and husky:

  • cypress:
    • needs to be ran inside the container in command line mode (as it will be ran on CI)
    • should also be ran on the host (to access the GUI to debug tests)
  • husky (not exaclty the same):
    • needs to be ran from the host (when a git commit is made on the host)
    • also, should be installed at the very root of the project, to install commit hooks inside .git at the root

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.