fix: Docker构建时的一些权限问题

This commit is contained in:
msojocs 2022-02-26 11:15:58 +08:00
parent 2830b9a408
commit 38677f49b1
7 changed files with 71 additions and 116 deletions

View File

@ -1,7 +1,10 @@
version: "3"
services:
wechat_devtools:
image: node:16.13.1
# image: node:16.13.1
build:
context: ./docker
dockerfile: Dockerfile
volumes:
- .:/workspace
- ./cache/.npm:/root/.npm
@ -9,4 +12,6 @@ services:
- ACTION=${ACTION_MODE:-false}
# - https_proxy=${https_proxy:-}
- NO_WINE=${NO_WINE:-false}
entrypoint: /workspace/docker/entrypoint
- LOCAL_USER_ID=${UID:-1000}
entrypoint: /workspace/docker/docker-entrypoint
userns_mode: "host"

View File

@ -1,52 +1,20 @@
FROM debian:buster
LABEL maintainer="minun (minun@mewmew.cn)"
FROM node:16.13.1
ENV LANG=C.UTF-8
# update repo sources
RUN set -ex; \
cp /etc/apt/sources.list /etc/apt/sources.list.bak; \
echo "deb http://mirrors.aliyun.com/debian buster main" > /etc/apt/sources.list; \
echo "deb http://mirrors.aliyun.com/debian buster-updates main" >> /etc/apt/sources.list; \
apt-get clean; \
dpkg --add-architecture i386; \
apt-get update;
RUN set -ex; \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
apt-utils \
dbus-x11 \
libasound2 \
libatk1.0-0 \
libatomic1 \
libcanberra-gtk3-module \
libgconf-2-4 \
libgtk3.0 \
libnss3 \
libupower-glib3 \
libxtst6 \
libx11-6 \
libx11-xcb1 \
libxss1 \
libxrandr2 \
mesa-utils \
ttf-wqy-microhei \
upower \
wine \
wine32 \
wine-binfmt \
xserver-xorg-video-all;
ADD wechat-devtools-compact-1.03.2008270.tar.gz /opt/wechat/devtools
COPY docker-entrypoint /opt/wechat/devtools/bin/docker-entrypoint
# COPY spdlog.docker.node /opt/wechat/devtools/package.nw/node_modules/spdlog/build/Release/spdlog.node
# COPY spdlog.docker.node /opt/wechat/devtools/package.nw/node_modules/spdlog-node/build/Release/spdlog.node
# RUN apt-get build-essential python libx11-dev pkg-config libxkbfile-dev
# RUN useradd -m minun
# xhost +
# docker run -t -i --rm -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY -v $HOME/.Xauthority:/root/.Xauthority wechat-devtools bash
RUN echo "\
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free\
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free\
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free\
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free\
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
"> /etc/apt/sources.list && apt-get clean && \
apt-get update && set -eux; \
apt-get update; \
apt-get install -y gosu libx11-dev libxkbfile-dev p7zip-full; \
rm -rf /var/lib/apt/lists/*; \
# verify that the binary works
gosu nobody true;
WORKDIR /workspace

View File

@ -1,6 +1,33 @@
#!/bin/bash
/etc/init.d/dbus start &&
if [ "$(id -u)" -eq '0' ]
then
USER_ID=${LOCAL_USER_ID:-9001}
usermod -u ${USER_ID} -g ${USER_ID} node > /dev/null 2>&1
chown -R ${USER_ID}:${USER_ID} /workspace > /dev/null 2>&1
/opt/wechat/devtools/bin/wechat-devtools "$@"
ACTION_MODE=$( export ACTION_MODE )
if [ $ACTION_MODE!='true' ]; then
npm set registry https://r.npm.taobao.org # 注册模块镜像
npm set disturl https://npm.taobao.org/dist # node-gyp 编译依赖的 node 源码镜像
## 以下选择添加
npm set sass_binary_site https://npm.taobao.org/mirrors/node-sass # node-sass 二进制包镜像
npm set electron_mirror https://npm.taobao.org/mirrors/electron/ # electron 二进制包镜像
npm set puppeteer_download_host https://npm.taobao.org/mirrors # puppeteer 二进制包镜像
npm set chromedriver_cdnurl https://npm.taobao.org/mirrors/chromedriver # chromedriver 二进制包镜像
npm set operadriver_cdnurl https://npm.taobao.org/mirrors/operadriver # operadriver 二进制包镜像
npm set phantomjs_cdnurl https://npm.taobao.org/mirrors/phantomjs # phantomjs 二进制包镜像
npm set selenium_cdnurl https://npm.taobao.org/mirrors/selenium # selenium 二进制包镜像
npm set node_inspector_cdnurl https://npm.taobao.org/mirrors/node-inspector # node-inspector 二进制包镜像
# npm cache clean --force # 清空缓存
fi
# ls -l
# cat /etc/passwd
exec gosu node docker/entrypoint
fi
echo "nothing"
# exec /usr/local/bin/gosu user entrypoint

