Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

What would be the best way to include to sqlc in the Docker build process? #803

Unanswered
kyleconroy asked this question in Q&A
Discussion options

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)

You must be logged in to vote

Replies: 3 comments

Comment options

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?

You must be logged in to vote
0 replies
Comment options

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.

You must be logged in to vote
0 replies
Comment options

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>

Go 1.16 Release Notes #tools

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /