forked from BaoXuebin/beancount-gs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: beancount deps, beancount build dockerfile
- Loading branch information
Showing
4 changed files
with
87 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters