diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 1f553c19..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,33 +0,0 @@ -version: 2 -jobs: - build: - docker: - - image: cypress/base:8 - steps: - - checkout - - restore_cache: # special step to restore the dependency cache - key: dependency-cache-{{ checksum "package.json" }} - - run: - name: install-npm-wee - command: npm install - - save_cache: # special step to save the dependency cache - key: dependency-cache-{{ checksum "package.json" }} - paths: - - ./node_modules - - run: - name: clone-e2e-test - command: git clone https://github.com/contentful/the-example-app-e2e-tests.git ./test/e2e - - run: - name: install-e2e-test - command: cd ./test/e2e && npm install - - run: - name: test - command: npm run test - - store_artifacts: - path: /tmp/artifact-1 - - destination: artifact-file-cypress-result_`date +%Y-%m-%d_%H-%M-%S` - - - store_artifacts: - path: /tmp/artifacts - diff --git a/Dockerfile b/Dockerfile index ab2607fb..fa087e6e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM node:9 - +# test command WORKDIR /app RUN npm install -g contentful-cli diff --git a/README.md b/README.md index 3fb48f32..196e06b3 100644 --- a/README.md +++ b/README.md @@ -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. - -Screenshot of the example app - -You can see a hosted version of `The node.js example app` on Heroku. - -## 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 '' -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= -CONTENTFUL_DELIVERY_TOKEN= -CONTENTFUL_PREVIEW_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= \ - -e CONTENTFUL_DELIVERY_TOKEN= \ - -e CONTENTFUL_PREVIEW_TOKEN= \ - -d the-example-app.nodejs -``` +testtttt \ No newline at end of file diff --git a/helm-chart/Chart.yaml b/helm-chart/Chart.yaml new file mode 100644 index 00000000..9bf1d760 --- /dev/null +++ b/helm-chart/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +name: APP_NAME +version: TEMP_CHART_VERSION +appVersion: TEMP_APP_VERSION +description: sample-nodejs-app diff --git a/helm-chart/templates/configmap.yaml b/helm-chart/templates/configmap.yaml new file mode 100644 index 00000000..d46ca281 --- /dev/null +++ b/helm-chart/templates/configmap.yaml @@ -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 }} \ No newline at end of file diff --git a/helm-chart/templates/deployment.yaml b/helm-chart/templates/deployment.yaml new file mode 100644 index 00000000..4ab66d29 --- /dev/null +++ b/helm-chart/templates/deployment.yaml @@ -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 }} + \ No newline at end of file diff --git a/helm-chart/templates/ingress.yaml b/helm-chart/templates/ingress.yaml new file mode 100644 index 00000000..efa8d1d6 --- /dev/null +++ b/helm-chart/templates/ingress.yaml @@ -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 }} diff --git a/helm-chart/templates/service.yaml b/helm-chart/templates/service.yaml new file mode 100644 index 00000000..aa2e5f16 --- /dev/null +++ b/helm-chart/templates/service.yaml @@ -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 }} diff --git a/helm-chart/values.yaml b/helm-chart/values.yaml new file mode 100644 index 00000000..5087e94a --- /dev/null +++ b/helm-chart/values.yaml @@ -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 + + +