Skip to content

Commit

Permalink
compose and K8s file cleanup (dockersamples#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
BretFisher authored Dec 17, 2022
1 parent f0fb81f commit 226edf0
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 509 deletions.
37 changes: 0 additions & 37 deletions ExampleVotingApp.sln

This file was deleted.

72 changes: 31 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,43 @@
Example Voting App
=========
# Example Voting App

A simple distributed application running across multiple Docker containers.

Getting started
---------------
## Getting started

Download [Docker Desktop](https://www.docker.com/products/docker-desktop) for Mac or Windows. [Docker Compose](https://docs.docker.com/compose) will be automatically installed. On Linux, make sure you have the latest version of [Compose](https://docs.docker.com/compose/install/).
Download [Docker Desktop](https://www.docker.com/products/docker-desktop) for Mac or Windows. [Docker Compose](https://docs.docker.com/compose) will be automatically installed. On Linux, make sure you have the latest version of [Compose](https://docs.docker.com/compose/install/).

This solution uses Python, Node.js, .NET, with Redis for messaging and Postgres for storage.

## Linux Containers
Run in this directory to build and run the app:

The Linux stack uses Python, Node.js, .NET Core, with Redis for messaging and Postgres for storage.

> If you're using [Docker Desktop on Windows](https://store.docker.com/editions/community/docker-ce-desktop-windows), you can run the Linux version by [switching to Linux containers](https://docs.docker.com/docker-for-windows/#switch-between-windows-and-linux-containers), or run the Windows containers version.
Run in this directory:
```
```shell
docker compose up
```
The app will be running at [http://localhost:5000](http://localhost:5000), and the results will be at [http://localhost:5001](http://localhost:5001).

The `vote` app will be running at [http://localhost:5000](http://localhost:5000), and the `results` will be at [http://localhost:5001](http://localhost:5001).

Alternately, if you want to run it on a [Docker Swarm](https://docs.docker.com/engine/swarm/), first make sure you have a swarm. If you don't, run:
```

```shell
docker swarm init
```

Once you have your swarm, in this directory run:
```

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

## Run the app in Kubernetes

Run the app in Kubernetes
-------------------------

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

First create the vote namespace

```
$ kubectl create namespace vote
```
Run the following command to create the deployments and services objects in the vote namespace:

Run the following command to create the deployments and services objects:
```
$ kubectl create -f k8s-specifications/
```shell
kubectl create -f k8s-specifications/
vote "vote" created
deployment "db" created
deployment "db" created
service "db" created
deployment "redis" created
Expand All @@ -58,23 +51,20 @@ 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

![Architecture diagram](architecture.png)

* A front-end web app in [Python](/vote) or [ASP.NET Core](/vote/dotnet) which lets you vote between two options
* A [Redis](https://hub.docker.com/_/redis/) or [NATS](https://hub.docker.com/_/nats/) queue which collects new votes
* A [.NET Core](/worker/) worker which consumes votes and stores them in…
* A [Postgres](https://hub.docker.com/_/postgres/) or [TiDB](https://hub.docker.com/r/dockersamples/tidb/tags/) database backed by a Docker volume
* A [Node.js](/result) or [ASP.NET Core SignalR](/result/dotnet) webapp which shows the results of the voting in real time

* A front-end web app in [Python](/vote) which lets you vote between two options
* A [Redis](https://hub.docker.com/_/redis/) which collects new votes
* A [.NET](/worker/) worker which consumes votes and stores them in…
* A [Postgres](https://hub.docker.com/_/postgres/) database backed by a Docker volume
* A [Node.js](/result) web app which shows the results of the voting in real time

Notes
-----
## Notes

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

This isn't an example of a properly architected perfectly designed distributed app... it's just a simple
example of the various types of pieces and languages you might see (queues, persistent data, etc), and how to
deal with them in Docker at a basic level.
This isn't an example of a properly architected perfectly designed distributed app... it's just a simple
example of the various types of pieces and languages you might see (queues, persistent data, etc), and how to
deal with them in Docker at a basic level.
30 changes: 0 additions & 30 deletions docker-compose-k8s.yml

This file was deleted.

32 changes: 0 additions & 32 deletions docker-compose-simple.yml

This file was deleted.

70 changes: 70 additions & 0 deletions docker-compose.images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# for running in docker compose with prebuilt images

# version is now using "compose spec"
# v2 and v3 are now combined!
# docker-compose v1.27+ required

services:
vote:
image: dockersamples/examplevotingapp_vote
depends_on:
redis:
condition: service_healthy
ports:
- "5000:80"
networks:
- front-tier
- back-tier

result:
image: dockersamples/examplevotingapp_result
depends_on:
db:
condition: service_healthy
ports:
- "5001:80"
networks:
- front-tier
- back-tier

worker:
image: dockersamples/examplevotingapp_worker
depends_on:
redis:
condition: service_healthy
db:
condition: service_healthy
networks:
- back-tier

redis:
image: redis:alpine
volumes:
- "./healthchecks:/healthchecks"
healthcheck:
test: /healthchecks/redis.sh
interval: "5s"
ports: ["6379"]
networks:
- back-tier

db:
image: postgres:15-alpine
environment:
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "postgres"
volumes:
- "db-data:/var/lib/postgresql/data"
- "./healthchecks:/healthchecks"
healthcheck:
test: /healthchecks/postgres.sh
interval: "5s"
networks:
- back-tier

volumes:
db-data:

networks:
front-tier:
back-tier:
9 changes: 0 additions & 9 deletions docker-compose.seed.yml

This file was deleted.

25 changes: 22 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ services:
command: python app.py
depends_on:
redis:
condition: service_healthy
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost"]
interval: 15s
timeout: 5s
retries: 3
start_period: 10s
volumes:
- ./vote:/app
ports:
Expand Down Expand Up @@ -46,7 +52,7 @@ services:
- back-tier

redis:
image: redis:5.0-alpine3.10
image: redis:alpine
volumes:
- "./healthchecks:/healthchecks"
healthcheck:
Expand All @@ -57,7 +63,7 @@ services:
- back-tier

db:
image: postgres:9.4
image: postgres:15-alpine
environment:
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "postgres"
Expand All @@ -70,6 +76,19 @@ services:
networks:
- back-tier

# this service runs once to seed the database with votes
# it won't run unless you specify the "seed" profile
# docker compose --profile seed up -d
seed:
build: ./seed-data
profiles: ["seed"]
depends_on:
vote:
condition: service_healthy
networks:
- front-tier
restart: "no"

volumes:
db-data:

Expand Down
Loading

0 comments on commit 226edf0

Please sign in to comment.