crystal-helloworld

This simple web server, replies with a "Hello world" message, along with the HTTP parameter string.

Click on the below button to:

  1. Launch a Cloud Shell machine
  2. Download this GitHub repository
  3. Build a container using Docker
  4. Push the container into Google Container Regsitry
  5. Launch Cloud Run

All automatically...

Run on Google Cloud

If you are not familiar with Crystal, it is very similar to the Ruby language, but it is compiled. The following docker image is only a few MB in size.

I have added a Makefile to simply building and deploying the executable.

Test

curl http:<Cloud Run URL>/hi/nick
Hello world, got /hi/nick

Clean up

gcloud run services delete crystal-webserver

Don't forget to delete the GCR repo as well.

Available make commands

$ make
Available targets:

  build/cloud                         Build docker container in Cloud
  build/docker                        Build docker container locally
  build/local                         Compiles source using shards command
  clean/cloud                         Delete Cloud Run service and container
  deploy                              Deploy container to Cloud Run
  docker/login                        Configures Docker to authenticate to GCR
  help                                This help screen
  logs                                Examine the logs from the Cloud container
  logs/stream                         Stream Cloud Run logs
  watch                               Locally run program with dynamic recompile

Resources

Cloud Run

  1. https://github.com/GoogleCloudPlatform/cloud-run-button

GNU Make

  1. GNU make
  2. The Art of Makefiles
  3. Makefile Best Practices
  4. Learn Makefiles

Notes

Send authorization token, if unauthenticated is not allowed

curl --header "Authorization: Bearer $(gcloud auth print-identity-token)" [URL]

It is now possible to send requests via a local proxy, even if the service is authenticated.

gcloud beta run services proxy