gpt4 book ai didi

php - Laravel Mix 和 alpine 3.14 权限错误

转载 作者:行者123 更新时间:2023-12-05 05:54:06 27 4
gpt4 key购买 nike

我正在尝试将我的 docker 镜像从 php:7.4-fpm-alpine3.13 升级到 php:7.4-fpm-alpine3.14,其中发生了这个问题。

错误:EACCES:权限被拒绝,打开 '/var/www/app/public/mix-manifest.json'

开发团队目前使用 Laravel Mix 生成静态文件。

日志:

/var/www/app # npm run development

> development
> mix

glob error [Error: EACCES: permission denied, scandir '/root/.npm/_logs'] {
errno: -13,
code: 'EACCES',
syscall: 'scandir',
path: '/root/.npm/_logs'
}
Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db

Why you should do it regularly:
https://github.com/browserslist/browserslist#browsers-data-updating

● Mix █████████████████████████ sealing (92%) asset processing SourceMapDevToolPlugin
attached SourceMap

internal/fs/utils.js:332
throw err;
^

Error: EACCES: permission denied, open '/var/www/app/public/mix-manifest.json'
at Object.openSync (fs.js:497:3)
at Object.writeFileSync (fs.js:1528:35)
at File.write (/var/www/app/node_modules/laravel-mix/src/File.js:211:12)
at Manifest.refresh (/var/www/app/node_modules/laravel-mix/src/Manifest.js:75:50)
at /var/www/app/node_modules/laravel-mix/src/webpackPlugins/ManifestPlugin.js:21:48
at Hook.eval [as callAsync] (eval at create (/var/www/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:12:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/var/www/app/node_modules/tapable/lib/Hook.js:18:14)
at Compiler.emitAssets (/var/www/app/node_modules/webpack/lib/Compiler.js:850:19)
at /var/www/app/node_modules/webpack/lib/Compiler.js:438:10
at processTicksAndRejections (internal/process/task_queues.js:77:11) {
errno: -13,
syscall: 'open',
code: 'EACCES',
path: '/var/www/app/public/mix-manifest.json'
}

我的 docker 文件:

FROM php:7.4-fpm-alpine3.14

ARG COMPONENT
ARG APP_ENV
ARG SRC_DIR

# Update & add nginx
RUN apk update && \
apk add nginx && mkdir -p /var/cache/nginx/ && \
chmod 777 -R /var/lib/nginx/tmp
COPY ./docker/nginx/nginx.conf /etc/nginx/nginx.conf
COPY ./docker/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf

# Give permission to nginx folder
RUN chown -R www-data:www-data /var/lib/nginx
RUN chmod 755 /var/lib/nginx/tmp/

# Add php.ini
COPY ./docker/${COMPONENT}/php.ini /etc/php7/php.ini

# Add entrypoint
COPY ./docker/${COMPONENT}/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

# Install nodejs, npm
RUN apk add --no-cache nodejs npm

# Create source code directory within container
RUN mkdir -p /var/www/app
RUN chown -R www-data:www-data /var/www/app

# Add source code from local to container
WORKDIR /var/www/app
COPY ${SRC_DIR} .

# Grant permission for folders & install packages
RUN chmod 777 -R bootstrap storage && \
cp ./env/.env.${APP_ENV} .env && \
composer install

RUN rm -rf .env
RUN npm install && npm run ${APP_ENV} && rm -rf node_modules

# Expose webserver ports
EXPOSE 80 443

# Command-line to run supervisord
CMD [ "/bin/bash", "/usr/local/bin/entrypoint.sh" ]

我尝试过的:

  • rm -rf ./node_modules 并重新安装
  • npm config set unsafe-perm true 在运行 npm 之前
  • 在 npm install 之前运行 npm config set user 0 && npm config set unsafe-perm true

感谢任何帮助!

最佳答案

时隔将近一年,再次面对宿敌,这一次我告诉自己,一定要一劳永逸地解决这个问题。对于将来面临这个问题的人来说,这就是您在 Alpine Image 上运行 Laravel-Mix 和 Nodejs 所需要的

有两个选项:

#1如果您固执,请使用从 musl 构建的 nodejs 14 的非官方图像运行它,而不是从 Alpine Repository 官方提供的包。然后提取可执行文件(node14.4.0 和 npm6.14.5)并将其添加到 PATH

FROM php:8-fpm-alpine3.15
ARG SRC_DIR
...
# setting up packages bla bla
...

# Install nodejs 14 from unofficial repo instead of
# This will not work RUN apk add --no-cache nodejs npm
RUN wget https://unofficial-builds.nodejs.org/download/release/v14.4.0/node-v14.4.0-linux-x64-musl.tar.xz -P /opt/
RUN tar -xf /opt/node-v14.4.0-linux-x64-musl.tar.xz -C /opt/
ENV PATH="$PATH:/opt/node-v14.4.0-linux-x64-musl/bin"
...

WORKDIR /var/www/app
COPY ${SRC_DIR} .
...
RUN npm install
# Generating static
RUN npm run dev
...

#2使用多阶段构建使用固定版本的节点构建静态而不是在 php alpine 图像上安装节点(这是我的主管暗示的,我不明白为什么我以前从未想过,愚蠢的我)

FROM node:14-alpine AS node_builder
ARG SRC_DIR

RUN mkdir -p /var/www/mix
WORKDIR /var/www/mix

COPY ${SRC_DIR} ./

# Installs all node packages
RUN npm install
# Generating static into /var/www/mix
RUN npm run dev

FROM php:8-fpm-alpine3.15 as php_final
...
# setting up packages bla bla
...
WORKDIR /var/www/app
COPY ${SRC_DIR} .

COPY --from=node_builder /var/www/mix/public ./public/
...

关于php - Laravel Mix 和 alpine 3.14 权限错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69720164/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com