Go Application deployment on Google App Engine flexible environment — PKC Blog Hub

package main 
import (
func main() {
r := gin.Default()
r.GET("/", func(c *gin.Context) {
c.String(200, "Hello World")
runtime: custom 
env: flex
# FOR GAE Flexible Environment Custom RuntimeFROM golang:1.14
# Set necessary environmet variables needed for our image
ENV GO111MODULE=on \CGO_ENABLED=0 \GOOS=linux \GOARCH=amd64# install build essentialsRUN apt-get update && \apt-get install -y wget build-essential pkg-config --no-install-recommendsRUN apt-get install -y mupdf mupdf-tools# Move to working directory /buildWORKDIR /build# Copy the code into the containerCOPY . .# Copy and download dependency using go modRUN go mod download# Build the applicationRUN go build -o main .# Export necessary port # default GCP App Engine PortEXPOSE 8080# Command to run when starting the containerCMD ["/build/main"]
gcloud app deploy
  • First, Enable the Cloud SQL Admin API in the project
  • Under app.yaml, we have to tell our application to allow secure connection or else the application can connect to the database, make changes as following
runtime: custom 
env: flex
cloud_sql_instances: $INSTANCE_CONNECTION_NAME$




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Review: Vivaldi Browser for Windows

Dynamic Programming for the confused : Rod cutting problem

UMA wants to see your web3 hack skills shine at Graph Hack

the next you’re perfectly in flow, writing the most important book of your entire career.

Front-End Web Developer Roadmap

Using lein checkouts for easier development of modules

Fire-Up Your Backend With FastApi Starlette And Uvicorn

Linux Commands to perform basic operations-

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
Prajwol KC

Prajwol KC

More from Medium

How to Import a Mongo database from a cloud server to your local machine in 2 minutes

Using Sourcetree to connect to Github without password

Access ORACLE (OCI) mysql instance from public internet

Running MongoDB in a Docker Container