Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: 是否可以实现生成 k8s 配置文件和 Dockerfile 的功能 #197

Open
AdrianWangs opened this issue Jul 20, 2024 · 4 comments
Assignees
Labels
enhancement T-good-first-issue This issue is good for newcomers.

Comments

@AdrianWangs
Copy link

AdrianWangs commented Jul 20, 2024

No description provided.

@StellarisW StellarisW changed the title 是否可以实现生成 k8s 配置文件和 Dockerfile 的功能 Feature Request: 是否可以实现生成 k8s 配置文件和 Dockerfile 的功能 Jul 20, 2024
@StellarisW
Copy link
Member

可以说下更详细的需求,例如根据什么(idl的哪部分信息),来生成配置文件,配置文件中包含哪些信息?

@AdrianWangs
Copy link
Author

可以说下更详细的需求,例如根据什么(idl的哪部分信息),来生成配置文件,配置文件中包含哪些信息?

可以参考一下 go-zero 的代码生成工具goctl 的文档中描述的功能:https://go-zero.dev/docs/tutorials/cli/docker

我们在将部署微服务时需要编写 Dockerfile,以将我们的镜像发布并部署到 k8s,最后生成的 Dockerfile 应该类似这样:

FROM golang:alpine AS builder

LABEL stage=gobuilder

ENV CGO_ENABLED 0
ENV GOPROXY https://goproxy.cn,direct
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

RUN apk update --no-cache && apk add --no-cache tzdata

WORKDIR /build

ADD go.mod .
ADD go.sum .
RUN go mod download
COPY . .
COPY rpc_study/user_api_rpc/api/etc /app/etc
RUN go build -ldflags="-s -w" -o /app/user rpc_study/user_api_rpc/api/user.go


FROM scratch

COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai
ENV TZ Asia/Shanghai

WORKDIR /app
COPY --from=builder /app/user /app/user
COPY --from=builder /app/etc /app/etc

CMD ["./user", "-f", "etc/user.yaml"]

他应该不需要借助 idl 去生成,而是通过需要打包的服务的文件名称,获取其相对于项目的根路径的相对路径来实现

需要实现的最终效果最好如下:


$ cwgo docker --help
Generate Dockerfile

Usage:
  cwgo docker [flags]

Flags:
      --base string      The base image to build the docker image, default scratch (default "scratch")
      --branch string    The branch of the remote repo, it does work with --remote
      --exe string       The executable name in the built image
      --go string        The file that contains main function
  -h, --help             help for docker
      --home string      The goctl home path of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority
      --port int         The port to expose, default none
      --remote string    The remote git repo of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority
                         The git repo directory must be consistent with the https://github.com/zeromicro/go-zero-template directory structure
      --tz string        The timezone of the container (default "Asia/Shanghai")
      --version string   The builder golang image version

@AdrianWangs
Copy link
Author

同样的,k8s 的配置文件可以参考一下这个:https://go-zero.dev/docs/tutorials/cli/kube

这些在实际的项目部署过程中都是比较重要的文件,同时也是我们编写起来比较麻烦的文件

@StellarisW
Copy link
Member

同样的,k8s 的配置文件可以参考一下这个:https://go-zero.dev/docs/tutorials/cli/kube

这些在实际的项目部署过程中都是比较重要的文件,同时也是我们编写起来比较麻烦的文件

ok的,我找个时间支持一下

@StellarisW StellarisW self-assigned this Jul 20, 2024
@StellarisW StellarisW added the T-good-first-issue This issue is good for newcomers. label Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement T-good-first-issue This issue is good for newcomers.
Development

No branches or pull requests

2 participants