|
@@ -164,6 +164,12 @@ go: cannot write multiple packages to non-directory ./bin/server
|
|
|
```
|
|
|
go: cannot write multiple packages to non-directory ./bin/server/main
|
|
|
```
|
|
|
+或
|
|
|
+```
|
|
|
+go: cannot write multiple packages to non-directory ./bin/app
|
|
|
+```
|
|
|
+
|
|
|
+这是因为`./cmd/server/...`路径下包含了多个包(main包和wire包),但编译命令在尝试将它们编译到一个单一文件。
|
|
|
|
|
|
需要修改Dockerfile中的以下内容:
|
|
|
|
|
@@ -173,10 +179,10 @@ RUN rm -rf /data/app/bin/
|
|
|
RUN export GOPROXY=https://goproxy.cn,direct && go mod tidy && go build -ldflags="-s -w" -o ./bin/server ${APP_RELATIVE_PATH}
|
|
|
```
|
|
|
|
|
|
-更改为:
|
|
|
+更改为(指定具体的main.go文件而不是整个目录):
|
|
|
```dockerfile
|
|
|
RUN mkdir -p /data/app/bin/
|
|
|
-RUN export GOPROXY=https://goproxy.cn,direct && go mod tidy && go build -ldflags="-s -w" -o ./bin/app ${APP_RELATIVE_PATH}
|
|
|
+RUN export GOPROXY=https://goproxy.cn,direct && go mod tidy && go build -ldflags="-s -w" -o ./bin/app ./cmd/server/main.go
|
|
|
```
|
|
|
|
|
|
2. 同时需要更新ENTRYPOINT:
|
|
@@ -189,7 +195,7 @@ ENTRYPOINT [ "./server" ]
|
|
|
ENTRYPOINT [ "./app" ]
|
|
|
```
|
|
|
|
|
|
-这种方式可以确保编译输出是一个单一的可执行文件,而不是目录结构,避免多包编译问题。
|
|
|
+这种方法的关键是直接指定main.go文件而不是使用通配符,这样就只编译单个入口文件,避免了多包编译问题。
|
|
|
|
|
|
## 验证部署
|
|
|
部署完成后,您可以通过以下方式验证服务是否正常运行:
|