api2html go mod 支持以及dockerfile 修改

api2html 是一个很不错的工具,但是因为时间问题,代码使用go vender 模式,不是很方便,同时构建也不方便
所以调整了下,支持go mod ,而且修改了dockerfile 构建,基于multi stage

go mod 生成

很简单使用go mod init 命令就可以了

 
go mod init github.com/devopsfaith/api2html

dockerfile

使用多阶段构建

FROM golang:1.15-alpine AS build-env
WORKDIR /go/src/app
ENV  GO111MODULE=on
ENV  GOPROXY=https://goproxy.cn
COPY . .
RUN set -x 
    && /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories 
    && apk update && apk add git 
    && go build
FROM alpine:latest
RUN set -x 
    && /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories 
    && apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
COPY --from=build-env /go/src/app/api2html .
ENTRYPOINT [ "./api2html" ]
CMD ["-h"]

说明

相关代码以及镜像已经放github 了容器镜像为dalongrong/api2html,具体使用方法可以参考api2html 官方文档

参考资料

https://github.com/rongfengliang/api2html
https://github.com/devopsfaith/api2html
https://api2html.com/

原文地址:https://www.cnblogs.com/rongfengliang/p/14196860.html