Day 15 Solution to #25daysofserverless using Cloud Run and Go
I may be a tad late to this challenge but that may be because I had to learn a bit of Golang first. I’ve never really used it before but after a couple of weeks, honestly, it’s starting to grow on me. If you are looking to get started with Go, I definitely recommend using some of the extensions that VSCode community has to offer. Not trying to plug their IDE but it’s actually been kind of nice. And that’s coming from a die-hard Sublime fan.
All of the code in my previous articles used Python and but in 2020, I want to add more Go, GCP, Kubernetes, and possibly Azure content. In the meantime, I thought I’d start off the new year with the Day 15 Solution to 25 Days of Serverless challenges found on their Github. While these are mostly Azure related challenges, I thought it’d be fun do a few using GCP. I solved a few other days so the solutions are here.
For this challenge, we were required to create a service that, given an image, will describe some keywords about the uploaded image. You’ll need to be authenticated with the right role via gcloud and Docker authorization to be able to perform the docker commands below.
I deployed an instance of Cloud Run with the Dockerfile and main.go found here using the follow commands:
docker build -t gcr.io/$GCP_PROJECT_NAME/day15 . && docker push gcr.io/$GCP_PROJECT_NAME/day15 && gcloud beta run deploy $CLOUD_RUN_NAME --image gcr.io/$GCP_PROJECT_NAME/day15 --region=us-central1 --platform=managed
This return a link that I could upload an image to and get some labels back about the image. In the background, when an image is uploaded, a temp file is created, uploaded to a Google Cloud Storage bucket, then removed (not from the bucket). Then the Cloud Vision API is called to scan and return labels found in the image back to the page. Demo images below:
While it’s not the prettiest or secure code, I’m not going to go into detail on the code for this post in order to keep it on the shorter side (the main.go file has some descriptions/comments anyways).
This challenge helped me get more familiar with a language I’ve been super curious about lately so I’m happy about that. Once again, thanks for taking the time to read… oh…