LoginSignup
10
6

More than 5 years have passed since last update.

ローカルからDocker内のlint-stagedを呼び出す

Last updated at Posted at 2019-03-24

huskylint-stagedを使って、コミット時に自動でlintを走らせるのは一般的だと思う。

しかしDockerのnodeコンテナで開発しているプロジェクトを、ローカルのWindowsなどからGitでコミットすると、lint-stagedのバイナリが実行できない。これはバイナリがwindowsで使われることを想定していない、つまりlinux向けにコンパイルされたものだからである。

こういった場合は、以下のようにdocker-compose runでコンテナ越しにlint-stagedを呼び出すと良い。

package.json
"husky": {
  "hooks": {
    "pre-commit": "docker-compose run --rm node yarn exec lint-staged"
  }
},
"lint-staged": {
  "*.{js,vue}": [
    "eslint --fix",
    "git add"
  ]
},

alpineイメージを使用する場合だと、gitがインストールされていないため、Dockerfileを以下のように書く。

FROM node:11.12-alpine
RUN apk add --no-cache git

ついでにdocker-compose.ymlも載せておく。

docker-compose.yml
version: '3'

services:
  node:
    build:
      context: ./docker/node
10
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
6