Automate Cloud Run deployment in a minute

  1. Run Go locally
  2. Run Go on Google Cloud Run
  1. Running Go locally -:
+-- Dockerfile
+-- docker-compose.yml
+-- app
| +-- app.go
FROM golang:1.10COPY ./app /go/src/github.com/user/sites/app
WORKDIR /go/src/github.com/user/sites/app
RUN go get -u github.com/gin-gonic/gin && go get ./RUN go buildCMD go get github.com/pilu/fresh && \
fresh; \
EXPOSE 8080
version: '2'
services:
golang.go:
container_name: golang.go
build: ./
environment:
- VIRTUAL_HOST=custom.pv
- APP_ENV=dev
volumes:
- ./app:/go/src/github.com/user/sites/app
ports:
- "5000:8080"
package mainimport (
"github.com/gin-gonic/gin"
"fmt"
)
func regRoutes(routes *gin.Engine) { routes.GET("/", func(c *gin.Context) {
c.JSON(200, gin.H{
"status": "up",
})
})}func main() { routes := gin.Default()
regRoutes(routes)
routes.Run() // run in 8080 port
}
components install beta --quiet gcloud auth configure-docker
docker build -t golangcloudrun:latest .docker tag  golangcloudrun:latest gcr.io/${{ secrets.GCLOUD_PROJECT_ID }}/golangcloudrun docker push gcr.io/${{ secrets.GCLOUD_PROJECT_ID }}/golangcloudrun:latest 
** components install beta --quiet **** gcloud beta run deploy ${CLOUD_RUN_SERVICE_NAME} — image gcr.io/${{ GCLOUD_PROJECT_ID }}/golangcloudrun — platform managed — region us-central1 — project=${{ secrets.GCLOUD_PROJECT_ID }} **

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store