From 20afafd138f43c73586cfbeb4577b8b5044cae27 Mon Sep 17 00:00:00 2001 From: BaoXuebin Date: Sun, 9 Apr 2023 22:53:26 +0800 Subject: [PATCH] update: docker compose add env and default port change 10000 --- docker-compose.yml | 10 ++++++--- dockerfile | 56 ++++++++++++++++++---------------------------- server.go | 4 ++-- var.env | 2 ++ 4 files changed, 33 insertions(+), 39 deletions(-) create mode 100644 var.env diff --git a/docker-compose.yml b/docker-compose.yml index a72bee6..e9320d1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,11 +2,15 @@ version: "3.9" services: app: container_name: beancount-gs - image: xdbin/beancount-gs:latest + image: xdbin/beancount-gs:${tag:-latest} ports: - "10000:80" + # volumes 挂载目录会导 /app/public/icons 中的图标被覆盖,这里将默认图标在挂载后重新拷贝图标 + command: > + sh -c "cp -rn /app/public/default_icons/* /app/public/icons && ./beancount-gs -p 80" volumes: - - "${dataPath:-/data/beancount}:${dataPath:-/data/beancount}" + - "${dataPath:-/data/beancount}:/data/beancount" - "${dataPath:-/data/beancount}/icons:/app/public/icons" - "${dataPath:-/data/beancount}/config:/app/config" - - "${dataPath:-/data/beancount}/bak:/app/bak" \ No newline at end of file + - "${dataPath:-/data/beancount}/bak:/app/bak" + - "${dataPath:-/data/beancount}/logs:/app/logs" \ No newline at end of file diff --git a/dockerfile b/dockerfile index 7606329..338f242 100644 --- a/dockerfile +++ b/dockerfile @@ -1,7 +1,17 @@ ARG BEANCOUNT_VERSION=2.3.5 ARG GOLANG_VERSION=1.17.3 -FROM golang:${GOLANG_VERSION} AS go_build_env +# 构建 beancount +FROM python:latest as beancount_builder +WORKDIR /build +ENV PATH "/app/bin:$PATH" +RUN python3 -mvenv /app +RUN git clone -b ${BEANCOUNT_VERSION} https://github.com/beancount/beancount.git +RUN python3 -m pip install ./beancount -i https://mirrors.aliyun.com/pypi/simple/ +RUN find /app -name __pycache__ -exec rm -rf -v {} + + +# 构建 beancount-gs +FROM golang:${GOLANG_VERSION} AS go_builder ENV GO111MODULE=on \ GOPROXY=https://goproxy.cn,direct \ @@ -9,44 +19,22 @@ ENV GO111MODULE=on \ CGO_ENABLED=0 \ PORT=80 -WORKDIR /tmp/build -RUN git clone https://github.com/BaoXuebin/beancount-gs.git - -WORKDIR /tmp/build/beancount-gs -RUN mkdir -p public/default_icons && cp -rn public/icons/* public/default_icons - +WORKDIR /build +COPY . . +COPY public/icons ./public/default_icons RUN go build . -FROM python:latest as build_env -ARG BEANCOUNT_VERSION - -ENV PATH "/app/bin:$PATH" -RUN python3 -mvenv /app - -WORKDIR /tmp/build -RUN git clone https://github.com/beancount/beancount - -WORKDIR /tmp/build/beancount -RUN git checkout ${BEANCOUNT_VERSION} - -RUN CFLAGS=-s pip3 install -U /tmp/build/beancount - -RUN pip3 uninstall -y pip - -RUN find /app -name __pycache__ -exec rm -rf -v {} + - +# 镜像 FROM python:3.10-alpine -COPY --from=build_env /app /app +COPY --from=beancount_builder /app /app WORKDIR /app -COPY --from=go_build_env /tmp/build/beancount-gs /app - -# volumes 挂载目录会导 /app/public/icons 中的图标被覆盖,这里将默认图标在挂载后重新拷贝图标 -RUN cp -rn /app/public/default_icons/* /app/public/icons +COPY --from=go_builder /build/beancount-gs ./ +COPY --from=go_builder /build/template ./template +COPY --from=go_builder /build/config ./config +COPY --from=go_builder /build/public ./public +COPY --from=go_builder /build/logs ./logs ENV PATH "/app/bin:$PATH" - -EXPOSE 80 - -CMD ["/app/beancount-gs", "-p", "80"] \ No newline at end of file +EXPOSE 80 \ No newline at end of file diff --git a/server.go b/server.go index 68d957c..fdf282b 100644 --- a/server.go +++ b/server.go @@ -101,7 +101,7 @@ func main() { var secret string var port int flag.StringVar(&secret, "secret", "", "服务器密钥") - flag.IntVar(&port, "p", 3001, "端口号") + flag.IntVar(&port, "p", 10000, "端口号") flag.Parse() // 读取配置文件 @@ -128,7 +128,7 @@ func main() { } // gin 日志设置 gin.DisableConsoleColor() - fs, _ := os.Create("gin.log") + fs, _ := os.Create("logs/gin.log") gin.DefaultWriter = io.MultiWriter(fs) router := gin.Default() // 注册路由 diff --git a/var.env b/var.env new file mode 100644 index 0000000..cf6cbb1 --- /dev/null +++ b/var.env @@ -0,0 +1,2 @@ +tag=latest +dataPath=/data/beancount \ No newline at end of file