Skip to content

Commit

Permalink
Add workshop demo of how to add cookie consent theme.
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamDumpleton committed May 14, 2024
1 parent 9ae1f16 commit d880bb1
Show file tree
Hide file tree
Showing 7 changed files with 394 additions and 0 deletions.
3 changes: 3 additions & 0 deletions workshops/lab-cookie-consent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Cookie Consent

Overview of embedding cookie consent.
196 changes: 196 additions & 0 deletions workshops/lab-cookie-consent/resources/workshop.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
apiVersion: training.educates.dev/v1beta1
kind: Workshop
metadata:
name: "lab-cookie-consent"
spec:
title: "Cookie Consent"
description: "Overview of embedding cookie consent."
publish:
image: $(image_repository)/labs-educates-showcase/lab-cookie-consent-files:$(workshop_version)
workshop:
files:
- image:
url: "$(image_repository)/labs-educates-showcase/lab-cookie-consent-files:$(workshop_version)"
includePaths:
- /workshop/**
- /exercises/**
- /README.md
packages:
- name: educates
files:
- image:
url: $(oci_image_cache)/educates-client-programs:installer-clean
path: bin
includePaths:
- educates-linux-$(platform_arch)
session:
namespaces:
budget: x-large
security:
policy: baseline
token:
enabled: false
applications:
terminal:
enabled: true
layout: split
editor:
enabled: true
console:
enabled: false
docker:
enabled: true
socket:
enabled: false
compose:
services:
registry:
image: registry:2.8.3
ports:
- "0.0.0.0:5001:5000"
registry:
enabled: false
vcluster:
enabled: false
volumes:
- name: admin-credentials-config
secret:
secretName: $(session_name)-kubeconfig
volumeMounts:
- name: admin-credentials-config
mountPath: /opt/kubeconfig
objects:
- apiVersion: v1
kind: Secret
metadata:
name: $(session_name)-admin-vcluster-values
namespace: $(workshop_namespace)
stringData:
values.yaml: |
vcluster:
image: rancher/k3s:v1.25.3-k3s1
syncer:
extraArgs:
- --tls-san=admin-vcluster.$(session_namespace).svc.$(cluster_domain)
- --out-kube-config-server=https://admin-vcluster.$(session_namespace).svc.$(cluster_domain)
mapServices:
fromHost:
- from: $(workshop_namespace)/registry-$(session_name)
to: default/registry
- from: $(workshop_namespace)/localhost-$(session_name)
to: default/loopback
sync:
ingresses:
enabled: true
- apiVersion: kappctrl.k14s.io/v1alpha1
kind: App
metadata:
name: $(session_name)-admin-vcluster-package
namespace: $(workshop_namespace)
spec:
serviceAccountName: kapp-installer
syncPeriod: 720h
noopDelete: true
fetch:
- helmChart:
name: vcluster
repository:
url: https://charts.loft.sh
template:
- helmTemplate:
name: admin-vcluster
namespace: $(session_namespace)
valuesFrom:
- secretRef:
name: $(session_name)-admin-vcluster-values
- ytt:
inline:
paths:
overlays.yaml: |
#@ load("@ytt:data", "data")
#@ load("@ytt:overlay", "overlay")
#@overlay/match by=overlay.all, expects="1+"
---
metadata:
#@overlay/match missing_ok=True
ownerReferences:
- apiVersion: training.educates.dev/v1beta1
kind: WorkshopSession
blockOwnerDeletion: true
controller: true
name: $(session_name)
uid: $(workshop_session_uid)
deploy:
- kapp:
rawOptions:
- --app-changes-max-to-keep=5
- apiVersion: secrets.educates.dev/v1beta1
kind: SecretCopier
metadata:
name: $(session_name)-kubeconfig
spec:
rules:
- sourceSecret:
name: vc-admin-vcluster
namespace: $(session_namespace)
targetNamespaces:
nameSelector:
matchNames:
- $(workshop_namespace)
targetSecret:
name: $(session_name)-kubeconfig
- apiVersion: v1
kind: Service
metadata:
name: registry-$(session_name)
namespace: $(workshop_namespace)
spec:
type: ClusterIP
selector:
deployment: $(session_name)
ports:
- name: registry
port: 80
protocol: TCP
targetPort: 5001
- apiVersion: v1
kind: Service
metadata:
name: localhost-$(session_name)
namespace: $(workshop_namespace)
spec:
type: ClusterIP
selector:
deployment: $(session_name)
ports:
- name: renderer
port: 10081
protocol: TCP
targetPort: 10081
environment:
images:
registries:
- content:
- destination: /educates-client-programs
prefix: /jorgemoralespou/educates-client-programs
stripPrefix: true
onDemand: true
urls:
- https://ghcr.io
objects:
- apiVersion: v1
kind: ServiceAccount
metadata:
name: kapp-installer
- apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kapp-installer-$(workshop_namespace)
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: kapp-installer
namespace: $(workshop_namespace)
31 changes: 31 additions & 0 deletions workshops/lab-cookie-consent/workshop/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# pathways:
# default: workshop
#
# paths:
# workshop:
# title: "Workshop"
#
# steps:
# - 00-workshop-overview
# - 01-workshop-instructions
# - 99-workshop-summary
#
# params:
# - name: NAME
# value: undefined
# aliases:
# - ALIAS

# modules:
# - name: 00-workshop-overview
# title: Workshop Overview
# - name: 01-workshop-instructions
# title: Workshop Instructions
# - name: 99-workshop-summary
# title: Workshop Summary

# params:
# - name: NAME
# value: undefined
# aliases:
# - ALIAS
145 changes: 145 additions & 0 deletions workshops/lab-cookie-consent/workshop/content/00-workshop-overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
---
title: Workshop Overview
---

Note that once `vcluster` provider config added to CLI as one of the set of opinionated configs, this can be simplified.

Download Javascript and CSS files for CookieConsent package from the CDN.

```terminal:execute
command: curl -L -o cookieconsent.css https://cdn.jsdelivr.net/gh/orestbida/[email protected]/dist/cookieconsent.css
```

```terminal:execute
command: curl -L -o cookieconsent.umd.js https://cdn.jsdelivr.net/gh/orestbida/[email protected]/dist/cookieconsent.umd.js
```

Create `.css` and `.js` files for the training portal.

```terminal:execute
command: cat cookieconsent.css > training-portal.css
```

```terminal:execute
command: cat cookieconsent.umd.js > training-portal.js
```

```terminal:execute
command: |
cat << EOF >> training-portal.js
/**
* All config. options available here:
* https://cookieconsent.orestbida.com/reference/configuration-reference.html
*/
CookieConsent.run({
categories: {
necessary: {
enabled: true, // this category is enabled by default
readOnly: true // this category cannot be disabled
},
analytics: {}
},
language: {
default: 'en',
translations: {
en: {
consentModal: {
title: 'We use cookies',
description: 'Cookie modal description',
acceptAllBtn: 'Accept all',
acceptNecessaryBtn: 'Reject all',
showPreferencesBtn: 'Manage Individual preferences'
},
preferencesModal: {
title: 'Manage cookie preferences',
acceptAllBtn: 'Accept all',
acceptNecessaryBtn: 'Reject all',
savePreferencesBtn: 'Accept current selection',
closeIconLabel: 'Close modal',
sections: [
{
title: 'Somebody said ... cookies?',
description: 'I want one!'
},
{
title: 'Strictly Necessary cookies',
description: 'These cookies are essential for the proper functioning of the website and cannot be disabled.',
//this field will generate a toggle linked to the 'necessary' category
linkedCategory: 'necessary'
},
{
title: 'Performance and Analytics',
description: 'These cookies collect information about how you use our website. All of the data is anonymized and cannot be used to identify you.',
linkedCategory: 'analytics'
},
{
title: 'More information',
description: 'For any queries in relation to my policy on cookies and your choices, please <a href="#contact-page">contact us</a>'
}
]
}
}
}
}
});
EOF
```

Create a Kubernetes secret using these as theme files.

```terminal:execute
command: kubectl create ns educates-themes
```

```terminal:execute
command: kubectl create secret generic cookieconsent-theme -n educates-themes --from-file=training-portal.css --from-file=training-portal.js
```

```editor:append-lines-to-file
file: ~/config.yaml
text: |
clusterInfrastructure:
provider: custom
clusterPackages:
contour:
enabled: false
kyverno:
enabled: false
clusterIngress:
domain: {{< param session_name >}}.{{< param ingress_domain >}}
clusterSecurity:
policyEngine: none
workshopSecurity:
rulesEngine: none
imageRegistry:
host: registry.default.svc.cluster.local
imagePuller:
enabled: false
websiteStyling:
defaultTheme: cookieconsent-theme
themeDataRefs:
- name: cookieconsent-theme
namespace: educates-themes
```

```terminal:execute
command: educates admin cluster install --config config.yaml
```

```terminal:execute
command: educates deploy-workshop -f https://github.com/vmware-tanzu-labs/lab-k8s-fundamentals/releases/latest/download/workshop.yaml
```

```terminal:execute
command: educates browse-workshops
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Workshop Instructions
---

This is the first page of the workshop instructions, create as many separate pages as you need to. If necessary pages can be located in sub directories to provided grouping.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Workshop Summary
---

This is the last page of the workshop. Include in this page a summary of the workshop and any links to resources relevant to the workshop. This ensures anyone doing the workshop has material they can research later to learn more.
Loading

0 comments on commit d880bb1

Please sign in to comment.