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

Reduced cartservice Docker Image size #46

Merged
merged 3 commits into from
Sep 24, 2018

Conversation

orthros
Copy link
Member

@orthros orthros commented Sep 21, 2018

Reduces docker image size for cartservice from ~2.36 GB to ~157 MB
Fixes Issue #36

image-size

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Sep 21, 2018
icu
WORKDIR /app
COPY --from=builder /cartservice .
ENTRYPOINT ["./cartservice", "start"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try running cart service with this? It will surprise me if this works "as-is".
For this to work, you need to create dotnet core package that can run as a standalone app.
The command line that should make it work is: dotnet cartservice.dll start

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprisingly enough it does! In the previous step the part that publishes:

 dotnet publish -c release -r linux-musl-x64 -o /cartservice

The -r linux-musl-x64 flag creates the standalone app (no runtime needed)

From my shell

$ docker build -t cartstore:opt . && docker run -it cartstore:opt
Sending build context to Docker daemon  1.957MB
Step 1/18 : FROM golang:1.10 as probe
 ---> d0e7a411e3da
Step 2/18 : RUN wget -qO/go/bin/dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 &&     chmod +x /go/bin/dep
 ---> Using cache
 ---> 7c2d74b22ce5
Step 3/18 : ENV PROJECT github.com/GoogleCloudPlatform/microservices-demo/src/cartservice/probe
 ---> Using cache
 ---> 296716190d3e
Step 4/18 : WORKDIR /go/src/$PROJECT
 ---> Using cache
 ---> 0231947d4bcb
Step 5/18 : COPY probe/Gopkg.* ./
 ---> Using cache
 ---> fd9261cf2006
Step 6/18 : RUN dep ensure --vendor-only -v
 ---> Using cache
 ---> ab4b6020b11b
Step 7/18 : COPY ./probe ./
 ---> Using cache
 ---> 36ac3ee47fb4
Step 8/18 : RUN go build -o /cartservice_probe .
 ---> Using cache
 ---> 714cc164dadf
Step 9/18 : FROM microsoft/dotnet:2.1-sdk-alpine as builder
 ---> 63ae68728eec
Step 10/18 : WORKDIR /app
 ---> Using cache
 ---> 7b7c4829e7f8
Step 11/18 : COPY . .
 ---> Using cache
 ---> f95632a78087
Step 12/18 : RUN dotnet restore &&     dotnet build &&     dotnet publish -c release -r linux-musl-x64 -o /cartservice
 ---> Using cache
 ---> 2ea27016ea29
Step 13/18 : FROM alpine:3.8
 ---> 196d12cf6ab1
Step 14/18 : COPY --from=probe /cartservice_probe /cartservice_probe
 ---> Using cache
 ---> fb7925969ab9
Step 15/18 : RUN apk add --no-cache     busybox-extras     libc6-compat     libunwind     libuuid     libgcc     libstdc++     libintl     icu
 ---> Using cache
 ---> 7c693b244cb4
Step 16/18 : WORKDIR /app
 ---> Using cache
 ---> 99dfda724b3b
Step 17/18 : COPY --from=builder /cartservice .
 ---> Using cache
 ---> 6083bf898a77
Step 18/18 : ENTRYPOINT ["./cartservice", "start"]
 ---> Using cache
 ---> 5c09c41e1d2f
Successfully built 5c09c41e1d2f
Successfully tagged cartstore:opt
Started as process with id 1
Reading host address from LISTEN_ADDR environment variable
Environment variable LISTEN_ADDR was not set. Setting the host to 0.0.0.0
Reading cart service port from PORT environment variable
PORT environment variable was not set. Setting the port to 8080
Reading redis cache address from environment variable REDIS_ADDR
Redis cache host(hostname+port) was not specified. Starting a cart service using local store
If you wanted to use Redis Cache as a backup store, you should provide its address via command line or REDIS_ADDRESS environment variable.
Local Cart Store was initialized
Trying to start a grpc server at  0.0.0.0:8080
Cart server is listening at 0.0.0.0:8080
Initialization completed

FROM gcr.io/google-appengine/aspnetcore:2.1.0
COPY --from=builder /cartservice_probe /cartservice_probe
RUN apt-get update && apt-get install net-tools telnet
FROM microsoft/dotnet:2.1-sdk-alpine as builder

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job, Colin!
I will take it with Cloud# to understand why there is such a substantial difference in image size between appengine image and this.

Copy link
Member Author

@orthros orthros Sep 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you and SGTM!

@ahmetb
Copy link
Contributor

ahmetb commented Sep 22, 2018

Thanks.

@ahmetb ahmetb merged commit ab60166 into GoogleCloudPlatform:master Sep 24, 2018
D-Mwanth pushed a commit to D-Mwanth/microservices-demo that referenced this pull request Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants