Skip to content

Commit a33c638

Browse files
committed
adding data seeding
Just run "docker-compose -f docker-compose.seed.yml up" to seed (you need to "docker-compose up -d" first)
1 parent d1920ed commit a33c638

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

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:

seed-data/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM python:3.9-slim
2+
3+
# add apache bench (ab) tool
4+
RUN apt-get update \
5+
&& apt-get install -y --no-install-recommends \
6+
apache2-utils \
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
WORKDIR /seed
10+
11+
COPY . .
12+
13+
# create POST data files with ab friendly formats
14+
RUN python make-data.py
15+
16+
CMD /seed/generate-votes.sh

seed-data/generate-votes.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
# create 3000 votes (2000 for option a, 1000 for option b)
4+
ab -n 1000 -c 50 -p posta -T "application/x-www-form-urlencoded" http://vote/
5+
ab -n 1000 -c 50 -p postb -T "application/x-www-form-urlencoded" http://vote/
6+
ab -n 1000 -c 50 -p posta -T "application/x-www-form-urlencoded" http://vote/

seed-data/make-data.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# this creates urlencode-friendly files without EOL
2+
import urllib.parse
3+
4+
outfile = open('postb', 'w')
5+
params = ({ 'vote': 'b' })
6+
encoded = urllib.parse.urlencode(params)
7+
outfile.write(encoded)
8+
outfile.close()
9+
outfile = open('posta', 'w')
10+
params = ({ 'vote': 'a' })
11+
encoded = urllib.parse.urlencode(params)
12+
outfile.write(encoded)
13+
outfile.close()

0 commit comments

Comments
 (0)