Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.
Open

Dev #150

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
33 changes: 0 additions & 33 deletions .circleci/config.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM node:9

# test command
WORKDIR /app

RUN npm install -g contentful-cli
Expand Down
125 changes: 1 addition & 124 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,124 +1 @@
## The node.js example app

[![CircleCI](https://img.shields.io/circleci/project/github/contentful/the-example-app.nodejs.svg)](https://circleci.com/gh/contentful/the-example-app.nodejs)

The node.js example app teaches the very basics of how to work with Contentful:

- consume content from the Contentful Delivery and Preview APIs
- model content
- edit content through the Contentful web app

The app demonstrates how decoupling content from its presentation enables greater flexibility and facilitates shipping higher quality software more quickly.

<a href="https://the-example-app-nodejs.herokuapp.com/" target="_blank"><img src="https://images.contentful.com/qz0n5cdakyl9/4GZmvrdodGM6CksMCkkAEq/700a527b8203d4d3ccd3c303c5b3e2aa/the-example-app.png" alt="Screenshot of the example app"/></a>

You can see a hosted version of `The node.js example app` on <a href="https://the-example-app-nodejs.contentful.com/" target="_blank">Heroku</a>.

## What is Contentful?

[Contentful](https://www.contentful.com) provides a content infrastructure for digital teams to power content in websites, apps, and devices. Unlike a CMS, Contentful was built to integrate with the modern software stack. It offers a central hub for structured content, powerful management and delivery APIs, and a customizable web app that enable developers and content creators to ship digital products faster.

## Requirements

* Node 8
* Git
* Contentful CLI (only for write access)

Without any changes, this app is connected to a Contentful space with read-only access. To experience the full end-to-end Contentful experience, you need to connect the app to a Contentful space with read _and_ write access. This enables you to see how content editing in the Contentful web app works and how content changes propagate to this app.

## Common setup

Clone the repo and install the dependencies.

```bash
git clone https://github.com/contentful/the-example-app.nodejs.git
cd the-example-app.nodejs
```

```bash
npm install
```

## Steps for read-only access

To start the express server, run the following

```bash
npm run start:dev
```

Open [http://localhost:3000](http://localhost:3000) and take a look around.


## Steps for read and write access (recommended)

Step 1: Install the [Contentful CLI](https://www.npmjs.com/package/contentful-cli)

Step 2: Login to Contentful through the CLI. It will help you to create a [free account](https://www.contentful.com/sign-up/) if you don't have one already.
```
contentful login
```
Step 3: Create a new space
```
contentful space create --name 'My space for the example app'
```
Step 4: [Seed](https://github.com/contentful/contentful-cli/tree/master/docs/space/seed) the new space with the example content model [`the-example-app`](https://github.com/contentful/content-models/tree/master/the-example-app). Replace the `SPACE_ID` with the id returned from the create command executed in step 3
```
contentful space seed -s '<SPACE_ID>' -t the-example-app
```
Step 5: Head to the Contentful web app's API section and grab `SPACE_ID`, `DELIVERY_ACCESS_TOKEN`, `PREVIEW_ACCESS_TOKEN`.

Step 6: Open `variables.env` and inject your credentials so it looks like this

```
NODE_ENV=development
CONTENTFUL_SPACE_ID=<SPACE_ID>
CONTENTFUL_DELIVERY_TOKEN=<DELIVERY_ACCESS_TOKEN>
CONTENTFUL_PREVIEW_TOKEN=<PREVIEW_ACCESS_TOKEN>
PORT=3000
```

Step 7: To start the express server, run the following
```bash
npm run start:dev
```
Final Step:

Open [http://localhost:3000?editorial_features=enabled](http://localhost:3000?editorial_features=enabled) and take a look around. This URL flag adds an “Edit” button in the app on every editable piece of content which will take you back to Contentful web app where you can make changes. It also adds “Draft” and “Pending Changes” status indicators to all content if relevant.

## Deploy to Heroku
You can also deploy this app to Heroku:

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)


## Use Docker
You can also run this app as a Docker container:

Step 1: Clone the repo

```bash
git clone https://github.com/contentful/the-example-app.nodejs.git
```

Step 2: Build the Docker image

```bash
docker build -t the-example-app.nodejs .
```

Step 3: Run the Docker container locally:

```bash
docker run -p 3000:3000 -d the-example-app.nodejs
```

If you created your own Contentful space, you can use it by overriding the following environment variables:

```bash
docker run -p 3000:3000 \
-e CONTENTFUL_SPACE_ID=<SPACE_ID> \
-e CONTENTFUL_DELIVERY_TOKEN=<DELIVERY_ACCESS_TOKEN> \
-e CONTENTFUL_PREVIEW_TOKEN=<PREVIEW_ACCESS_TOKEN> \
-d the-example-app.nodejs
```
testtttt
5 changes: 5 additions & 0 deletions helm-chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
name: APP_NAME
version: TEMP_CHART_VERSION
appVersion: TEMP_APP_VERSION
description: sample-nodejs-app
10 changes: 10 additions & 0 deletions helm-chart/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: vol-configs-{{ .Release.Name }}
namespace: {{ .Values.namespace }}
labels:
app: {{ .Values.metadata.name }}
part-of: {{ .Values.metadata.labels.partOf }}
data:
{{- toYaml .Values.configmap.data | nindent 2 }}
54 changes: 54 additions & 0 deletions helm-chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.metadata.name }}
namespace: {{ .Values.metadata.namespace }}
labels:
app: {{ .Values.metadata.name }}
part-of: {{ .Values.metadata.labels.partOf }}
spec:
selector:
matchLabels:
app: {{ .Values.metadata.name }}
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 2
maxUnavailable: 0
template:
metadata:
labels:
app: {{ .Values.metadata.name }}
part-of: {{ .Values.metadata.labels.partOf }}
spec:
tolerations:
{{- toYaml .Values.spec.tolerations | nindent 8 }}
affinity:
{{- toYaml .Values.spec.affinity | nindent 8 }}
containers:
- name: {{ .Values.metadata.name }}
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: {{ .Values.service.port }}

{{- if .Values.spec.containers.readinessProbe }}
readinessProbe:
{{ toYaml .Values.spec.containers.readinessProbe | indent 10 }}
{{- end }}
{{- if .Values.spec.containers.livenessProbe }}
livenessProbe:
{{ toYaml .Values.spec.containers.livenessProbe | indent 10 }}
{{- end }}
resources:
{{- toYaml .Values.spec.containers.resources | nindent 10 }}
securityContext:
{{- toYaml .Values.spec.containers.securityContext | nindent 10 }}
volumeMounts:
{{- toYaml .Values.spec.containers.volumeMounts | nindent 10 }}
env:
{{- toYaml .Values.spec.containers.env | nindent 10 }}

volumes:
{{- toYaml .Values.spec.containers.volumes | nindent 8 }}

25 changes: 25 additions & 0 deletions helm-chart/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{- $servicePort := .Values.service.port -}}
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: {{ .Values.metadata.name }}
namespace: {{ .Values.metadata.namespace }}
labels:
app: {{ .Values.metadata.name }}
part-of: {{ .Values.metadata.labels.partOf }}

{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}

spec:
{{- if .Values.ingress.tls }}
tls:
{{ toYaml .Values.ingress.tls | indent 4 }}
{{- end }}

{{- if .Values.ingress.rules }}
rules:
{{ toYaml .Values.ingress.rules | indent 4 }}
{{- end }}
17 changes: 17 additions & 0 deletions helm-chart/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
kind: Service
apiVersion: v1
metadata:
name: {{ .Values.metadata.name }}
namespace: {{ .Values.metadata.namespace }}
labels:
app: {{ .Values.metadata.name }}
part-of: {{ .Values.metadata.labels.partOf }}
spec:
type: {{ .Values.service.type }}
selector:
app: {{ .Values.metadata.name }}
ports:
- name: {{ .Values.metadata.name }}-http
port: 80
protocol: {{ .Values.service.protocol }}
targetPort: {{ .Values.service.port }}
111 changes: 111 additions & 0 deletions helm-chart/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
metadata:
name: sample-nodejs
namespace: TEMP_NAMESPACE
labels:
partOf: sample-nodejs

service:
type: NodePort
port: 3000
protocol: TCP

image:
repository: dendipradigta/sample-nodejs
tag: TMP_IMAGE_VERSION
# tag: latest
pullPolicy: Always

spec:
replicasCout: 1
restartPolicy: OnFailure

tolerations: []
# - key: pool
# value: preemptible

affinity: {}
# nodeAffinity:
# weight: 70
# key: cloud.google.com/gke-preemptible
# operator: In
# values:
# - "true"
# podAntiAffinity:
# weight: 50
# key: part-of
# operator: In
# values:
# - avalon
# topologyKey: "kubernetes.io/hostname"

containers: {}
# command: ["/app/sample-nodejs","update", "recipe_with_promo"]
# readinessProbe:
# httpGet:
# path: /ping
# port: 7723
# initialDelaySeconds: 10
# periodSeconds: 5
# timeoutSeconds: 5
# livenessProbe:
# httpGet:
# path: /ping
# port: 7723
# initialDelaySeconds: 10
# periodSeconds: 5
# timeoutSeconds: 5

# resources:
# limits:
# cpu: 100m
# memory: 200Mi
# requests:
# cpu: 50m
# memory: 100Mi

# securityContext:
# capabilities:
# drop:
# - all
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 10002

# volumeMounts:
# - name: configs
# mountPath: /sample-nodejs

# env:
# Uncomment this section to add container env variables
# - name: DB_HOST
# value: '10.11.0.32'
# - name: DB_password
# value: 'xxxxxxx'

# volumes:
# - name: configs
# configMap:
# name: vol-configs-sample-nodejs

configmap: {}

ingress:
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/configuration-snippet: |
proxy_set_header l5d-dst-override $service_name.$namespace.svc.cluster.local;

tls: []
# - secretName: star-kurio-me

rules:
- host: sample.dendi.com
http:
paths:
- path: /
backend:
serviceName: sample-nodejs
servicePort: 80