Skip to content

Commit 94c49c7

Browse files
authored
compose and K8s file cleanup (dockersamples#273)
1 parent f1d2767 commit 94c49c7

13 files changed

+139
-509
lines changed

ExampleVotingApp.sln

Lines changed: 0 additions & 37 deletions
This file was deleted.

README.md

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,43 @@
1-
Example Voting App
2-
=========
1+
# Example Voting App
32

43
A simple distributed application running across multiple Docker containers.
54

6-
Getting started
7-
---------------
5+
## Getting started
86

9-
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/).
7+
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/).
108

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

12-
## Linux Containers
11+
Run in this directory to build and run the app:
1312

14-
The Linux stack uses Python, Node.js, .NET Core, with Redis for messaging and Postgres for storage.
15-
16-
> 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.
17-
18-
Run in this directory:
19-
```
13+
```shell
2014
docker compose up
2115
```
22-
The app will be running at [http://localhost:5000](http://localhost:5000), and the results will be at [http://localhost:5001](http://localhost:5001).
16+
17+
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).
2318

2419
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:
25-
```
20+
21+
```shell
2622
docker swarm init
2723
```
24+
2825
Once you have your swarm, in this directory run:
29-
```
26+
27+
```shell
3028
docker stack deploy --compose-file docker-stack.yml vote
3129
```
3230

31+
## Run the app in Kubernetes
3332

34-
Run the app in Kubernetes
35-
-------------------------
36-
37-
The folder k8s-specifications contains the yaml specifications of the Voting App's services.
33+
The folder k8s-specifications contains the YAML specifications of the Voting App's services.
3834

39-
First create the vote namespace
40-
41-
```
42-
$ kubectl create namespace vote
43-
```
35+
Run the following command to create the deployments and services objects in the vote namespace:
4436

45-
Run the following command to create the deployments and services objects:
46-
```
47-
$ kubectl create -f k8s-specifications/
37+
```shell
38+
kubectl create -f k8s-specifications/
39+
vote "vote" created
40+
deployment "db" created
4841
deployment "db" created
4942
service "db" created
5043
deployment "redis" created
@@ -58,23 +51,20 @@ deployment "worker" created
5851

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

61-
Architecture
62-
-----
54+
## Architecture
6355

6456
![Architecture diagram](architecture.png)
6557

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

73-
Notes
74-
-----
64+
## Notes
7565

76-
The voting application only accepts one vote per client. It does not register votes if a vote has already been submitted from a client.
66+
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.
7767

78-
This isn't an example of a properly architected perfectly designed distributed app... it's just a simple
79-
example of the various types of pieces and languages you might see (queues, persistent data, etc), and how to
80-
deal with them in Docker at a basic level.
68+
This isn't an example of a properly architected perfectly designed distributed app... it's just a simple
69+
example of the various types of pieces and languages you might see (queues, persistent data, etc), and how to
70+
deal with them in Docker at a basic level.

docker-compose-k8s.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

docker-compose-simple.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

docker-compose.images.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# for running in docker compose with prebuilt images
2+
3+
# version is now using "compose spec"
4+
# v2 and v3 are now combined!
5+
# docker-compose v1.27+ required
6+
7+
services:
8+
vote:
9+
image: dockersamples/examplevotingapp_vote
10+
depends_on:
11+
redis:
12+
condition: service_healthy
13+
ports:
14+
- "5000:80"
15+
networks:
16+
- front-tier
17+
- back-tier
18+
19+
result:
20+
image: dockersamples/examplevotingapp_result
21+
depends_on:
22+
db:
23+
condition: service_healthy
24+
ports:
25+
- "5001:80"
26+
networks:
27+
- front-tier
28+
- back-tier
29+
30+
worker:
31+
image: dockersamples/examplevotingapp_worker
32+
depends_on:
33+
redis:
34+
condition: service_healthy
35+
db:
36+
condition: service_healthy
37+
networks:
38+
- back-tier
39+
40+
redis:
41+
image: redis:alpine
42+
volumes:
43+
- "./healthchecks:/healthchecks"
44+
healthcheck:
45+
test: /healthchecks/redis.sh
46+
interval: "5s"
47+
ports: ["6379"]
48+
networks:
49+
- back-tier
50+
51+
db:
52+
image: postgres:15-alpine
53+
environment:
54+
POSTGRES_USER: "postgres"
55+
POSTGRES_PASSWORD: "postgres"
56+
volumes:
57+
- "db-data:/var/lib/postgresql/data"
58+
- "./healthchecks:/healthchecks"
59+
healthcheck:
60+
test: /healthchecks/postgres.sh
61+
interval: "5s"
62+
networks:
63+
- back-tier
64+
65+
volumes:
66+
db-data:
67+
68+
networks:
69+
front-tier:
70+
back-tier:

docker-compose.seed.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

docker-compose.yml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ services:
99
command: python app.py
1010
depends_on:
1111
redis:
12-
condition: service_healthy
12+
condition: service_healthy
13+
healthcheck:
14+
test: ["CMD", "curl", "-f", "http://localhost"]
15+
interval: 15s
16+
timeout: 5s
17+
retries: 3
18+
start_period: 10s
1319
volumes:
1420
- ./vote:/app
1521
ports:
@@ -46,7 +52,7 @@ services:
4652
- back-tier
4753

4854
redis:
49-
image: redis:5.0-alpine3.10
55+
image: redis:alpine
5056
volumes:
5157
- "./healthchecks:/healthchecks"
5258
healthcheck:
@@ -57,7 +63,7 @@ services:
5763
- back-tier
5864

5965
db:
60-
image: postgres:9.4
66+
image: postgres:15-alpine
6167
environment:
6268
POSTGRES_USER: "postgres"
6369
POSTGRES_PASSWORD: "postgres"
@@ -70,6 +76,19 @@ services:
7076
networks:
7177
- back-tier
7278

79+
# this service runs once to seed the database with votes
80+
# it won't run unless you specify the "seed" profile
81+
# docker compose --profile seed up -d
82+
seed:
83+
build: ./seed-data
84+
profiles: ["seed"]
85+
depends_on:
86+
vote:
87+
condition: service_healthy
88+
networks:
89+
- front-tier
90+
restart: "no"
91+
7392
volumes:
7493
db-data:
7594

0 commit comments

Comments
 (0)