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

Simplify Golang images #416

Merged
merged 5 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions golang/go-cloud-run-hello-world/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Use base golang image from Docker Hub
FROM golang:1.15

# Download the dlv (delve) debugger for go (you can comment this out if unused)
RUN go get -u -v github.com/go-delve/delve/cmd/dlv
FROM golang:1.15 AS build

WORKDIR /src/hello-world

Expand All @@ -14,20 +11,23 @@ RUN go mod download
COPY . ./

# Compile the application to /app.
RUN go build -mod=readonly -v -o /app
# Skaffold passes in debug-oriented compiler flags
ARG SKAFFOLD_GO_GCFLAGS
RUN echo "Go gcflags: ${SKAFFOLD_GO_GCFLAGS}"
RUN go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -mod=readonly -v -o /app

# Now create separate deployment image
FROM gcr.io/distroless/base

# Definition of this variable is used by 'skaffold debug' to identify a golang binary.
# Default behavior - a failure prints a stack trace for the current goroutine.
# See https://golang.org/pkg/runtime/
ENV GOTRACEBACK=single

# Copy template & assets
COPY index.html /index.html
COPY assets ./assets/

# If you want to use the debugger, you need to modify the entrypoint to the
# container and point it to the "dlv debug" command:
# * UNCOMMENT the following ENTRYPOINT statement,
# * COMMENT OUT the last ENTRYPOINT statement
# Start the "dlv debug" server on port 3000 of the container.
ENTRYPOINT ["dlv", "exec", "/app", "--continue", "--accept-multiclient", "--api-version=2", "--headless", "--listen=:3000", "--log"]

# If you want to run WITHOUT the debugging server:
# * COMMENT OUT the previous ENTRYPOINT statements,
# * UNCOMMENT the following ENTRYPOINT statement.
# ENTRYPOINT ["/app"]
WORKDIR /hello-world
COPY --from=build /app ./app
COPY index.html index.html
COPY assets assets/

ENTRYPOINT ["./app"]
30 changes: 15 additions & 15 deletions golang/go-guestbook/src/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Use base golang image from Docker Hub
FROM golang:1.15

# Download the dlv (delve) debugger for go (you can comment this out if unused)
RUN go get -u -v github.com/go-delve/delve/cmd/dlv
FROM golang:1.15 as build

WORKDIR /src/backend

Expand All @@ -14,16 +11,19 @@ RUN go mod download
COPY . ./

# Compile the application to /app/backend.
RUN go build -o /app/backend .
# Skaffold passes in debug-oriented compiler flags
ARG SKAFFOLD_GO_GCFLAGS
RUN echo "Go gcflags: ${SKAFFOLD_GO_GCFLAGS}"
RUN go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -mod=readonly -v -o /app/backend .

# Now create separate deployment image
FROM gcr.io/distroless/base

# If you want to use the debugger, you need to modify the entrypoint to the
# container and point it to the "dlv debug" command:
# * UNCOMMENT the following ENTRYPOINT statement,
# * COMMENT OUT the last ENTRYPOINT statement
# Start the "dlv debug" server on port 3000 of the container.
ENTRYPOINT ["dlv", "exec", "/app/backend", "--continue", "--accept-multiclient", "--api-version=2", "--headless", "--listen=:3000", "--log"]
# Definition of this variable is used by 'skaffold debug' to identify a golang binary.
# Default behavior - a failure prints a stack trace for the current goroutine.
# See https://golang.org/pkg/runtime/
ENV GOTRACEBACK=single

# If you want to run WITHOUT the debugging server:
# * COMMENT OUT the previous ENTRYPOINT statements,
# * UNCOMMENT the following ENTRYPOINT statement.
# ENTRYPOINT ["/app/backend"]
WORKDIR /app
COPY --from=build /app/backend /app/backend
ENTRYPOINT ["/app/backend"]
32 changes: 17 additions & 15 deletions golang/go-guestbook/src/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Use base golang image from Docker Hub
FROM golang:1.15

# Download the dlv (delve) debugger for go (you can comment this out if unused)
RUN go get -u -v github.com/go-delve/delve/cmd/dlv
FROM golang:1.15 as build

WORKDIR /src/frontend

Expand All @@ -14,16 +11,21 @@ RUN go mod download
COPY . ./

# Compile the application to /app/frontend.
RUN go build -o /app/frontend .
# Skaffold passes in debug-oriented compiler flags
ARG SKAFFOLD_GO_GCFLAGS
RUN echo "Go gcflags: ${SKAFFOLD_GO_GCFLAGS}"
RUN go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -mod=readonly -v -o /app/frontend .

# Now create separate deployment image
FROM gcr.io/distroless/base

# If you want to use the debugger, you need to modify the entrypoint to the
# container and point it to the "dlv debug" command:
# * UNCOMMENT the following ENTRYPOINT statement,
# * COMMENT OUT the last ENTRYPOINT statement
# Start the "dlv debug" server on port 3000 of the container.
ENTRYPOINT ["dlv", "exec", "/app/frontend", "--continue", "--accept-multiclient", "--api-version=2", "--headless", "--listen=:3000", "--log"]
# Definition of this variable is used by 'skaffold debug' to identify a golang binary.
# Default behavior - a failure prints a stack trace for the current goroutine.
# See https://golang.org/pkg/runtime/
ENV GOTRACEBACK=single

# If you want to run WITHOUT the debugging server:
# * COMMENT OUT the previous ENTRYPOINT statements,
# * UNCOMMENT the following ENTRYPOINT statement.
# ENTRYPOINT ["/app/frontend"]
WORKDIR /app
COPY static /app/static
COPY templates /app/templates
COPY --from=build /app/frontend /app/frontend
ENTRYPOINT ["/app/frontend"]
37 changes: 20 additions & 17 deletions golang/go-hello-world/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Use base golang image from Docker Hub
FROM golang:1.15
# Go binaries are standalone, so use a multi-stage build to produce smaller images.

# Download the dlv (delve) debugger for go (you can comment this out if unused)
RUN go get -u -v github.com/go-delve/delve/cmd/dlv
# Use base golang image from Docker Hub
FROM golang:1.15 as build

WORKDIR /src/hello-world

Expand All @@ -14,16 +13,20 @@ RUN go mod download
COPY . ./

# Compile the application to /app.
RUN go build -v -o /app

# If you want to use the debugger, you need to modify the entrypoint to the
# container and point it to the "dlv debug" command:
# * UNCOMMENT the following ENTRYPOINT statement,
# * COMMENT OUT the last ENTRYPOINT statement
# Start the "dlv debug" server on port 3000 of the container.
ENTRYPOINT ["dlv", "exec", "/app", "--continue", "--accept-multiclient", "--api-version=2", "--headless", "--listen=:3000", "--log"]

# If you want to run WITHOUT the debugging server:
# * COMMENT OUT the previous ENTRYPOINT statements,
# * UNCOMMENT the following ENTRYPOINT statement.
# ENTRYPOINT ["/app"]
# Skaffold passes in debug-oriented compiler flags
ARG SKAFFOLD_GO_GCFLAGS
RUN echo "Go gcflags: ${SKAFFOLD_GO_GCFLAGS}"
RUN go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -mod=readonly -v -o /app

# Now create separate deployment image
FROM gcr.io/distroless/base

# Definition of this variable is used by 'skaffold debug' to identify a golang binary.
# Default behavior - a failure prints a stack trace for the current goroutine.
# See https://golang.org/pkg/runtime/
ENV GOTRACEBACK=single

WORKDIR /hello-world
COPY --from=build /app .
COPY template ./template
ENTRYPOINT ["./app"]