Skip to content

Commit c8349a4

Browse files
committed
add circle seeting for testing and CI pipeline
1 parent 8848382 commit c8349a4

File tree

8 files changed

+105
-6
lines changed

8 files changed

+105
-6
lines changed

Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
FROM debian:jessie
2-
RUN apt-get update && apt-get install -y \
3-
git \
4-
vim
5-
COPY abc.txt /src/abc.txt
6-
CMD ["echo", "hello world"]
1+
FROM python:3.5
2+
RUN pip install Flask==0.11.1 redis==2.10.5
3+
RUN useradd -ms /bin/bash admin
4+
USER admin
5+
WORKDIR /app
6+
CMD ["python", "app.py"]

Dockerfile-example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM debian:jessie
2+
RUN apt-get update && apt-get install -y \
3+
git \
4+
vim
5+
COPY abc.txt /src/abc.txt
6+
CMD ["echo", "hello world"]

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,9 @@ Write and Run Unit Tests inside Containers
161161
> cd dockerapp0.5
162162
> docker-compose up -d
163163
> docker-compose run dockerapp python test.py
164+
```
165+
Introduction to Continuous Integration(Github and CircleCI)
166+
```
167+
> ssh-keygen -t rsa -b 4096 -C "your_email@example.com" (genrate ssh key)
168+
> cat ~/.ssh/id_rsa.pub
164169
```

app/app.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from flask import Flask, request, render_template
2+
import redis
3+
4+
app = Flask(__name__)
5+
default_key = '1'
6+
cache = redis.StrictRedis(host='redis', port=6379, db=0)
7+
cache.set(default_key, "one")
8+
9+
@app.route('/', methods=['GET', 'POST'])
10+
def mainpage():
11+
12+
key = default_key
13+
if 'key' in request.form:
14+
key = request.form['key']
15+
16+
if request.method == 'POST' and request.form['submit'] == 'save':
17+
cache.set(key, request.form['cache_value'])
18+
19+
cache_value = None;
20+
if cache.get(key):
21+
cache_value = cache.get(key).decode('utf-8')
22+
23+
return render_template('index.html', key=key, cache_value=cache_value)
24+
25+
if __name__ == '__main__':
26+
app.run(host='0.0.0.0')

app/templates/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<html>
2+
<head>
3+
<title>key value lookup service</title>
4+
</head>
5+
<body>
6+
<form method="POST">
7+
<input type="text" name="key" value={{ key }}>
8+
<input type="text" name="cache_value" value={{ cache_value }}>
9+
<input type="submit" name="submit" value="load">
10+
<input type="submit" name="submit" value="save">
11+
</form>
12+
</body>
13+
</html>

app/test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import unittest
2+
import app
3+
4+
class TestDockerapp(unittest.TestCase):
5+
6+
def setUp(self):
7+
self.app = app.app.test_client()
8+
9+
def test_save_value(self):
10+
response = self.app.post('/', data=dict(submit='save', key='2', cache_value='two'))
11+
assert response.status_code == 200
12+
assert b'2' in response.data
13+
assert b'two' in response.data
14+
15+
def test_load_value(self):
16+
self.app.post('/', data=dict(submit='save', key='2', cache_value='two'))
17+
response = self.app.post('/', data=dict(submit='load', key='2'))
18+
assert response.status_code == 200
19+
assert b'2' in response.data
20+
assert b'two' in response.data
21+
22+
if __name__=='__main__':
23+
unittest.main()

circle.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
machine:
2+
pre:
3+
- curl -sSL https://s3.amazonaws.com/circle-downloads/install-circleci-docker.sh | bash -s -- 1.13.0
4+
services:
5+
- docker
6+
7+
dependencies:
8+
pre:
9+
- sudo pip install docker-compose==1.13.0
10+
11+
test:
12+
override:
13+
- docker-compose up -d
14+
- docker-compose run dockerapp python test.py

docker-compose.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: "3.0"
2+
services:
3+
dockerapp:
4+
build: .
5+
ports:
6+
- "5000:5000"
7+
volumes:
8+
- ./app:/app
9+
depends_on:
10+
- redis
11+
redis:
12+
image: redis:3.2.0

0 commit comments

Comments
 (0)