Slide 23
Slide 23 text
Dagger 101
FROM golang:1.19 as build
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY *.go ./
RUN CGO_ENABLED=0 GOOS=linux go build -o
/app
EXPOSE 8080
CMD ["/app"]
Dagger
Dockerfile
func Build(src *dagger.Directory) *dagger.Container {
return dag.Container().From("golang:1.19").
WithWorkdir("/app").
WithDirectory(".", src,
Include: []string{"go.mod", "go.sum"}).
WithExec([]string{"go", "mod", "download"}).
WithDirectory(".", src).
WithEnvVariable("CGO_ENABLED", "0").
WithEnvVariable("GOOS", "linux").
WithExec([]string{"go", "build", "-o", "/app"}).
WithDefaultArgs([]string{"/app"})
}