Skip to content

Commit

Permalink
Add a docker image for dev and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
calixteman committed Jan 11, 2019
1 parent b877395 commit 4a1371f
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 9 deletions.
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM alpine

RUN apk update
RUN apk add openssl
RUN openssl req \
-newkey rsa:4096 -nodes -sha256 -keyout server.key \
-x509 -days 365 -out server.crt \
-subj "/C=FR/ST=Paris/L=Paris/O=Crash-Stop/OU=Crash/CN=crash-stop.org"

FROM python:slim

ENV DATABASE_URL=postgresql://crash:stop@postgres:5432/crashstop
ENV MEMCACHEDCLOUD_SERVERS=memcached:11211
ENV MEMCACHEDCLOUD_USERNAME=
ENV MEMCACHEDCLOUD_PASSWORD=
ENV PORT=8080
ENV PYTHONPATH=.
ENV PYTHONUNBUFFERED=1

WORKDIR /tmp

ADD requirements.txt /tmp/requirements.txt
ADD test-requirements.txt /tmp/test-requirements.txt

RUN pip install -r requirements.txt
RUN pip install -r test-requirements.txt

WORKDIR /

COPY --from=0 server.* /
ADD Procfile .
RUN sed -i 's/gunicorn/gunicorn --reload --reload-extra-file static --reload-extra-file templates --certfile=\/server.crt --keyfile=\/server.key/g' Procfile

WORKDIR /code

EXPOSE 8080
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,17 @@ You can find more explanations here: https://crash-stop-addon.herokuapp.com/.

## Setup

Install the prerequisites via `pip`:
Install docker and docker-compose and then:
```sh
sudo pip install -r requirements.txt
docker-compose up --build
```
Then you can test in your browser: https://localhost:8080/sumup.html?s=OOM%20|%20small.

## Running tests

Install test prerequisites via `pip`:
In using docker:
```sh
sudo pip install -r test-requirements.txt
```

Run tests:
```sh
pytest -vv tests/
docker-compose -f docker-compose-test.yml run tests
```

## Bugs
Expand Down
15 changes: 15 additions & 0 deletions bin/init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

from crashstop import models, signatures


while True:
try:
models.create()
break
except: # NOQA
pass

signatures.update()
27 changes: 27 additions & 0 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "3"
services:
tests:
build: .
volumes:
- .:/code
command: >
bash -c "python bin/init.py &&
PYTHONDONTWRITEBYTECODE=1 pytest -p no:cacheprovider -vv tests/"
depends_on:
- postgres
- memcached
links:
- postgres
- memcached
postgres:
image: postgres
environment:
- POSTGRES_USER=crash
- POSTGRES_PASSWORD=stop
- POSTGRES_DB=crashstop
expose:
- 5432
memcached:
image: memcached
expose:
- 11211
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: "3"
services:
web:
build: .
ports:
- "8080:8080"
volumes:
- .:/code
command: >
bash -c "python bin/init.py &&
honcho -d . -f /Procfile start"
depends_on:
- postgres
- memcached
links:
- postgres
- memcached
postgres:
image: postgres
environment:
- POSTGRES_USER=crash
- POSTGRES_PASSWORD=stop
- POSTGRES_DB=crashstop
expose:
- 5432
memcached:
image: memcached
expose:
- 11211
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ jinja2>=2.10
flask>=1.0.2
flask_sqlalchemy>=2.3.2
sqlalchemy>=1.2.12
honcho>=1.0.1
gunicorn>=19.9.0
psycopg2-binary>=2.7.5
apscheduler>=3.5.3
Expand Down

0 comments on commit 4a1371f

Please sign in to comment.