0

我花了几个小时尝试不同的节点映像并安装不同的软件包,但没有任何帮助。在主机系统上,我在运行时似乎没有任何问题npm run dev,但是在使用 Docker (Alpine Linux) 时,我得到以下输出:

#33 72.29 npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
#33 74.72 npm WARN deprecated flatten@1.0.3: flatten is deprecated in favor of utility frameworks such as lodash.
#33 76.10 npm WARN deprecated babel-eslint@10.1.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
#33 76.76 npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
#33 83.24 npm WARN deprecated browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
#33 87.83 npm WARN deprecated browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
#33 88.47 npm WARN deprecated debug@4.1.1: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
#33 93.98 npm WARN deprecated browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
#33 94.60 npm WARN deprecated debug@4.1.1: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
#33 100.7 npm WARN deprecated debug@4.1.1: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
#33 101.5 npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
#33 101.7 npm WARN deprecated uuid@2.0.3: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
#33 102.5 npm WARN deprecated uuid@2.0.3: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
#33 120.3 npm ERR! code 1
#33 120.3 npm ERR! path /usr/src/node_modules/mozjpeg
#33 120.3 npm ERR! command failed
#33 120.3 npm ERR! command sh -c node lib/install.js
#33 120.3 npm ERR! ⚠ The `/usr/src/node_modules/mozjpeg/vendor/cjpeg` binary doesn't seem to work correctly
#33 120.3 npm ERR!   ⚠ mozjpeg pre-build test failed
#33 120.3 npm ERR!   ℹ compiling from source
#33 120.3 npm ERR! /usr/src/node_modules/mozjpeg/lib/install.js:22
#33 120.3 npm ERR!              var builder = new BinBuild()
#33 120.3 npm ERR!                            ^
#33 120.3 npm ERR! 
#33 120.3 npm ERR! TypeError: BinBuild is not a constructor
#33 120.3 npm ERR!     at /usr/src/node_modules/mozjpeg/lib/install.js:22:17
#33 120.3 npm ERR!     at BinWrapper.<anonymous> (/usr/src/node_modules/mozjpeg/node_modules/bin-wrapper/index.js:156:4)
#33 120.3 npm ERR!     at ChildProcess.<anonymous> (/usr/src/node_modules/mozjpeg/node_modules/bin-check/index.js:26:4)
#33 120.3 npm ERR!     at ChildProcess.emit (node:events:394:28)
#33 120.3 npm ERR!     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
#33 120.4 
#33 120.4 npm ERR! A complete log of this run can be found in:
#33 120.4 npm ERR!     /root/.npm/_logs/2021-08-25T07_40_00_055Z-debug.log
------
failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c apk add --update --no-cache     bash     autoconf     gcc     g++     make     automake     nasm     libtool     zlib     libc6-compat     libpng     libpng-dev     mesa-dev     libxi     build-base     && rm -rf /var/cache/apk/*     && npm ci --no-optional && npm cache clean --force     npm install -g gulp     && npm install gulp]: exit code: 1

我的 Dockerfile:

FROM node:16-alpine

RUN npm i npm@latest -g

WORKDIR /usr/src

COPY ./app/package*.json ./

RUN apk add --update --no-cache \
    bash \
    autoconf \
    gcc \
    g++ \
    make \
    automake \
    nasm \
    libtool \
    zlib \
    libc6-compat \
    libpng \
    libpng-dev \
    mesa-dev \
    libxi \
    build-base \
    && rm -rf /var/cache/apk/* \
    && npm ci --no-optional && npm cache clean --force \
    npm install -g gulp \
    && npm install gulp

ENV PATH /usr/src/node_modules/.bin/:$PATH

WORKDIR /usr/src/app

COPY . .


吞咽文件

import imagemin, { gifsicle, mozjpeg, optipng, svgo } from 'gulp-imagemin';

gulp.task('images', () => {
  logger('[Images] Optimizing...');
  return gulp
    .src(`${options.paths.src.img}/**/*.*`)
    .pipe(
      imagemin(
        [
          gifsicle({ interlaced: true }),
          mozjpeg({ quality: 80, progressive: true }),
          optipng({ optimizationLevel: 5 }),
          svgo({ plugins: [{ removeViewBox: true }, { cleanupIDs: false }] }),
        ],
        {
          silent: false,
        }
      )
    )
    .pipe(
      isProd
        ? gulp.dest(options.paths.build.img)
        : gulp.dest(options.paths.dist.img)
    )
    .on('end', () => logger('[Images] Success!', figures.tick, 'GREEN'))
    .on('error', () => logger('[Images] Failed', figures.cross, 'RED'));
});

包.json

{
"devDependencies": {
"gulp-imagemin": "^8.0.0",
  }
}

码头工人-compose.yml

version: '3'

volumes:
  local_postgres_data: {}
  local_postgres_data_backups: {}
  notused:

services:
  postgres:
    build:
      context: .
      dockerfile: ./app/docker/postgres/Dockerfile
    image: webapp_prodcution_postgres
    volumes:
      - local_postgres_data:/var/lib/postgresql/data:Z
      - local_postgres_data_backups:/backups:z
    env_file:
      - ./app/.envs/.local/.env

  django:
    image: webapp_local_django
    build:
      context: .
      dockerfile: ./app/docker/django/Dockerfile
    volumes:
      - ./app/:/usr/src/app/
    command: /usr/src/app/docker/django/start_dev
    ports:
      - 8000:8000
    env_file:
      - ./app/.envs/.local/.env
    depends_on:
      - postgres

  node:
    image: webapp_local_node
    build:
      context: .
      dockerfile: ./app/docker/node/Dockerfile
    depends_on:
      - django
    volumes:
      - ./app/:/usr/src/app/
      - notused:/usr/src/app/node_modules/
    command: bash -c "rm -rf /usr/src/app/node_modules/* && npm run dev"
    ports:
      - '3000:3000'

4

1 回答 1

0

我会回答我自己的问题。显然,当我尝试修复 npm 漏洞时,在resolutions我指定"bin-build"TypeError: BinBuild is not a constructor.

无论如何,主要问题是如何imagemin在 Linux 上顺利运行。以下设置运行良好:

我更新的 Dockerfile

FROM node:12-buster-slim

RUN npm i npm@latest -g

WORKDIR /usr/src

COPY ./app/package*.json ./

RUN apt-get update && apt-get install -y --no-install-recommends \
    autoconf \
    automake \
    g++ \
    libpng-dev \
    make\
    nasm \
    -y wget \
    && wget -q -O /tmp/libpng12.deb http://mirrors.kernel.org/ubuntu/pool/main/libp/libpng/libpng12-0_1.2.54-1ubuntu1_amd64.deb \
    && dpkg -i /tmp/libpng12.deb \
    && rm /tmp/libpng12.deb \
    && npm ci --no-optional && npm cache clean --force \
    npm install -g gulp \
    && npm install gulp

ENV PATH /usr/src/node_modules/.bin/:$PATH

WORKDIR /usr/src/app

COPY . .

于 2021-08-25T11:17:11.753 回答