viper-app/Dockerfile

66 lines
2.2 KiB
Docker
Raw Normal View History

2023-02-03 16:18:31 +08:00
# syntax=docker/dockerfile:1.4
##### web
FROM node:lts-alpine AS web
WORKDIR /build
ADD gui /build
RUN --mount=type=cache,id=golang-1.19.5-alpine.3.16/var/cache/apk,target=/var/cache/apk \
sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \
&& apk add gcc g++ zlib-dev nasm make autoconf automake libtool
RUN echo "network-timeout 600000" >> .yarnrc \
&& yarn config set registry https://registry.npm.taobao.org \
&& yarn config set sass_binary_site https://cdn.npm.taobao.org/dist/node-sass -g \
&& export NODE_OPTIONS=--openssl-legacy-provider \
&& yarn cache clean && yarn && yarn build
FROM golang:1.19.5-alpine3.16 as builder
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \
&& go env -w GONOSUMDB=lab.threathunter.cn \
&& go env -w GOPROXY=goproxy.threathunter.cn
WORKDIR /build
ADD . .
COPY --from=web /build/dist internal/server/web
RUN --mount=type=cache,id=golang-1.19.5-alpine.3.16/var/cache/apk,target=/var/cache/apk \
apk add gcc g++ libpcap-dev
RUN --mount=type=cache,id=golang-1.19.5-alpine3.16/go/pkg/mod,target=/go/pkg/mod \
--mount=type=cache,id=golang-1.19.5-alpine3.16/root/.cache,target=/root/.cache \
go mod download
RUN --mount=type=cache,id=golang-1.19.5-alpine3.16/go/pkg/mod,target=/go/pkg/mod \
--mount=type=cache,id=golang-1.19.5-alpine3.16/root/.cache,target=/root/.cache \
CGO_ENABLED=1 go build -a -ldflags '-w -s' -o /cmd
FROM scratch as binary
COPY --link --from=builder /cmd /cmd
#################################### base ####################################
FROM alpine:3.16 as image
# set work directory
WORKDIR /app
# set noninteractive
ENV DEBIAN_FRONTEND noninteractive
ENV PATH="/app:${PATH}"
# install zh_CN utf8
RUN --mount=type=cache,id=alpine-3.16/var/cache/apk,target=/var/cache/apk \
sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \
&& apk add su-exec tzdata bash busybox tree libpcap
COPY --link --from=binary /cmd /app/cmd
COPY --link ./deploy/sys-root /
RUN chmod +x /docker-entrypoint.sh /docker-cmd.sh /app/cmd
VOLUME [ "/app/data", "/app/conf", "/app/logs" ]
EXPOSE 20028
ENTRYPOINT [ "/docker-entrypoint.sh" ]
CMD [ "/docker-cmd.sh" ]