Last active
April 19, 2022 06:16
-
-
Save tatsuyasusukida/64b6bbff77e0f560a57878be2dd55cee to your computer and use it in GitHub Desktop.
Cloud Run Golang Example
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
module loremipsum.co.jp/column-cloudrun-go | |
go 1.18 |
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
package main | |
import ( | |
"encoding/json" | |
"log" | |
"net/http" | |
"os" | |
) | |
func main() { | |
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { // <1> | |
var res struct { // <2> | |
Ok bool `json:"ok"` | |
} | |
res.Ok = true | |
b, err := json.Marshal(&res) // <3> | |
if err != nil { // <4> | |
log.Println(err) | |
w.WriteHeader(500) | |
return | |
} | |
w.WriteHeader(200) // <5> | |
w.Write(b) // <6> | |
}) | |
port := os.Getenv("PORT") // <7> | |
log.Printf("Listening on %v", port) | |
log.Fatal(http.ListenAndServe(":"+port, nil)) // <8> | |
} |
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
IMAGE = asia-northeast1-docker.pkg.dev/`gcloud config get-value project`/cloud-run/column-cloudrun-nodejs | |
build: | |
pack build column-cloudrun-go --builder gcr.io/buildpacks/builder | |
tag: | |
docker image tag column-cloudrun-go $(IMAGE) | |
push: | |
docker image push $(IMAGE) | |
deploy: | |
gcloud run deploy column-cloudrun-go \ | |
--image $(IMAGE) \ | |
--region asia-northeast1 \ | |
--platform managed \ | |
--allow-unauthenticated | |
staging: build tag push deploy | |
delete: | |
gcloud run services delete column-cloudrun-go \ | |
--region asia-northeast1 \ | |
--platform managed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment