【发布时间】:2020-04-23 13:43:47
【问题描述】:
我正在尝试为 Go 应用程序构建我的第一个 Dockerfile,并使用 DroneCI 构建管道。
DroneCI 配置如下:
kind: pipeline
type: docker
name: Build auto git tagger
steps:
- name: test and build
image: golang
commands:
- go mod download
- go test ./test
- go build ./cmd/git-tagger
- name: Build docker image
image: plugins/docker
pull: if-not-exists
settings:
username:
password:
repo:
dockerfile: ./build/ci/Dockerfile
registry:
auto_tag: true
trigger:
branch:
- master
我遵循了https://github.com/golang-standards/project-layout的结构约定:
到目前为止,Dockerfile 如下所示:
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
下一步是将 GO 应用程序二进制文件复制到容器中,这里的问题是,将编译后的二进制文件放在哪里?目前,它放入项目文件夹中。
【问题讨论】:
-
通常没关系。关键是你知道它在哪里,所以你可以执行它。
-
如何指定二进制的输出文件夹?
-
set GOBIN, or use the
-oflag。二进制文件必须位于package子树(Dockerfile 所在的位置)中,COPY 才能工作。