A simple API to return fortunes. Written in Go and deployed to AppEngine Managed VMs. The deployment target (AppEngine Managed VMs) necessitates some changes within the Go app from the standard library and using AppEngine, in general, necessitates familiarity with app.yaml
.
AppEngine Managed VM golang app with project directory structure as per gb, an alternative Go build tool.
- Docker
gcloud
- Go
gcloud components update gae-go app
go get -u google.golang.org/appengine
A Google Cloud Project will be necessary at this point to do a trial build or development.
Google Cloud Project gdgnoco-fortune
(refered to as PROJECT_NAME
)
First login with gcloud config set project
then run the local Docker vm via gcloud preview app run
gcloud config set project PROJECT_NAME
gcloud preview app run ./app.yaml
Deploying is done via the gcloud preview app deploy
command.
gcloud preview app deploy ./app.yaml
- parse out
\n\t\t-- AUTHOR\n
as author, add to Fortune struct - nice front web page, use React/Riot/Polymer/Angular to call api and show fortune
- unescape braindead string parsing
- use other features of Google AppEngine (Datastore) to allow custom fortunes
FYI, what makes an AppEngine app a Managed VM app are the following additions to app.yaml
runtime: go
vm: true
api_version: go1
Basic gcr Dockerfile looks in the project root folder. Change the COPY
command to point to the local package source src/gdg-fortunecookieapi
(since we're using a gb project structure)
COPY ./src/gdg-fortunecookieapi /go/src/app
To remove exited docker containers (on OSX w/ boot2docker, therefore no sudo
)
docker rm $(docker ps -a | grep Exited | awk '{print $NF}')
To remove unassociated/untagged docker images
docker rmi $(docker images | grep "^<none>" | awk '{print $3}')