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

Statically built Client Library sample does not work when containerized #338

Closed
DazWilkin opened this issue Nov 26, 2017 · 2 comments
Closed
Labels
🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@DazWilkin
Copy link

Perplexed but anxious that this is a trivial or obvious solution. The working Docker container (#3) is 1GB and expensive to move around. If it worked, it would be more convenient, to use Docker container (#2) as this is only 12MB.

  1. Statically built sample -- works
  2. Containerize getting-started/bookshelf: use MDL UI library #1 -- doesn't work (but only 11.9MB) -- blocks (indefinitely)
  3. Containerize using golang|go-wrapper -- works (but 1.02GB!)

Took this Golang sample:
https://github.com/GoogleCloudPlatform/golang-samples/blob/master/pubsub/pubsub_quickstart/main.go
https://cloud.google.com/pubsub/docs/reference/libraries

Extended it trivially to (a) reference environment variables; (b) publish a message too:
https://gist.github.com/DazWilkin/bd8300af9f3f9be0954573304775639b

1. Static build no container

CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64 \
go build -ldflags '-extldflags "-static"' -o pubsub pubsub.go

Then:

PROJECT_ID=${PROJECT} \
PUBSUB_TOPIC=${PUB} \
GOOGLE_APPLICATION_CREDENTIALS=./key.json \
./pubsub

and:

2017/11/26 11:45:25 Topic '${PUB}' exists no need to recreate
2017/11/26 11:45:26 Message ID: 175704661496913

2. Containerize it

Dockerfile.scratch

FROM scratch
ADD pubsub /
ENTRYPOINT ["/pubsub"]

and:

docker build \
--tag=${IMAGE}:${TAG} \
--file=Dockerfile.scratch \
.

docker run \
--interactive \
--tty \
--rm \
--env=PROJECT_ID=$PROJECT \
--env=PUBSUB_TOPIC=$PUB \
--env=GOOGLE_APPLICATION_CREDENTIALS=/config/key.json \
--volume=$PWD:/config \
$IMAGE:$TAG

and appears to just block indefinitely on pubsub.NewClient(...)

3. Containerize using golang|go-wrapper

Dockerfile.golang

FROM golang:1.9

WORKDIR /go/src/app
COPY . .

RUN go-wrapper download   # "go get -d -v ./..."
RUN go-wrapper install    # "go install -v ./..."

CMD ["go-wrapper", "run"] # ["app"]

and build using the above and same run:

docker build \
--tag=${IMAGE}:${TAG} \
--file=Dockerfile.golang \
.

docker run \
--interactive \
--tty \
--rm \
--env=PROJECT_ID=$PROJECT \
--env=PUBSUB_TOPIC=$PUB \
--env=GOOGLE_APPLICATION_CREDENTIALS=/config/key.json \
--volume=$PWD:/config \
$IMAGE:$TAG

Generates:

+ exec app
2017/11/26 19:53:19 Topic $PUB' exists no need to recreate
2017/11/26 19:53:19 Message ID: 175706135054686
@DazWilkin
Copy link
Author

My colleague pointed me to Distroless.

I'm going to try that out as it appears to be my solution.

https://github.com/GoogleCloudPlatform/distroless

@DazWilkin
Copy link
Author

Distroless worked!

Dockerfile.distroless

FROM golang:1.8 as build

WORKDIR /go/src/app
COPY pubsub.go .

RUN go-wrapper download   # "go get -d -v ./..."
RUN go-wrapper install

FROM gcr.io/distroless/base
COPY --from=build /go/bin/app /
CMD ["/app"]

build and run as before:

2017/11/27 17:32:06 Topic '$PUB' exists no need to recreate
2017/11/27 17:32:06 Message ID: 175919015426938

@yoshi-automation yoshi-automation added 🚨 This issue needs some love. triage me I really want to be triaged. labels Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

2 participants