View File

@ -19,56 +19,10 @@ fail() {
echo -e "\033[41;37m 失败 \033[0m $1"
}
echo "start"
echo "start $UID"
python --version
echo "docker node version: $( node --version )"
ACTION_MODE=$( export ACTION_MODE )
if [ $ACTION_MODE!='true' ]; then
npm set registry https://r.npm.taobao.org # 注册模块镜像
npm set disturl https://npm.taobao.org/dist # node-gyp 编译依赖的 node 源码镜像
## 以下选择添加
npm set sass_binary_site https://npm.taobao.org/mirrors/node-sass # node-sass 二进制包镜像
npm set electron_mirror https://npm.taobao.org/mirrors/electron/ # electron 二进制包镜像
npm set puppeteer_download_host https://npm.taobao.org/mirrors # puppeteer 二进制包镜像
npm set chromedriver_cdnurl https://npm.taobao.org/mirrors/chromedriver # chromedriver 二进制包镜像
npm set operadriver_cdnurl https://npm.taobao.org/mirrors/operadriver # operadriver 二进制包镜像
npm set phantomjs_cdnurl https://npm.taobao.org/mirrors/phantomjs # phantomjs 二进制包镜像
npm set selenium_cdnurl https://npm.taobao.org/mirrors/selenium # selenium 二进制包镜像
npm set node_inspector_cdnurl https://npm.taobao.org/mirrors/node-inspector # node-inspector 二进制包镜像
# npm cache clean --force # 清空缓存
echo "\
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free\
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free\
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free\
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free\
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
"> /etc/apt/sources.list
fi
apt-get clean; # 清空缓存
apt-get update; # 更新
apt-get install -y libx11-dev libxkbfile-dev p7zip-full
echo "=====安装node-gyp nw-gyp===="
npm uninstall node-gyp -g
npm install node-gyp nw-gyp npm -g --registry=https://registry.npm.taobao.org
node-gyp install
node-gyp list
# test
# cd /
# mkdir -p test
# rm -rf test.a
# exec /workspace/tools/rebuild-node-modules
# exit 0;
# end test
cd /workspace
rm -rf node nwjs package.nw
#

View File

@ -1,17 +1,5 @@
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
let str1 = "window.screen.orientation \\x26\\x26 /^landscape/.tes";
str1 = str1
.replace(
/[^\\]((\\x[\da-f]{2}|\\u[\da-f]{4})){1,}/gi,
function ($0, $1, $2) {
console.log($0, eval('"' + $0 + '"'));
return eval('"' + $0 + '"');
}
)
.replace(/\\[\s\S]{1}/gi, function ($0, $1, $2) {
// console.log($0, $1)
const c = $0 === "\\n" ? "\n" : $0[1];
return c;
});
console.log(str1);
fs.chmodSync(path.resolve(__dirname, '../package.nw'), 0o777)

View File

@ -38,6 +38,11 @@ fi
# 将node加入环境
export PATH="$root_dir/node/bin":$PATH
echo "=====安装node-gyp nw-gyp===="
npm uninstall node-gyp -g
npm install node-gyp nw-gyp npm -g --registry=https://registry.npm.taobao.org
node-gyp install
node-gyp list
echo "==========Initializing nwjs=========="
if [ -f "$root_dir/nwjs/nw" ]; then

View File

@ -179,6 +179,14 @@ const upgrade = function (extractPath) {
path.resolve(__dirname, "../package.nw")
);
// 尝试修改权限
try {
execSync(`chmod -R 755 ${path.resolve(__dirname, '../package.nw')}`)
} catch (err) {
// ignore
console.error(err)
}
// 删除临时
execSync(`rm -rf ${extractPath}`);