/example-voting-app

Primary LanguageJavaScriptApache License 2.0Apache-2.0

Example Voting App (GitOps + Helm Demo Env)

  • DEPRECATED - New templates coming soon.

PreReqs:

Only one example-voting-app demo per Kubernetes cluster. If you absolutely must share update the release names with your personal

  • Find and prepend your user/org info (shortname) to the following values in .codefresh/codefresh-cd.yml:

    • ${{CF_BRANCH_TAG_NORMALIZED}}-${{CF_PULL_REQUEST_NUMBER}}-${{CF_REPO_NAME}}
    • staging-example-voting-app
    • production-example-voting-app

    with unique prepended value like...

    • dustinvb-${{CF_BRANCH_TAG_NORMALIZED}}-${{CF_PULL_REQUEST_NUMBER}}-${{CF_REPO_NAME}}
    • dustinvb-staging-example-voting-app
    • dustinvb-production-example-voting-app

This pipeline will create Helm Releases in a few ways. Every PR gets a new release just create a branch and a PR back to your forker repository. Staging and Production both get a release and are long-lived environments. They are triggered by creating a new GitHub Release. After staging deploys successfully you will be prompted to Approve the release to Production.

*External LB Requirements:

6-10 External Ephemeral IPs required for normal usage from Cloud provider

2 External IPs Required per running example-voting-app release.

**Some popular Kubernetes options

If wanted, Allure is supported and step is there just setup Storage Integration and uncomment the step in cd.yml

Storage Integration

Now onto the How-to!

Either Fork or copy this repositories content to your Github Account or a GIT repository in another Version Control System.

Make sure you have complete pre-reqs

  1. Create example-voting-app project.
  2. Create example-voting-app pipeline.
  3. Unselect the option ADD GIT COMMIT TRIGGER.
  4. Click CREATE.
  5. Add the contents of codefresh.yml to Inline Editor.
  6. Save pipeline (DO NOT RUN)
  7. Make any modifications to Codefresh YAML files you need to make like the release names (explained above)
  8. Build example-voting-app pipeline selecting Advanced Options and specifying name of your GitHub Org GITHUB_ORG, Kubernetes cluster KUBERNETES_CLUSTER_NAME as shown in Codefresh and the Kubernetes namespace KUBERNETES_NAMESPACE to deploy example-voting-app releases to (this namespace is created automatically by pipeline and must not exist before hand). This is a one-time operation and not idempotent at this time.

Now you can play with the release or do something similar with your own application.

Development Workflow

To generate staging release simply add a new GitHub Release to your forked repository.

To generate production release approve that pipeline to continue on.

PRs generate PR release based on PR information.

ORIGINAL DOCUMENTATION FROM SOURCE REPOSITORY

Example Voting App

Getting started

Download Docker. If you are on Mac or Windows, Docker Compose will be automatically installed. On Linux, make sure you have the latest version of Compose. If you're using Docker for Windows on Windows 10 pro or later, you must also switch to Linux containers.

Run in this directory:

docker-compose up

The app will be running at http://localhost:5000, and the results will be at http://localhost:5001.

Alternately, if you want to run it on a Docker Swarm, first make sure you have a swarm. If you don't, run:

docker swarm init

Once you have your swarm, in this directory run:

docker stack deploy --compose-file docker-stack.yml vote

Run the app in Kubernetes

The folder k8s-specifications contains the yaml specifications of the Voting App's services.

Run the following command to create the deployments and services objects:

$ kubectl create -f k8s-specifications/
deployment "db" created
service "db" created
deployment "redis" created
service "redis" created
deployment "result" created
service "result" created
deployment "vote" created
service "vote" created
deployment "worker" created

The vote interface is then available on port 31000 on each host of the cluster, the result one is available on port 31001.

Architecture

Architecture diagram

  • A Python webapp which lets you vote between two options
  • A Redis queue which collects new votes
  • A .NET worker which consumes votes and stores them in…
  • A Postgres database backed by a Docker volume
  • A Node.js webapp which shows the results of the voting in real time

Note

The voting application only accepts one vote per client. It does not register votes if a vote has already been submitted from a client.