Using the docker container as a build step?
What do you want to change?
This seems related to #753 , without building my own sqlc container I'm trying to figure out if I can include sqlc as part of my build process. In particular I need to pass in a custom sqlc.yaml location so am trying to do something like this (which doesn't work):
FROM kjconroy/sqlc AS sqlc-generate
WORKDIR /src
COPY . .
RUN sqlc generate -f configs/sqlc.yaml
FROM golang:1.18 AS builder
COPY --from=sqlc-generate /src/gen gen
...
The container has sqlc as the entrypoint so it's called by default, but by that point flag parsing has happened so something like RUN generate -f configs/sqlc.yaml doesn't work
What database engines need to be changed?
No response
What programming language backends need to be changed?
No response
Looks like we need to unset the ENTRYPOINT in the docker file and add sqlc to the PATH. We may also need to create a default work directory, but I'm not sure about that
The current container image cannot run RUN because the base image is scratch.
The expected usage is to use volume mount like docker run -w /sqlc -v $PWD:/sqlc kjconroy/sqlc generate.
(I think it is better to specify WORKDIR even for the current container image)
If you want to use it as a build step, you can use
FROM debian AS sqlc-generate
COPY --from=kjconroy/sqlc /workspace/sqlc /usr/bin/sqlc
WORKDIR /src
COPY . .
RUN sqlc generate -f sqlc.json
FROM golang:1.18 AS builder
COPY --from=sqlc-generate /src/gen gen gen
It would be better to use COPY --from to directly COPY the binary, but it's not much different from using curl to get the binary.
You can change the container image base image from scratch to make it easier to use in cases like this issue. However, the container image will be somewhat larger.