sample fullstack web application hosted on GKE
Spookystore is a sample web store that offers a variety of Fall items. Users can log into the store with their Google account, add products to their Cart, and initiate a Checkout. Past transactions, along with a Products inventory, are stored in a database.
- Install and start minikube:
minikube start
. - Install Skaffold
skaffold dev -f skaffold-minikube.yml
- this will deploy Spookystore to the local minikube cluster, then watch for code changes. On change, skaffold will build a new image and patch in the changes.
- Create a new GCP project
- Create a new GKE cluster
- Set up a new Service Account
- Enable the OAuth API
- Enable Cloud Datastore
- Add the Transaction Counter as a Cloud Function, and update the calls in the frontend to reflect your new Function's trigger URL.
skaffold run -f skaffold.yml
- this will build and deploy Spookystore to your GKE cluster, then halt.
note - Due to security concerns, Google's OAuth redirect will not work with a raw IP. Therefore, unless you map a domain name to the Frontend's Ingress and set up a Cloud DNS zone, you will not be able to login.
SpookyStore is a microservices-based, full-stack web application. Given that the project's goal is to use GCP products and explore how they work together, each component lives in GCP:
- Cloud DNS: A DNS Zone maps
spookystore.net
to a GKE Static IP address. - Ingress: The Static IP is assigned to the frontend web server's Ingress resource. This Ingress resource allows traffic into a Kubernetes service which fronts the frontend server container.
- Frontend: All external requests go through the Frontend web server. This server is written in Go and exposes a set of endpoints:
/home
,/checkout
, etc. The frontend renders one dynamic HTML template per page, and has some lightweight client-side javascript to handle button clicks. The CSS is Material Design Lite. - Backend: The Frontend calls the Backend web server, also written in Go. This server is gRPC-based and handles calls to Cloud Datastore.
- Cloud Datastore: holds
Product
,User
, andTransactionCounter
entities. The JSON Products inventory is added to Datastore on startup. Users are added to the database when they login with their Google account. - Cloud Functions: A small Python function increments a Total Transactions counter in Cloud Datastore. This counter keeps track of all transactions across all users. This Function is triggered in a Javascript function when any user checks out.
- Compile the backend (
spookystore
):make
- Compile the frontend (
web
) server:make web
- In a terminal tab, start the backend server:
./bin/spookystore --addr=:8001 --google-project-id=spookystore-18
- In another terminal tab,
cd ./cmd/web
and start the frontend server:
./web -addr=:8000 --spooky-store-addr=:8001 \
--google-oauth2-config=/Users/mokeefe/spooky-oauth.json \
--google-project-id=spookystore-18
- In a browser, navigate to
localhost:8000
to view the SpookyStore.
protoc -I . ./spookystore.proto --go_out=plugins=grpc:.