-
Notifications
You must be signed in to change notification settings - Fork 962
What would be the best way to include to sqlc in the Docker build process?
#803
-
I have a typical docker image like:
WORKDIR /build
ADD go.mod go.sum vendor ./
ADD . .
RUN CGO_ENABLED=0 GOOS=linux go build -mod vendor -a -installsuffix nocgo -o /manager ./manager
BUT, now I would also like to perform the sqlc generate before building my program's binary.
I was thinking about doing something like this:
FROM golang:1.15.2-buster AS builder
WORKDIR /go
RUN go get -u github.com/tmthrgd/go-bindata
RUN go get -u github.com/kyleconroy/sqlc/cmd/sqlc
WORKDIR /build
ADD go.mod go.sum vendor ./
ADD . .
// NOTICE THIS TO GENERATE QUERIES
// NOTICE THIS TO GENERATE QUERIES
// NOTICE THIS TO GENERATE QUERIES
RUN sqlc generate
RUN CGO_ENABLED=0 GOOS=linux go build -mod vendor -a -installsuffix nocgo -o /manager ./manager
But this is failing atm right in the go get part for the master and I would like to lock sqlc to a specific version. 1.5.0 or this incoming 1.6.0.
=> ERROR [4/4] RUN go get github.com/kyleconroy/sqlc/cmd/sqlc 90.1s
------
> [4/4] RUN go get github.com/kyleconroy/sqlc/cmd/sqlc:
#7 72.66 # github.com/kyleconroy/sqlc/internal/engine/dolphin
#7 72.66 src/github.com/kyleconroy/sqlc/internal/engine/dolphin/convert.go:303:28: n.OldTable undefined (type *"github.com/pingcap/parser/ast".RenameTableStmt has no field or method OldTable)
How would you recommend to include the sqlc in the docker building process please?
Update:
For now, it seems I got it working with:
ADD https://github.com/kyleconroy/sqlc/releases/download/v1.5.0/sqlc-v1.5.0-linux-amd64.tar.gz ./
RUN tar -xzf ./sqlc-v1.5.0-linux-amd64.tar.gz --directory ./bin/
And then:
RUN cd identities && sqlc generate
RUN CGO_ENABLED=0 GOOS=linux go build -mod vendor -a -installsuffix nocgo -o /manager ./manager
But not if there is a better way.
Originally posted by @EnchanterIO in #788 (comment)
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 3 comments
-
I think your approach of directly referencing the binary is better than building sqlc from source. It should be faster and less prone to build errors.
Another option would be to use the official sqlc Docker image (https://hub.docker.com/r/kjconroy/sqlc) and multistage builds.
Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions
-
That could be a good alternative as well! I am going with the downloaded binary for now. Will let you know if I encounter some downsides of this approach.
Beta Was this translation helpful? Give feedback.
All reactions
-
Starting with Go 1.16, which will be released in February, it will be easier to do a version-specific global installation.
go install <package>@<version>
Beta Was this translation helpful? Give feedback.