update: docker compose add env and default port change 10000

This commit is contained in:
BaoXuebin 2023-04-09 22:53:26 +08:00
parent 222dc6af3a
commit 20afafd138
4 changed files with 33 additions and 39 deletions

View File

@ -2,11 +2,15 @@ version: "3.9"
services: services:
app: app:
container_name: beancount-gs container_name: beancount-gs
image: xdbin/beancount-gs:latest image: xdbin/beancount-gs:${tag:-latest}
ports: ports:
- "10000:80" - "10000:80"
# volumes 挂载目录会导 /app/public/icons 中的图标被覆盖,这里将默认图标在挂载后重新拷贝图标
command: >
sh -c "cp -rn /app/public/default_icons/* /app/public/icons && ./beancount-gs -p 80"
volumes: volumes:
- "${dataPath:-/data/beancount}:${dataPath:-/data/beancount}" - "${dataPath:-/data/beancount}:/data/beancount"
- "${dataPath:-/data/beancount}/icons:/app/public/icons" - "${dataPath:-/data/beancount}/icons:/app/public/icons"
- "${dataPath:-/data/beancount}/config:/app/config" - "${dataPath:-/data/beancount}/config:/app/config"
- "${dataPath:-/data/beancount}/bak:/app/bak" - "${dataPath:-/data/beancount}/bak:/app/bak"
- "${dataPath:-/data/beancount}/logs:/app/logs"

View File

@ -1,7 +1,17 @@
ARG BEANCOUNT_VERSION=2.3.5 ARG BEANCOUNT_VERSION=2.3.5
ARG GOLANG_VERSION=1.17.3 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 \ ENV GO111MODULE=on \
GOPROXY=https://goproxy.cn,direct \ GOPROXY=https://goproxy.cn,direct \
@ -9,44 +19,22 @@ ENV GO111MODULE=on \
CGO_ENABLED=0 \ CGO_ENABLED=0 \
PORT=80 PORT=80
WORKDIR /tmp/build WORKDIR /build
RUN git clone https://github.com/BaoXuebin/beancount-gs.git COPY . .
COPY public/icons ./public/default_icons
WORKDIR /tmp/build/beancount-gs
RUN mkdir -p public/default_icons && cp -rn public/icons/* public/default_icons
RUN go build . 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 FROM python:3.10-alpine
COPY --from=build_env /app /app COPY --from=beancount_builder /app /app
WORKDIR /app WORKDIR /app
COPY --from=go_build_env /tmp/build/beancount-gs /app COPY --from=go_builder /build/beancount-gs ./
COPY --from=go_builder /build/template ./template
# volumes 挂载目录会导 /app/public/icons 中的图标被覆盖,这里将默认图标在挂载后重新拷贝图标 COPY --from=go_builder /build/config ./config
RUN cp -rn /app/public/default_icons/* /app/public/icons COPY --from=go_builder /build/public ./public
COPY --from=go_builder /build/logs ./logs
ENV PATH "/app/bin:$PATH" ENV PATH "/app/bin:$PATH"
EXPOSE 80
EXPOSE 80
CMD ["/app/beancount-gs", "-p", "80"]

View File

@ -101,7 +101,7 @@ func main() {
var secret string var secret string
var port int var port int
flag.StringVar(&secret, "secret", "", "服务器密钥") flag.StringVar(&secret, "secret", "", "服务器密钥")
flag.IntVar(&port, "p", 3001, "端口号") flag.IntVar(&port, "p", 10000, "端口号")
flag.Parse() flag.Parse()
// 读取配置文件 // 读取配置文件
@ -128,7 +128,7 @@ func main() {
} }
// gin 日志设置 // gin 日志设置
gin.DisableConsoleColor() gin.DisableConsoleColor()
fs, _ := os.Create("gin.log") fs, _ := os.Create("logs/gin.log")
gin.DefaultWriter = io.MultiWriter(fs) gin.DefaultWriter = io.MultiWriter(fs)
router := gin.Default() router := gin.Default()
// 注册路由 // 注册路由

2
var.env Normal file
View File

@ -0,0 +1,2 @@
tag=latest
dataPath=/data/beancount