Dockerize ESLint с предустановками - PullRequest
1 голос
/ 19 апреля 2020

Я пытаюсь создать этап Cit / CD для GitLab, который бы только ограничивал мой код и выполнялся перед всеми остальными шагами. Беда в том, что я пытаюсь сделать пометку (вместе с ее конфигурацией) на предварительно построенном изображении для оптимизации скорости.

Мой .gitlab-ci.yml

stages:
  - prelint
  - lint
  - build
  - deploy

build-linter:
  stage: prelint
  script: echo 'This builds the linter image'
  only:
    changes:
      - Dockerfile.lint

lint:
  stage: lint
  image: prebuilt-linter
  script:
    - npm run lint

И содержимое Dockerfile.lint:

FROM node:lts-alpine

RUN npm i -g eslint \
  prettier \
  @babel/core \
  core-js \
  core-js-compat@3.4.7 \
  eslint-config-prettier \
  eslint-plugin-prettier \
  eslint-plugin-vue \
  @vue/cli-service \
  @vue/cli-plugin-eslint \
  @vue/cli-plugin-babel \
  @vue/cli-plugin-unit-jest \
  @vue/cli-plugin-e2e-nightwatch \
  @vue/eslint-config-prettier \
  babel-eslint

WORKDIR /app
CMD eslint

Однако в настоящее время происходит ошибка, потому что я думаю, что он пытается найти зависимости из собственного каталога node_modules/ проекта и не будет использовать глобально установленные.

$ npm run lint
00:01
> @project/1.0.0 lint /builds/frontend
> vue-cli-service lint
 ERROR  Error: Cannot find module '@vue/cli-plugin-babel/preset' from '/builds/frontend'
Error: Cannot find module '@vue/cli-plugin-babel/preset' from '/builds/frontend'
    at Function.resolveSync [as sync] (/usr/local/lib/node_modules/@babel/core/node_modules/resolve/lib/sync.js:81:15)
    at resolveStandardizedName (/usr/local/lib/node_modules/@babel/core/lib/config/files/plugins.js:101:31)
    at resolvePreset (/usr/local/lib/node_modules/@babel/core/lib/config/files/plugins.js:58:10)
    at loadPreset (/usr/local/lib/node_modules/@babel/core/lib/config/files/plugins.js:77:20)
    at createDescriptor (/usr/local/lib/node_modules/@babel/core/lib/config/config-descriptors.js:154:9)
    at /usr/local/lib/node_modules/@babel/core/lib/config/config-descriptors.js:109:50
    at Array.map (<anonymous>)
    at createDescriptors (/usr/local/lib/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
    at createPresetDescriptors (/usr/local/lib/node_modules/@babel/core/lib/config/config-descriptors.js:101:10)
    at presets (/usr/local/lib/node_modules/@babel/core/lib/config/config-descriptors.js:47:19)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @project@1.0.0 lint: `vue-cli-service lint`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @project@1.0.0 lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-04-14T18_59_23_427Z-debug.log
ERROR: Job failed: command terminated with exit code 1

Как лучше всего было бы использовать зависимости, необходимые для работы eslint во встроенном образе, без необходимости каждый раз устанавливать зависимости? Я не хотел бы полагаться на установку devDependencies проекта, так как все еще бывали частые перебои в кэше из-за исправления нерелевантных зависимостей et c.

...