Skip to content

Commit 38826ff

Browse files
committed
Merge from the original repo
1 parent 5af7f66 commit 38826ff

File tree

106 files changed

+6456
-7243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+6456
-7243
lines changed

ExampleVotingApp.sln

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28010.2036
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vote", "vote\dotnet\Vote\Vote.csproj", "{9687EAF5-BFF3-4F8D-9C78-1B8EE12CE091}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Worker", "worker\dotnet\Worker\Worker.csproj", "{083764E8-4C34-43FB-A468-F80CE0ADE10A}"
9+
EndProject
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Result", "result\dotnet\Result\Result.csproj", "{9AD16D72-E3F5-4A76-814C-40EBD1EE7892}"
11+
EndProject
12+
Global
13+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
14+
Debug|Any CPU = Debug|Any CPU
15+
Release|Any CPU = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{9687EAF5-BFF3-4F8D-9C78-1B8EE12CE091}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{9687EAF5-BFF3-4F8D-9C78-1B8EE12CE091}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{9687EAF5-BFF3-4F8D-9C78-1B8EE12CE091}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{9687EAF5-BFF3-4F8D-9C78-1B8EE12CE091}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{083764E8-4C34-43FB-A468-F80CE0ADE10A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{083764E8-4C34-43FB-A468-F80CE0ADE10A}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{083764E8-4C34-43FB-A468-F80CE0ADE10A}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{083764E8-4C34-43FB-A468-F80CE0ADE10A}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{9AD16D72-E3F5-4A76-814C-40EBD1EE7892}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{9AD16D72-E3F5-4A76-814C-40EBD1EE7892}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{9AD16D72-E3F5-4A76-814C-40EBD1EE7892}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{9AD16D72-E3F5-4A76-814C-40EBD1EE7892}.Release|Any CPU.Build.0 = Release|Any CPU
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
GlobalSection(ExtensibilityGlobals) = postSolution
35+
SolutionGuid = {9DEFC158-1225-4393-8A38-22256211D43D}
36+
EndGlobalSection
37+
EndGlobal

MAINTAINERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Bret Fisher <[email protected]>
2+
Michael Irwin <[email protected]>
3+
4+
# Alumni, thanks for your work!
15
Aanand Prasad <[email protected]>
26
Ben Firshman <[email protected]>
37
Fernando Mayo <[email protected]>

README.md

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
Example Voting App
22
=========
33

4+
A simple distributed application running across multiple Docker containers.
5+
46
Getting started
57
---------------
68

7-
Download [Docker](https://www.docker.com/products/overview). If you are on 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/).
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/).
10+
11+
12+
## Linux Containers
13+
14+
The Linux stack uses Python, Node.js, .NET Core (or optionally Java), 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.
817
918
Run in this directory:
1019
```
@@ -21,19 +30,71 @@ Once you have your swarm, in this directory run:
2130
docker stack deploy --compose-file docker-stack.yml vote
2231
```
2332

33+
## Windows Containers
34+
35+
An alternative version of the app uses Windows containers based on Nano Server. This stack runs on .NET Core, using [NATS](https://nats.io) for messaging and [TiDB](https://github.com/pingcap/tidb) for storage.
36+
37+
You can build from source using:
38+
39+
```
40+
docker-compose -f docker-compose-windows.yml build
41+
```
42+
43+
Then run the app using:
44+
45+
```
46+
docker-compose -f docker-compose-windows.yml up -d
47+
```
48+
49+
> Or in a Windows swarm, run `docker stack deploy -c docker-stack-windows.yml vote`
50+
51+
The app will be running at [http://localhost:5000](http://localhost:5000), and the results will be at [http://localhost:5001](http://localhost:5001).
52+
53+
54+
Run the app in Kubernetes
55+
-------------------------
56+
57+
The folder k8s-specifications contains the yaml specifications of the Voting App's services.
58+
59+
First create the vote namespace
60+
61+
```
62+
$ kubectl create namespace vote
63+
```
64+
65+
Run the following command to create the deployments and services objects:
66+
```
67+
$ kubectl create -f k8s-specifications/
68+
deployment "db" created
69+
service "db" created
70+
deployment "redis" created
71+
service "redis" created
72+
deployment "result" created
73+
service "result" created
74+
deployment "vote" created
75+
service "vote" created
76+
deployment "worker" created
77+
```
78+
79+
The vote interface is then available on port 31000 on each host of the cluster, the result one is available on port 31001.
80+
2481
Architecture
2582
-----
2683

2784
![Architecture diagram](architecture.png)
2885

29-
* A Python webapp which lets you vote between two options
30-
* A Redis queue which collects new votes
31-
* A .NET worker which consumes votes and stores them in…
32-
* A Postgres database backed by a Docker volume
33-
* A Node.js webapp which shows the results of the voting in real time
86+
* A front-end web app in [Python](/vote) or [ASP.NET Core](/vote/dotnet) which lets you vote between two options
87+
* A [Redis](https://hub.docker.com/_/redis/) or [NATS](https://hub.docker.com/_/nats/) queue which collects new votes
88+
* A [.NET Core](/worker/src/Worker), [Java](/worker/src/main) or [.NET Core 2.1](/worker/dotnet) worker which consumes votes and stores them in…
89+
* A [Postgres](https://hub.docker.com/_/postgres/) or [TiDB](https://hub.docker.com/r/dockersamples/tidb/tags/) database backed by a Docker volume
90+
* A [Node.js](/result) or [ASP.NET Core SignalR](/result/dotnet) webapp which shows the results of the voting in real time
91+
3492

93+
Notes
94+
-----
3595

36-
Note
37-
----
96+
The voting application only accepts one vote per client. It does not register votes if a vote has already been submitted from a client.
3897

39-
The voting application only accepts one vote per client. It does not register votes if a vote has already been submitted from a client.
98+
This isn't an example of a properly architected perfectly designed distributed app... it's just a simple
99+
example of the various types of pieces and languages you might see (queues, persistent data, etc), and how to
100+
deal with them in Docker at a basic level.

docker-compose-javaworker.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ services:
1414

1515
result:
1616
build: ./result
17-
command: nodemon --debug server.js
17+
command: nodemon server.js
1818
volumes:
1919
- ./result:/app
2020
ports:
@@ -41,6 +41,9 @@ services:
4141
db:
4242
image: postgres:9.4
4343
container_name: db
44+
environment:
45+
POSTGRES_USER: "postgres"
46+
POSTGRES_PASSWORD: "postgres"
4447
volumes:
4548
- "db-data:/var/lib/postgresql/data"
4649
networks:

docker-compose-k8s.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: '3'
2+
3+
services:
4+
redis:
5+
image: redis:alpine
6+
ports:
7+
- "6379:6379"
8+
db:
9+
image: postgres:9.4
10+
environment:
11+
POSTGRES_USER: "postgres"
12+
POSTGRES_PASSWORD: "postgres"
13+
ports:
14+
- "5432:5432"
15+
vote:
16+
image: dockersamples/examplevotingapp_vote:before
17+
ports:
18+
- "5000:80"
19+
deploy:
20+
replicas: 1
21+
result:
22+
image: dockersamples/examplevotingapp_result:before
23+
ports:
24+
- "5001:80"
25+
worker:
26+
image: dockersamples/examplevotingapp_worker
27+
visualizer:
28+
image: dockersamples/visualizer:stable
29+
ports:
30+
- "8080:8080"

docker-compose-windows-1809.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
version: "3.2"
2+
3+
services:
4+
vote:
5+
image: dockersamples/examplevotingapp_vote:dotnet-nanoserver-1809
6+
build:
7+
context: ./vote/dotnet
8+
dockerfile: Dockerfile.1809
9+
ports:
10+
- "5000:80"
11+
depends_on:
12+
- message-queue
13+
14+
result:
15+
image: dockersamples/examplevotingapp_result:dotnet-nanoserver-1809
16+
build:
17+
context: ./result/dotnet
18+
dockerfile: Dockerfile.1809
19+
ports:
20+
- "5001:80"
21+
environment:
22+
- "ConnectionStrings:ResultData=Server=db;Port=4000;Database=votes;User=root;SslMode=None"
23+
depends_on:
24+
- db
25+
26+
worker:
27+
image: dockersamples/examplevotingapp_worker:dotnet-nanoserver-1809
28+
build:
29+
context: ./worker/dotnet
30+
dockerfile: Dockerfile.1809
31+
environment:
32+
- "ConnectionStrings:VoteData=Server=db;Port=4000;Database=votes;User=root;SslMode=None"
33+
depends_on:
34+
- message-queue
35+
- db
36+
37+
message-queue:
38+
image: nats:2.0.4
39+
40+
db:
41+
image: dockersamples/tidb:nanoserver-1809
42+
ports:
43+
- "3306:4000"
44+
45+
networks:
46+
default:
47+
external:
48+
name: nat

docker-compose-windows.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
version: "3.2"
2+
3+
services:
4+
vote:
5+
image: dockersamples/examplevotingapp_vote:dotnet-nanoserver-sac2016
6+
build:
7+
context: ./vote/dotnet
8+
ports:
9+
- "5000:80"
10+
depends_on:
11+
- message-queue
12+
13+
result:
14+
image: dockersamples/examplevotingapp_result:dotnet-nanoserver-sac2016
15+
build:
16+
context: ./result/dotnet
17+
ports:
18+
- "5001:80"
19+
environment:
20+
- "ConnectionStrings:ResultData=Server=db;Port=4000;Database=votes;User=root;SslMode=None"
21+
depends_on:
22+
- db
23+
24+
worker:
25+
image: dockersamples/examplevotingapp_worker:dotnet-nanoserver-sac2016
26+
build:
27+
context: ./worker/dotnet
28+
environment:
29+
- "ConnectionStrings:VoteData=Server=db;Port=4000;Database=votes;User=root;SslMode=None"
30+
depends_on:
31+
- message-queue
32+
- db
33+
34+
message-queue:
35+
image: nats:nanoserver
36+
37+
db:
38+
image: dockersamples/tidb:nanoserver
39+
ports:
40+
- "3306:4000"
41+
42+
networks:
43+
default:
44+
external:
45+
name: nat

docker-compose.seed.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
seed:
3+
build: ./seed-data
4+
networks:
5+
- front-tier
6+
restart: "no"
7+
8+
networks:
9+
front-tier:

docker-compose.yml

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,25 @@ services:
88
- ./vote:/app
99
ports:
1010
- "5000:80"
11-
networks:
12-
- front-tier
13-
- back-tier
14-
15-
result:
16-
build: ./result
17-
command: nodemon --debug server.js
18-
volumes:
19-
- ./result:/app
20-
ports:
21-
- "5001:80"
22-
- "5858:5858"
23-
networks:
24-
- front-tier
25-
- back-tier
26-
27-
worker:
28-
build:
29-
context: ./worker
30-
networks:
31-
- back-tier
3211

3312
redis:
3413
image: redis:alpine
35-
container_name: redis
3614
ports: ["6379"]
37-
networks:
38-
- back-tier
15+
16+
worker:
17+
build: ./worker
3918

4019
db:
4120
image: postgres:9.4
42-
container_name: db
4321
environment:
44-
- POSTGRES_USER=postgres
45-
- POSTGRES_PASSWORD=postgres
46-
- POSTGRES_HOST_AUTH_METHOD= trust
47-
volumes:
48-
- "db-data:/var/lib/postgresql/data"
49-
networks:
50-
- back-tier
51-
52-
volumes:
53-
db-data:
22+
POSTGRES_USER: "postgres"
23+
POSTGRES_PASSWORD: "postgres"
5424

55-
networks:
56-
front-tier:
57-
back-tier:
25+
result:
26+
build: ./result
27+
command: nodemon server.js
28+
volumes:
29+
- ./result:/app
30+
ports:
31+
- "5001:80"
32+
- "5858:5858"

0 commit comments

Comments
 (0)