1、add air conf,add makefile,add dockerfile
This commit is contained in:
parent
50cab69ca0
commit
fb8010a367
46
.air.conf
Normal file
46
.air.conf
Normal file
@ -0,0 +1,46 @@
|
||||
# [Air](https://github.com/cosmtrek/air) TOML 格式的配置文件
|
||||
|
||||
# 工作目录
|
||||
# 使用 . 或绝对路径,请注意 `tmp_dir` 目录必须在 `root` 目录下
|
||||
root = "."
|
||||
tmp_dir = "tmp"
|
||||
|
||||
[build]
|
||||
# 只需要写你平常编译使用的shell命令。你也可以使用 `make`
|
||||
# Windows平台示例: cmd = "go build -o tmp\main.exe ."
|
||||
cmd = "swag init && go build -o ./tmp/main ."
|
||||
# 由`cmd`命令得到的二进制文件名
|
||||
# Windows平台示例:bin = "tmp\main.exe"
|
||||
bin = "tmp/main"
|
||||
# 自定义执行程序的命令,可以添加额外的编译标识例如添加 GIN_MODE=release
|
||||
# Windows平台示例:full_bin = "tmp\main.exe"
|
||||
full_bin = "APP_ENV=dev APP_USER=air ./tmp/main"
|
||||
# 监听以下文件扩展名的文件.
|
||||
include_ext = ["go", "tpl", "tmpl", "html"]
|
||||
# 忽略这些文件扩展名或目录
|
||||
exclude_dir = ["assets", "tmp", "vendor", "frontend/node_modules"]
|
||||
# 监听以下指定目录的文件
|
||||
include_dir = []
|
||||
# 排除以下文件
|
||||
exclude_file = []
|
||||
# 如果文件更改过于频繁,则没有必要在每次更改时都触发构建。可以设置触发构建的延迟时间
|
||||
delay = 1000 # ms
|
||||
# 发生构建错误时,停止运行旧的二进制文件。
|
||||
stop_on_error = true
|
||||
# air的日志文件名,该日志文件放置在你的`tmp_dir`中
|
||||
log = "air_errors.log"
|
||||
|
||||
[log]
|
||||
# 显示日志时间
|
||||
time = true
|
||||
|
||||
[color]
|
||||
# 自定义每个部分显示的颜色。如果找不到颜色,使用原始的应用程序日志。
|
||||
main = "magenta"
|
||||
watcher = "cyan"
|
||||
build = "yellow"
|
||||
runner = "green"
|
||||
|
||||
[misc]
|
||||
# 退出时删除tmp目录
|
||||
clean_on_exit = true
|
36
Dockerfile
Normal file
36
Dockerfile
Normal file
@ -0,0 +1,36 @@
|
||||
FROM golang:alpine AS builder
|
||||
|
||||
# 为我们的镜像设置必要的环境变量
|
||||
ENV GO111MODULE=on \
|
||||
GOPROXY=https://goproxy.cn,direct \
|
||||
CGO_ENABLED=0 \
|
||||
GOOS=linux \
|
||||
GOARCH=amd64
|
||||
|
||||
# 移动到工作目录:/build
|
||||
WORKDIR /build
|
||||
|
||||
# 将代码复制到容器中
|
||||
COPY . .
|
||||
|
||||
# 将我们的代码编译成二进制可执行文件 app
|
||||
RUN go mod tidy && go build -o dash .
|
||||
|
||||
###################
|
||||
# 接下来创建一个小镜像
|
||||
###################
|
||||
FROM alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 从builder镜像中把静态文件拷贝到当前目录
|
||||
COPY ./static .
|
||||
|
||||
# 从builder镜像中把配置文件拷贝到当前目录
|
||||
COPY ./conf .
|
||||
|
||||
# 从builder镜像中把/dist/app 拷贝到当前目录
|
||||
COPY --from=builder /build/app .
|
||||
|
||||
# 需要运行的命令
|
||||
ENTRYPOINT ["/app/dash"]
|
25
Makefile
Normal file
25
Makefile
Normal file
@ -0,0 +1,25 @@
|
||||
.PHONY: all build run gotool clean help
|
||||
|
||||
BINARY="dash"
|
||||
|
||||
all: gotool build
|
||||
|
||||
build:
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ${BINARY}
|
||||
|
||||
run:
|
||||
@go run ./
|
||||
|
||||
gotool:
|
||||
go fmt ./
|
||||
go vet ./
|
||||
|
||||
clean:
|
||||
@if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi
|
||||
|
||||
help:
|
||||
@echo "make - 格式化 Go 代码, 并编译生成二进制文件"
|
||||
@echo "make build - 编译 Go 代码, 生成二进制文件"
|
||||
@echo "make run - 直接运行 Go 代码"
|
||||
@echo "make clean - 移除二进制文件和 vim swap files"
|
||||
@echo "make gotool - 运行 Go 工具 'fmt' and 'vet'"
|
Loading…
Reference in New Issue
Block a user