Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Dockerfile.build-and-run to realize multi-stage build;fix @testin… #813

Merged
merged 5 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions Dockerfile.build-and-run
Original file line number Diff line number Diff line change
@@ -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" ]
2 changes: 1 addition & 1 deletion src/webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading