Как прервать Docker-Build при возникновении ошибки npm-install? - PullRequest
0 голосов
/ 11 июля 2019

Часть наших шагов по Docker-Build включает запуск npm-install для установки набора зависимостей. Однако, если во время установки npm выдается ошибка, вызванная чем-то вроде недопустимой зависимости, сборка Docker продолжается, что занимает много времени, занимая много впустую потраченного времени и ресурсов.

Я не слишком хорошо разбираюсь в Docker, поэтому мне было интересно, есть ли какой-нибудь способ включить в мой Dockerfile или файл package.json поиск ненулевого кода ошибки, генерируемого процессом npm-install и прервать сборку Docker, если найден, но я не уверен, как это будет сделано.

Это вывод, который я получаю при сборке docker-compose для моего контейнера. В файле package.json я ввел ложную зависимость, чтобы вызвать сбой установки npm: amwell-component @ blahblahblahthisisatypointentionallytocauseerror

> cd client && npm install

npm ERR! code ETARGET
npm ERR! notarget No matching version found for amwell-component@blahblahblahthisisatypointentionallytocauseerror
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! notarget 
npm ERR! notarget It was specified as a dependency of 'amwell_server'
npm ERR! notarget 

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-07-11T17_05_17_154Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! amwell_server-parent@ postinstall: `cd client && npm install`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the amwell_server-parent@ postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-07-11T17_05_17_193Z-debug.log

Здесь я вижу, что он выдает ненулевой код ошибки, но даже если выдается ошибка npm, сборка Docker-compose все равно продолжает работать:

Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: linux.mirrors.es.net
 * extras: mirror.team-cymru.com
 * updates: ftpmirror.your.org
Resolving Dependencies
--> Running transaction check
---> Package icu.x86_64 0:50.1.2-17.el7 will be installed
--> Processing Dependency: libicu(x86-64) = 50.1.2-17.el7 for package: icu-50.1.2-17.el7.x86_64
--> Processing Dependency: libicuuc.so.50()(64bit) for package: icu-50.1.2-17.el7.x86_64
--> Processing Dependency: libicutu.so.50()(64bit) for package: icu-50.1.2-17.el7.x86_64
--> Processing Dependency: libicui18n.so.50()(64bit) for package: icu-50.1.2-17.el7.x86_64
--> Processing Dependency: libicudata.so.50()(64bit) for package: icu-50.1.2-17.el7.x86_64
--> Running transaction check
---> Package libicu.x86_64 0:50.1.2-17.el7 will be installed
--> Finished Dependency Resolution

Вот как выглядит Dockerfile. Чтобы защитить IP, я отредактировал некоторые данные и заменил их на «х»:

LABEL maintainer "xxxxxx xxxxx xxxxxxx <xxxxxxxxxxxxxx@xxxxxx.com>"
LABEL xxx.xxxxxx.name="Amwell Server"
LABEL xxx.xxxxxx.repo-url="https://github.xxxxxx.com/xxxxx-xxxxx/amwell_server"

RUN RAILS_ENV=production bundle exec rake assets:precompile
RUN RAILS_ENV=production bundle exec rake tmp:clear

ONBUILD ARG ONBUILD_ENV=test
ONBUILD RUN source /onbuild/$ONBUILD_ENV.sh
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...