Move Cloud Run image property to GCP config struct
Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com>
This commit is contained in:
13
examples/cloudrun-app/go-http-server/.dockerignore
Normal file
13
examples/cloudrun-app/go-http-server/.dockerignore
Normal file
@@ -0,0 +1,13 @@
|
||||
# The .dockerignore file excludes files from the container build process.
|
||||
#
|
||||
# https://docs.docker.com/engine/reference/builder/#dockerignore-file
|
||||
|
||||
# Exclude locally vendored dependencies.
|
||||
vendor/
|
||||
|
||||
# Exclude "build-time" ignore files.
|
||||
.dockerignore
|
||||
.gcloudignore
|
||||
|
||||
# Exclude git history and configuration.
|
||||
.gitignore
|
33
examples/cloudrun-app/go-http-server/Dockerfile
Normal file
33
examples/cloudrun-app/go-http-server/Dockerfile
Normal file
@@ -0,0 +1,33 @@
|
||||
# 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.16-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
|
||||
|
||||
# Copy local code to the container image.
|
||||
COPY . ./
|
||||
|
||||
# Build the binary.
|
||||
RUN go build -v -o server
|
||||
|
||||
# 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 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 /app/server
|
||||
|
||||
# Run the web service on container startup.
|
||||
CMD ["/app/server"]
|
3
examples/cloudrun-app/go-http-server/go.mod
Normal file
3
examples/cloudrun-app/go-http-server/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module github.com/dagger-cloud-run-example
|
||||
|
||||
go 1.16
|
35
examples/cloudrun-app/go-http-server/main.go
Normal file
35
examples/cloudrun-app/go-http-server/main.go
Normal file
@@ -0,0 +1,35 @@
|
||||
// Sample run-helloworld is a minimal Cloud Run service.
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.Print("starting server...")
|
||||
http.HandleFunc("/", handler)
|
||||
|
||||
// Determine port for HTTP service.
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = "8080"
|
||||
log.Printf("defaulting to port %s", port)
|
||||
}
|
||||
|
||||
// Start HTTP server.
|
||||
log.Printf("listening on port %s", port)
|
||||
if err := http.ListenAndServe(":"+port, nil); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func handler(w http.ResponseWriter, r *http.Request) {
|
||||
name := os.Getenv("NAME")
|
||||
if name == "" {
|
||||
name = "World"
|
||||
}
|
||||
fmt.Fprintf(w, "Hello %s!\n", name)
|
||||
}
|
Reference in New Issue
Block a user