Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support CYMBAL_BRANDING environment variable #602

Merged
merged 4 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ gcloud container clusters delete onlineboutique \
- **Anthos Service Mesh**: ASM requires Workload Identity to be enabled in your GKE cluster. [See the workload identity instructions](docs/workload-identity.md) to configure and deploy the app. Then, use the [service mesh guide](/docs/service-mesh.md).
- **non-GKE clusters (Minikube, Kind)**: see the [Development Guide](/docs/development-guide.md)
- **Memorystore**: [See these instructions](/docs/memorystore.md) to replace the in-cluster `redis` database with hosted Google Cloud Memorystore (redis).
- **Cymbal Shops Branding**: [See these instructions](/docs/cymbal-shops.md)


## Architecture
Expand Down
25 changes: 25 additions & 0 deletions docs/cymbal-shops.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Cymbal Shops Branding

By default, when you deploy this sample app, the "Online Boutique" branding (logo and wording) will be used.
But you may want to use Google Cloud's fictitious company, _Cymbal Shops_, instead.

To use "Cymbal Shops" branding, set the `CYMBAL_BRANDING` environment variable to `"true"` in the the Kubernetes manifest (`.yaml`) for the `frontend` Deployment.

```
Shabirmean marked this conversation as resolved.
Show resolved Hide resolved
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
spec:
...
template:
...
spec:
...
containers:
...
env:
...
- name: CYMBAL_BRANDING
value: "true"
```
2 changes: 2 additions & 0 deletions kubernetes-manifests/frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ spec:
# value: "1"
# - name: JAEGER_SERVICE_ADDR
# value: "jaeger-collector:14268"
# - name: CYMBAL_BRANDING
# value: "true"
resources:
requests:
cpu: 100m
Expand Down
29 changes: 17 additions & 12 deletions src/frontend/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ type platformDetails struct {
}

var (
templates = template.Must(template.New("").
isCymbalBrand = "true" == strings.ToLower(os.Getenv("CYMBAL_BRANDING"))
templates = template.Must(template.New("").
Funcs(template.FuncMap{
"renderMoney": renderMoney,
"renderCurrencyLogo": renderCurrencyLogo,
Expand Down Expand Up @@ -102,17 +103,18 @@ func (fe *frontendServer) homeHandler(w http.ResponseWriter, r *http.Request) {
plat.setPlatformDetails(strings.ToLower(env))

if err := templates.ExecuteTemplate(w, "home", map[string]interface{}{
"session_id": sessionID(r),
"request_id": r.Context().Value(ctxKeyRequestID{}),
"user_currency": currentCurrency(r),
"show_currency": true,
"currencies": currencies,
"products": ps,
"cart_size": cartSize(cart),
"banner_color": os.Getenv("BANNER_COLOR"), // illustrates canary deployments
"ad": fe.chooseAd(r.Context(), []string{}, log),
"platform_css": plat.css,
"platform_name": plat.provider,
"session_id": sessionID(r),
"request_id": r.Context().Value(ctxKeyRequestID{}),
"user_currency": currentCurrency(r),
"show_currency": true,
"currencies": currencies,
"products": ps,
"cart_size": cartSize(cart),
"banner_color": os.Getenv("BANNER_COLOR"), // illustrates canary deployments
"ad": fe.chooseAd(r.Context(), []string{}, log),
"platform_css": plat.css,
"platform_name": plat.provider,
"is_cymbal_brand": isCymbalBrand,
NimJay marked this conversation as resolved.
Show resolved Hide resolved
}); err != nil {
log.Error(err)
}
Expand Down Expand Up @@ -196,6 +198,7 @@ func (fe *frontendServer) productHandler(w http.ResponseWriter, r *http.Request)
"cart_size": cartSize(cart),
"platform_css": plat.css,
"platform_name": plat.provider,
"is_cymbal_brand": isCymbalBrand,
}); err != nil {
log.Println(err)
}
Expand Down Expand Up @@ -306,6 +309,7 @@ func (fe *frontendServer) viewCartHandler(w http.ResponseWriter, r *http.Request
"expiration_years": []int{year, year + 1, year + 2, year + 3, year + 4},
"platform_css": plat.css,
"platform_name": plat.provider,
"is_cymbal_brand": isCymbalBrand,
}); err != nil {
log.Println(err)
}
Expand Down Expand Up @@ -377,6 +381,7 @@ func (fe *frontendServer) placeOrderHandler(w http.ResponseWriter, r *http.Reque
"recommendations": recommendations,
"platform_css": plat.css,
"platform_name": plat.provider,
"is_cymbal_brand": isCymbalBrand,
}); err != nil {
log.Println(err)
}
Expand Down
Binary file added src/frontend/static/favicon-cymbal.ico
Binary file not shown.
170 changes: 170 additions & 0 deletions src/frontend/static/icons/Cymbal_NavLogo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions src/frontend/static/styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,14 @@ header .navbar.sub-navbar > .container {
padding-right: 26px;
}

header .navbar.sub-navbar .logo {
width: 209px;
header .top-left-logo {
height: 40px;
NimJay marked this conversation as resolved.
Show resolved Hide resolved
}

header .top-left-logo-cymbal {
height: 30px;
}

header .navbar.sub-navbar .navbar-brand {
padding: 0;
}
Expand Down
18 changes: 16 additions & 2 deletions src/frontend/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Online Boutique</title>
<title>
{{ if $.is_cymbal_brand }}
Cymbal Shops
{{ else }}
Online Boutique
{{ end }}
</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB"
crossorigin="anonymous">
<link rel="preconnect" href="https://fonts.googleapis.com">
Expand All @@ -31,7 +37,11 @@
<link rel="stylesheet" type="text/css" href="/static/styles/styles.css">
<link rel="stylesheet" type="text/css" href="/static/styles/cart.css">
<link rel="stylesheet" type="text/css" href="/static/styles/order.css">
{{ if $.is_cymbal_brand }}
<link rel='shortcut icon' type='image/x-icon' href='/static/favicon-cymbal.ico' />
{{ else }}
<link rel='shortcut icon' type='image/x-icon' href='/static/favicon.ico' />
{{ end }}
</head>

<body>
Expand All @@ -44,7 +54,11 @@
<div class="navbar sub-navbar">
<div class="container d-flex justify-content-between">
<a href="/" class="navbar-brand d-flex align-items-center">
<img src="/static/icons/Hipster_NavLogo.svg" alt="" class="logo" />
{{ if $.is_cymbal_brand }}
<img src="/static/icons/Cymbal_NavLogo.svg" alt="" class="top-left-logo-cymbal" />
{{ else }}
<img src="/static/icons/Hipster_NavLogo.svg" alt="" class="top-left-logo" />
{{ end }}
</a>
<div class="controls">

Expand Down