go-spatial / tegola

Tegola is a Mapbox Vector Tile server written in Go
http://tegola.io/
MIT License
1.25k stars 192 forks source link

Google Cloud Functions #584

Open digitaltopo opened 5 years ago

digitaltopo commented 5 years ago

Can Tegola be run as a Google Cloud Function? Does anyone have experience deploying Tegola in this way?

ARolek commented 5 years ago

@digitaltopo not yet, though a shim could be developed much like we did for AWS Lambda. Would you be interested in working on this?

gorbypark commented 4 years ago

@digitaltopo Have you considered Google Cloud Run? It's basically like Cloud Functions but runs any docker container as a function. I haven't used it with Tegola but I have deployed my GIS REST API to it and it worked flawlessly. I feel like if your config.toml used the Cloud Run PORT env variable it would "just work". I might give it a try this week.

[webserver]
port = ":${PORT}"
gorbypark commented 4 years ago

@digitaltopo I can confirm it works on Google Cloud Run. I'll put up a repo when I can sanitize my config file, but I basically created a new git repo with my config.toml and a Dockerfile like below

FROM gospatial/tegola:latest
COPY config.toml /opt/tegola_config/config.toml
ENTRYPOINT ["/opt/tegola", "serve", "--config=/opt/tegola_config/config.toml"]

and then created a trigger in Google Cloud Builder to create a docker container from the Dockerfile. Then I went into Cloud Run and created a new service using the built container and added some ENV variables. All I did in my TOML was make everything an ENV variable (this was all using the console.cloud.google.com GUI).

[webserver]
port = ":${PORT}"

# register data providers
[[providers]]
name = "mypostgis"           # provider name is referenced from map layers
type = "postgis"        # the type of data provider. currently only supports postgis
host = "${PG_HOST}"      # postgis database host
port = "${PG_PORT}"          # postgis database port
database = "${PG_DB}"       # postgis database name
user = "${PG_USER}"         # postgis database user
password = "${PG_PASSWORD}"           # postgis database password
srid = "${SRID}"

I also create a cloudbuilder.yaml to auto deploy a new Cloud Run instance whenever a new container is built in Cloud Builder. So basically I can just push an updated config to GitHub and it will auto deploy that. It's pretty slick to be honest. I haven't tested it too thoroughly but tweaking the RAM limit and concurrent connections in Cloud Run seems like all that would be required to have an "infinitely scaling" tegola setup (at least until you run into Postgres limits).