This commit is contained in:
神楽坂 白 2023-10-30 13:52:35 +00:00
parent ee8fa9eb9d
commit 4eae8f44af
2 changed files with 34 additions and 0 deletions

23
Dockerfile Normal file
View File

@ -0,0 +1,23 @@
# 使用Alpine Linux作为基础镜像
FROM golang:1.20-alpine
# 设置工作目录
WORKDIR /app
# 安装git克隆代码仓库编译应用然后卸载git
RUN echo 'nameserver 1.1.1.1' > /etc/resolv.conf && \
apk add --no-cache git && \
git clone https://gitlab.ni-co.moe/shira/temp-mail-receiver.git /tmp/code && \
cd /tmp/code && \
go build -o /app/myapp && \
cp generate-config.sh /app/generate-config.sh && \
cd /app && \
rm -rf /tmp/code && \
apk del git
# 赋予脚本执行权限
RUN chmod +x /app/generate-config.sh
# 设置启动命令
ENTRYPOINT ["/app/generate-config.sh"]
CMD ["/app/myapp", "-c", "config.json"]

11
generate-config.sh Normal file
View File

@ -0,0 +1,11 @@
#!/bin/ash
# 使用环境变量生成config.json
echo "{
\"addr\": \"$ADDR\",
\"api_url\": \"$API_URL\",
\"api_key\": $API_KEY
}" > config.json
# 执行传入的命令
exec "$@"