From 3106afab564d1ea82f593fb2642e307b326f83cc Mon Sep 17 00:00:00 2001 From: Eric Schmidt Date: Fri, 26 Jun 2020 15:44:06 -0700 Subject: [PATCH 1/5] Add go.mod, go.sum, .gcloudignore along with Dockerfile for Cloud Run deployment --- memorystore/redis/.gcloudignore | 6 ++++ .../redis/cloud_run_deployment/Dockerfile | 31 +++++++++++++++++++ memorystore/redis/go.mod | 7 +++++ memorystore/redis/go.sum | 2 ++ 4 files changed, 46 insertions(+) create mode 100644 memorystore/redis/.gcloudignore create mode 100644 memorystore/redis/cloud_run_deployment/Dockerfile create mode 100644 memorystore/redis/go.mod create mode 100644 memorystore/redis/go.sum diff --git a/memorystore/redis/.gcloudignore b/memorystore/redis/.gcloudignore new file mode 100644 index 0000000000..ff9909ff2f --- /dev/null +++ b/memorystore/redis/.gcloudignore @@ -0,0 +1,6 @@ +cloud_run_deployment/ +gae_flex_deployment/ +gae_standard_deployment/ +gce_deployment/ +gke_deployment/ +README.md diff --git a/memorystore/redis/cloud_run_deployment/Dockerfile b/memorystore/redis/cloud_run_deployment/Dockerfile new file mode 100644 index 0000000000..09c45772b3 --- /dev/null +++ b/memorystore/redis/cloud_run_deployment/Dockerfile @@ -0,0 +1,31 @@ +# Use the official Golang image to create a build artifact. +# This is based on Debian and sets the GOPATH to /go. +# https://hub.docker.com/_/golang +FROM golang:1.13 as builder + +# Create and change to the app directory. +WORKDIR /app + +# Retrieve application dependencies. +# This allows the container build to reuse cached dependencies. +COPY go.* ./ +RUN go mod download + +# Copy local code to the container image. +COPY . ./ + +# Build the binary. +RUN CGO_ENABLED=0 GOOS=linux go build -v -o server + +# Use the official Alpine image for a lean production container. +# https://hub.docker.com/_/alpine +# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds +FROM alpine:3 +RUN apk add --no-cache ca-certificates + +# Copy the binary to the production image from the builder stage. +COPY --from=builder /app/server /server + +# Run the web service on container startup. +CMD ["/server"] + diff --git a/memorystore/redis/go.mod b/memorystore/redis/go.mod new file mode 100644 index 0000000000..9217d32949 --- /dev/null +++ b/memorystore/redis/go.mod @@ -0,0 +1,7 @@ +module github.com/GoogleCloudPlatform/golang-samples/memorystore/redis + +go 1.13 + +require ( + github.com/gomodule/redigo v2.0.0+incompatible +) diff --git a/memorystore/redis/go.sum b/memorystore/redis/go.sum new file mode 100644 index 0000000000..1192dbc2dd --- /dev/null +++ b/memorystore/redis/go.sum @@ -0,0 +1,2 @@ +github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0= +github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= From 9a7229fc370b8f3351e2d27bafd1c543521a7193 Mon Sep 17 00:00:00 2001 From: Tyler Bui-Palsulich Date: Tue, 30 Jun 2020 11:02:27 -0400 Subject: [PATCH 2/5] memorystore/redis: go mod tidy --- memorystore/redis/go.mod | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/memorystore/redis/go.mod b/memorystore/redis/go.mod index 9217d32949..730a1033d6 100644 --- a/memorystore/redis/go.mod +++ b/memorystore/redis/go.mod @@ -2,6 +2,4 @@ module github.com/GoogleCloudPlatform/golang-samples/memorystore/redis go 1.13 -require ( - github.com/gomodule/redigo v2.0.0+incompatible -) +require github.com/gomodule/redigo v2.0.0+incompatible From b8878162e44aa93f821d95e7c774aa273ddf77f1 Mon Sep 17 00:00:00 2001 From: Tyler Bui-Palsulich Date: Tue, 30 Jun 2020 11:04:58 -0400 Subject: [PATCH 3/5] badfiles_test.go: ignore .gcloudignore --- badfiles_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/badfiles_test.go b/badfiles_test.go index 11a8e68da5..9c593aaaab 100644 --- a/badfiles_test.go +++ b/badfiles_test.go @@ -50,6 +50,7 @@ var allowList = []string{ "LICENSE", "**/*Dockerfile*", "**/.dockerignore", + "**/.gcloudignore", "**/Makefile", ".gitignore", From 185113e13312b1f540049ffd556d5f3bb42ed1b4 Mon Sep 17 00:00:00 2001 From: Eric Schmidt Date: Thu, 9 Jul 2020 18:34:01 -0700 Subject: [PATCH 4/5] memorystore/redis: Update Cloud Run Dockerfile and regenerate go.mod and go.sum --- .../redis/cloud_run_deployment/Dockerfile | 34 +++++++++++++++---- memorystore/redis/go.mod | 4 +-- memorystore/redis/go.sum | 10 ++++-- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/memorystore/redis/cloud_run_deployment/Dockerfile b/memorystore/redis/cloud_run_deployment/Dockerfile index 09c45772b3..42993ebc40 100644 --- a/memorystore/redis/cloud_run_deployment/Dockerfile +++ b/memorystore/redis/cloud_run_deployment/Dockerfile @@ -1,13 +1,30 @@ -# Use the official Golang image to create a build artifact. +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START memorystore_cloud_run_dockerfile] + +# Use the offical golang image to create a binary. # This is based on Debian and sets the GOPATH to /go. # https://hub.docker.com/_/golang -FROM golang:1.13 as builder +FROM golang:1.14-buster as builder # Create and change to the app directory. WORKDIR /app # Retrieve application dependencies. # This allows the container build to reuse cached dependencies. +# Expecting to copy go.mod and if present go.sum. COPY go.* ./ RUN go mod download @@ -15,13 +32,15 @@ RUN go mod download COPY . ./ # Build the binary. -RUN CGO_ENABLED=0 GOOS=linux go build -v -o server +RUN go build -mod=readonly -v -o server -# Use the official Alpine image for a lean production container. -# https://hub.docker.com/_/alpine +# Use the official Debian slim image for a lean production container. +# https://hub.docker.com/_/debian # https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds -FROM alpine:3 -RUN apk add --no-cache ca-certificates +FROM debian:buster-slim +RUN set -x && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ + ca-certificates && \ + rm -rf /var/lib/apt/lists/* # Copy the binary to the production image from the builder stage. COPY --from=builder /app/server /server @@ -29,3 +48,4 @@ COPY --from=builder /app/server /server # Run the web service on container startup. CMD ["/server"] +# [END memorystore_cloud_run_dockerfile] diff --git a/memorystore/redis/go.mod b/memorystore/redis/go.mod index 730a1033d6..778a42a47b 100644 --- a/memorystore/redis/go.mod +++ b/memorystore/redis/go.mod @@ -1,5 +1,5 @@ module github.com/GoogleCloudPlatform/golang-samples/memorystore/redis -go 1.13 +go 1.14 -require github.com/gomodule/redigo v2.0.0+incompatible +require github.com/gomodule/redigo v1.8.2 diff --git a/memorystore/redis/go.sum b/memorystore/redis/go.sum index 1192dbc2dd..c757a0185f 100644 --- a/memorystore/redis/go.sum +++ b/memorystore/redis/go.sum @@ -1,2 +1,8 @@ -github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0= -github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gomodule/redigo v1.8.2 h1:H5XSIre1MB5NbPYFp+i1NBbb5qN1W8Y8YAQoAYbkm8k= +github.com/gomodule/redigo v1.8.2/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From 04f531b4c7a29d2806abb9665ec3b3eb229262e5 Mon Sep 17 00:00:00 2001 From: Eric Schmidt Date: Thu, 9 Jul 2020 18:40:47 -0700 Subject: [PATCH 5/5] memorystore/redis: go mod tidy --- memorystore/redis/go.sum | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/memorystore/redis/go.sum b/memorystore/redis/go.sum index c757a0185f..b5c2ef3333 100644 --- a/memorystore/redis/go.sum +++ b/memorystore/redis/go.sum @@ -1,8 +1,13 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gomodule/redigo v1.8.2 h1:H5XSIre1MB5NbPYFp+i1NBbb5qN1W8Y8YAQoAYbkm8k= github.com/gomodule/redigo v1.8.2/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=