Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#225 Dockerize protoc-gen-go #228

Closed
wants to merge 1 commit into from
Closed

#225 Dockerize protoc-gen-go #228

wants to merge 1 commit into from

Conversation

con-mark
Copy link

@con-mark con-mark commented Oct 4, 2022

@con-mark
Copy link
Author

con-mark commented Oct 4, 2022

Please let me know if this is what you expected you should be able to use docker run gidari_protoc-gen-go1 and it will work as the binary

@prestonvasquez
Copy link
Contributor

prestonvasquez commented Oct 5, 2022

@con-mark This is a bit more complicated than I expected. I think we need to make the dockerfile do something like this using multi-stage builds:

FROM golang:1.19.2-alpine
WORKDIR /go
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest

FROM node:18-alpine3.15
COPY --from=0 /go ./
RUN apk add --no-cache protoc

And the compose configuration something like this:

  protoc:
    hostname: protoc
    build:
      context: .
      dockerfile: docker/protec-gen.Dockerfile
    entrypoint: protoc
    volumes:
      - /proto:/proto

And the Make target something like this:

.PHONY: proto
proto:

        docker-compose -f "docker-compose.yml" up -d \
                --remove-orphans \
                --force-recreate \
                --build protoc

        docker-compose -f "docker-compose.yml" run protoc --proto_path=proto --go_out=proto proto/db.proto

This still doesn't work quite right, but it allows us to run protoc through a volume. What are your thoughts?

@prestonvasquez prestonvasquez self-requested a review October 5, 2022 00:49
@con-mark
Copy link
Author

con-mark commented Oct 5, 2022

Hey @prestonvasquez

The only improvement I could see to this would be to update your Dockerfile as such

FROM golang:1.19.2-alpine as goBuilder
WORKDIR /go
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest

FROM node:18-alpine3.15
COPY --from=goBuilder /go ./
RUN apk add --no-cache protoc

I question your need to add a multi stage build as you could just do it all with the go image.
As for the issue I can make a little more progress by adding a copy into the Dockerfile to add in the local proto folder however when doing this you get an issue as it is missing imports from reading on stack overflow it might be to do with the includes folder.
I wish I could be more help but Go wouldn't be a language I am strong with.

Finally I have a question on why you feel the need to add to the docker compose?

you could simply use the following commands and get the same result

docker build -t protec -f docker/protec-gen.Dockerfile .
docker run protec --proto_path=proto --go_out=proto proto/db.proto

the issue you might run into with either approaches to what you wish to do is by making a binary is that they are path context specific so not sure if they would really be beneficial to do personally I would just encourage someone build the image then use an alias for the run command.

Let me know your opinion :)

@prestonvasquez
Copy link
Contributor

prestonvasquez commented Oct 6, 2022

@con-mark Thank you for looking into this. I think your analysis makes it clear that we should just hang onto this development dependency, especially since in reality any users of this library will be required to have protobuf installed.

I like the idea of migrating our docker files to a docker/ directory, however. I'm going to close this ticket but if you would like the follow up to migrate our docker files to docker/, it's yours: #241 .

Apologies for any inconvenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants