add: beancount deps, beancount build dockerfile
This commit is contained in:
parent
94ac302767
commit
b8488f5fd6
62
dockerfile
62
dockerfile
|
@ -1,61 +1,27 @@
|
|||
# 构建beancount2.3.6
|
||||
FROM python:3.11.9-alpine3.19 as beancount_builder
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
RUN echo "https://mirrors.aliyun.com/alpine/v3.16/main/" > /etc/apk/repositories \
|
||||
&& echo "https://mirrors.aliyun.com/alpine/v3.16/community/" >> /etc/apk/repositories \
|
||||
&& set -x \
|
||||
&& apk add --no-cache gcc musl-dev \
|
||||
&& python3 -mvenv /app \
|
||||
&& wget https://github.com/beancount/beancount/archive/refs/tags/2.3.6.tar.gz \
|
||||
&& tar -zxvf 2.3.6.tar.gz \
|
||||
&& /app/bin/pip install ./beancount-2.3.6 -i https://mirrors.aliyun.com/pypi/simple/ \
|
||||
&& find /app -name __pycache__ -exec rm -rf -v {} + \
|
||||
&& apk del gcc musl-dev
|
||||
|
||||
# 构建 beancount-gs
|
||||
FROM golang:1.17.3-alpine AS go_builder
|
||||
FROM golang:1.17.3 AS go_builder
|
||||
|
||||
ENV GO111MODULE=on \
|
||||
GOPROXY=https://goproxy.cn,direct \
|
||||
GIN_MODE=release \
|
||||
CGO_ENABLED=0 \
|
||||
PORT=80
|
||||
GOPROXY=https://goproxy.cn,direct \
|
||||
GIN_MODE=release \
|
||||
CGO_ENABLED=0 \
|
||||
PORT=80
|
||||
|
||||
WORKDIR /build
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
COPY public/icons /build/public/default_icons
|
||||
COPY public/icons ./public/default_icons
|
||||
RUN go build .
|
||||
|
||||
# 镜像
|
||||
FROM python:3.11.9-alpine3.19
|
||||
FROM beancount-alpine:2.3.6
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
#RUN echo "https://mirrors.aliyun.com/alpine/v3.16/main/" > /etc/apk/repositories \
|
||||
# && echo "https://mirrors.aliyun.com/alpine/v3.16/community/" >> /etc/apk/repositories \
|
||||
# && set -x \
|
||||
# && apk update \
|
||||
# && apk add --no-cache gcc musl-dev \
|
||||
# && python3 -mvenv /app/beancount \
|
||||
# && /app/beancount/bin/pip install --no-cache-dir beancount==2.3.6 -i https://mirrors.aliyun.com/pypi/simple/ \
|
||||
# && apk del gcc musl-dev
|
||||
|
||||
# 大概116M的文件
|
||||
COPY --from=beancount_builder /app /app/beancount
|
||||
|
||||
COPY --from=go_builder /build/beancount-gs /app
|
||||
COPY --from=go_builder /build/template /app/template
|
||||
COPY --from=go_builder /build/config /app/config
|
||||
COPY --from=go_builder /build/public /app/public
|
||||
COPY --from=go_builder /build/logs /app/logs
|
||||
|
||||
ENV LANG=C.UTF-8 \
|
||||
SHELL=/bin/bash \
|
||||
PS1="\u@\h:\w \$ " \
|
||||
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/app/bin:/app/beancount/bin"
|
||||
COPY --from=go_builder /app/beancount-gs ./
|
||||
COPY --from=go_builder /app/template ./template
|
||||
COPY --from=go_builder /app/config ./config
|
||||
COPY --from=go_builder /app/public ./public
|
||||
COPY --from=go_builder /app/logs ./logs
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
ENTRYPOINT [ "/bin/sh", "-c", "cp -rn /app/public/default_icons/* /app/public/icons && /app/beancount-gs -p 80" ]
|
||||
ENTRYPOINT [ "/bin/sh", "-c", "cp -rn /app/public/default_icons/* /app/public/icons && /app/beancount-gs -p 80" ]
|
|
@ -0,0 +1,49 @@
|
|||
# 第一阶段:构建阶段
|
||||
FROM python:3.11.9-alpine3.19 as builder
|
||||
|
||||
# 设置环境变量,防止 Python 创建 .pyc 文件
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
# 替换为阿里云的镜像源,并安装必要的依赖
|
||||
RUN echo "https://mirrors.aliyun.com/alpine/v3.15/main/" > /etc/apk/repositories && \
|
||||
echo "https://mirrors.aliyun.com/alpine/v3.15/community/" >> /etc/apk/repositories && \
|
||||
apk update && \
|
||||
apk add --no-cache --virtual .build-deps \
|
||||
gcc \
|
||||
g++ \
|
||||
musl-dev
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 创建虚拟环境
|
||||
RUN python3 -m venv /app/venv
|
||||
|
||||
# 将 Beancount 源码压缩包复制到容器中
|
||||
COPY beancount-2.3.6.tar.gz /app
|
||||
|
||||
# 解压 Beancount 源码到 /beancount 目录
|
||||
RUN mkdir /beancount && \
|
||||
tar -xzf /app/beancount-2.3.6.tar.gz -C /beancount --strip-components=1
|
||||
|
||||
# 激活虚拟环境并安装 Beancount
|
||||
RUN /app/venv/bin/pip install --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/ && \
|
||||
/app/venv/bin/pip install /beancount -i https://mirrors.aliyun.com/pypi/simple/ && \
|
||||
# 清理不必要的文件
|
||||
rm -rf /app/beancount-2.3.6.tar.gz && \
|
||||
find /app -name __pycache__ -exec rm -rf -v {} +
|
||||
|
||||
# 第二阶段:运行阶段
|
||||
FROM python:3.11.9-alpine3.19
|
||||
|
||||
# 设置环境变量,防止 Python 创建 .pyc 文件
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 从构建阶段复制虚拟环境到当前镜像
|
||||
COPY --from=builder /app/venv /app/venv
|
||||
|
||||
# 将虚拟环境的 bin 目录添加到 PATH 环境变量
|
||||
ENV PATH="/app/venv/bin:$PATH"
|
Binary file not shown.
|
@ -80,27 +80,27 @@ func getMaxDate(str_date1 string, str_date2 string) string {
|
|||
|
||||
// 获取1-2个日期字符串中最小的日期值
|
||||
// 如果双参数均为空,则返回账簿开始记账日期
|
||||
func getMinDate(str_date1 string, str_date2 string) string {
|
||||
//time_layout := "2006-01-02 15:04:05"
|
||||
var min_date string
|
||||
if str_date1 != "" && str_date2 == "" {
|
||||
// 只定义了第一个账户,取第一个账户的日期为准
|
||||
min_date = str_date1
|
||||
} else if str_date1 == "" && str_date2 != "" {
|
||||
// 只定义了第二个账户,取第二个账户的日期为准
|
||||
min_date = str_date2
|
||||
} else if str_date1 != "" && str_date2 != "" {
|
||||
// 重复定义的账户,取最早的时间
|
||||
t1 := getTimeStamp(str_date1)
|
||||
t2 := getTimeStamp(str_date2)
|
||||
if t1 < t2 {
|
||||
min_date = str_date1
|
||||
} else {
|
||||
min_date = str_date2
|
||||
}
|
||||
} else if str_date1 == "" && str_date2 == "" {
|
||||
// 没有定义账户,取固定日期"1970-01-01"
|
||||
min_date = "1970-01-01"
|
||||
}
|
||||
return min_date
|
||||
}
|
||||
//func getMinDate(str_date1 string, str_date2 string) string {
|
||||
// //time_layout := "2006-01-02 15:04:05"
|
||||
// var min_date string
|
||||
// if str_date1 != "" && str_date2 == "" {
|
||||
// // 只定义了第一个账户,取第一个账户的日期为准
|
||||
// min_date = str_date1
|
||||
// } else if str_date1 == "" && str_date2 != "" {
|
||||
// // 只定义了第二个账户,取第二个账户的日期为准
|
||||
// min_date = str_date2
|
||||
// } else if str_date1 != "" && str_date2 != "" {
|
||||
// // 重复定义的账户,取最早的时间
|
||||
// t1 := getTimeStamp(str_date1)
|
||||
// t2 := getTimeStamp(str_date2)
|
||||
// if t1 < t2 {
|
||||
// min_date = str_date1
|
||||
// } else {
|
||||
// min_date = str_date2
|
||||
// }
|
||||
// } else if str_date1 == "" && str_date2 == "" {
|
||||
// // 没有定义账户,取固定日期"1970-01-01"
|
||||
// min_date = "1970-01-01"
|
||||
// }
|
||||
// return min_date
|
||||
//}
|
||||
|
|
Loading…
Reference in New Issue