diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..eec1ee0 --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/generate-config.sh b/generate-config.sh new file mode 100644 index 0000000..fa237c5 --- /dev/null +++ b/generate-config.sh @@ -0,0 +1,11 @@ +#!/bin/ash + +# 使用环境变量生成config.json +echo "{ + \"addr\": \"$ADDR\", + \"api_url\": \"$API_URL\", + \"api_key\": $API_KEY +}" > config.json + +# 执行传入的命令 +exec "$@" \ No newline at end of file