diff --git a/guestbook-go/Dockerfile b/guestbook-go/Dockerfile index bf25e7db3..753a56254 100644 --- a/guestbook-go/Dockerfile +++ b/guestbook-go/Dockerfile @@ -11,20 +11,36 @@ # 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. +# Use Go 1.18 base image +FROM golang:1.18 AS builder -FROM golang:1.10.0 -RUN go get github.com/codegangsta/negroni \ - github.com/gorilla/mux \ - github.com/xyproto/simpleredis/v2 +# Set the working directory WORKDIR /app -ADD ./main.go . + +# Copy Go module files and download dependencies +COPY go.mod go.sum ./ +RUN go mod download + +# Copy the source code and build the application +COPY main.go ./ RUN CGO_ENABLED=0 GOOS=linux go build -o main . +# Use a minimal base image to keep the final image small FROM scratch + +# Set the working directory WORKDIR /app -COPY --from=0 /app/main . + +# Copy the built binary from the builder stage +COPY --from=builder /app/main . + +# Copy static files COPY ./public/index.html public/index.html COPY ./public/script.js public/script.js COPY ./public/style.css public/style.css + +# Define the command to run the application CMD ["/app/main"] + +# Expose the port on which the application will run EXPOSE 3000 diff --git a/guestbook-go/go.mod b/guestbook-go/go.mod new file mode 100644 index 000000000..c36d7032d --- /dev/null +++ b/guestbook-go/go.mod @@ -0,0 +1,14 @@ +module Guestbook + +go 1.20 + +require ( + github.com/codegangsta/negroni v1.0.0 + github.com/gorilla/mux v1.8.1 + github.com/xyproto/simpleredis/v2 v2.6.5 +) + +require ( + github.com/gomodule/redigo v1.8.9 // indirect + github.com/xyproto/pinterface v1.5.3 // indirect +) \ No newline at end of file diff --git a/guestbook-go/go.sum b/guestbook-go/go.sum new file mode 100644 index 000000000..e948c6d8e --- /dev/null +++ b/guestbook-go/go.sum @@ -0,0 +1,20 @@ +github.com/codegangsta/negroni v1.0.0 h1:+aYywywx4bnKXWvoWtRfJ91vC59NbEhEY03sZjQhbVY= +github.com/codegangsta/negroni v1.0.0/go.mod h1:v0y3T5G7Y1UlFfyxFn/QLRU4a2EuNau2iZY63YTKWo0= +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.9 h1:Sl3u+2BI/kk+VEatbj0scLdrFhjPmbxOc1myhDP41ws= +github.com/gomodule/redigo v1.8.9/go.mod h1:7ArFNvsTjH8GMMzB4uy1snslv2BwmginuMs06a1uzZE= +github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= +github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= +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.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/xyproto/pinterface v1.5.3 h1:RKkNT88cwrSqD9hU4cYAO5yeo8srg4TG+74Pcj88iz0= +github.com/xyproto/pinterface v1.5.3/go.mod h1:X5B5pKE49ak7SpyDh5QvJvLH9cC9XuZNDcl5hEyYc34= +github.com/xyproto/simpleredis/v2 v2.6.5 h1:PtAz5j2UUACNHx5LetI60dbCsVMhIv1H878bND4VQK4= +github.com/xyproto/simpleredis/v2 v2.6.5/go.mod h1:OrWVubZGr0SbpAjkAQkFn/iiex2AsblBm80uhYxbjQY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= \ No newline at end of file