From ed37d455c5811fc55b8ca1848ccb7025914de0ce Mon Sep 17 00:00:00 2001 From: john tong <40350896+ColorfulDick@users.noreply.github.com> Date: Sat, 14 Dec 2024 10:51:45 +0800 Subject: [PATCH] =?UTF-8?q?add=20Dockerfile.build-and-run=20to=20realize?= =?UTF-8?q?=20multi-stage=20build;fix=20@testin=E2=80=A6=20(#813)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add Dockerfile.build-and-run to realize multi-stage build;fix @testing-library/user-event@7.2.1 has unmet peer dependency @testing-library/dom@>=5 * support download node.js according to linux arch * Revert "support download node.js according to linux arch" This reverts commit f39f4f7dfaab6b4624b7c59d64cccbdd5d00095f. * support download node.js according to linux arch * remove golang proxy of cn --------- Co-authored-by: zhongtong --- Dockerfile.build-and-run | 69 ++++++++++++++++++++++++++++++++++++++++ src/webapp/package.json | 2 +- 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 Dockerfile.build-and-run diff --git a/Dockerfile.build-and-run b/Dockerfile.build-and-run new file mode 100644 index 00000000..9d4350a6 --- /dev/null +++ b/Dockerfile.build-and-run @@ -0,0 +1,69 @@ +#docker build -t bililive-go:build . -f Dockerfile.build-and-run +FROM golang:1.23.4-bullseye AS builder + +WORKDIR /build + +#安装tar解压xz需要的xz-utils和构建web页面所需的yarn +RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ + echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ + apt-get update && \ + apt-get install -y yarn xz-utils + + +#根据架构安装构建web页面所需的node.js +RUN ARCH=$(uname -m) && \ + if [ $ARCH = 'x86_64' ]; then \ + NODE_ARCH='x64'; \ + elif [ $ARCH = 'aarch64' ]; then \ + NODE_ARCH='arm64'; \ + else \ + echo '不支持的架构: $ARCH'; \ + fi && \ + wget https://nodejs.org/dist/v18.20.3/node-v18.20.3-linux-${NODE_ARCH}.tar.xz && \ + tar Jxvf /build/node-v18.20.3-linux-${NODE_ARCH}.tar.xz && \ + rm -rf /usr/bin/node /usr/bin/npm && \ + ln -s /build/node-v18.20.3-linux-${NODE_ARCH}/bin/node /usr/bin/node && \ + ln -s /build/node-v18.20.3-linux-${NODE_ARCH}/bin/npm /usr/bin/npm + +COPY . . + +#配置golang编译环境并进行构建 +RUN go env -w GO111MODULE=on && \ + make build-web && \ + make + +RUN sh -c "/build/bin/bililive* --version" + + +FROM alpine + +ARG tag + +ENV WORKDIR="/srv/bililive" +ENV OUTPUT_DIR="/srv/bililive" \ + CONF_DIR="/etc/bililive-go" \ + PORT=8080 + +ENV PUID=0 PGID=0 UMASK=022 + +RUN mkdir -p $OUTPUT_DIR && \ + mkdir -p $CONF_DIR && \ + apk update && \ + apk --no-cache add ffmpeg libc6-compat curl su-exec tzdata && \ + cp -r -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime + +COPY --from=builder /build/bin/bililive* /usr/bin/bililive-go + + +COPY config.docker.yml $CONF_DIR/config.yml + +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +VOLUME $OUTPUT_DIR + +EXPOSE $PORT + +WORKDIR ${WORKDIR} +ENTRYPOINT [ "sh" ] +CMD [ "/entrypoint.sh" ] diff --git a/src/webapp/package.json b/src/webapp/package.json index 6af08630..a59c74ca 100644 --- a/src/webapp/package.json +++ b/src/webapp/package.json @@ -4,7 +4,7 @@ "private": true, "homepage": "./", "dependencies": { - "@testing-library/jest-dom": "^4.2.4", + "@testing-library/jest-dom": "^5.0.0", "@testing-library/react": "^9.3.2", "@testing-library/user-event": "^7.1.2", "@types/jest": "^24.0.0",