Last active
May 13, 2021 11:33
-
-
Save wietsevenema/7570f9e9aa2e7f56bced1cfa36d98fa1 to your computer and use it in GitHub Desktop.
Bootstrap and Deploy a Go Service to Google Cloud Run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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