Skip to content

Instantly share code, notes, and snippets.

@wietsevenema
Last active May 13, 2021 11:33
Show Gist options
  • Save wietsevenema/7570f9e9aa2e7f56bced1cfa36d98fa1 to your computer and use it in GitHub Desktop.
Save wietsevenema/7570f9e9aa2e7f56bced1cfa36d98fa1 to your computer and use it in GitHub Desktop.
Bootstrap and Deploy a Go Service to Google Cloud Run
#!/bin/bash
GO111MODULE=on go get github.com/google/ko/cmd/ko
go mod init example
cat <<EOF - > main.go
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
http.HandleFunc("/",
func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello World")
})
log.Fatal(http.ListenAndServe(":8080", nil))
}
EOF
export PROJECT=$(gcloud config get-value project)
export KO_DOCKER_REPO=gcr.io/$PROJECT
ko publish -P example
gcloud run deploy \
--image gcr.io/$PROJECT/example \
--port 8080 \
example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment