diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..173258f --- /dev/null +++ b/.coveragerc @@ -0,0 +1,2 @@ +[run] +source = period \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..a6784bf --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,20 @@ +stages: + - build + - deploy + +buiild job: + stage: build + script: + - export PYTHONPATH=. + - export FLASK_APP=period + - apt-get udate -qy + - apt-get install -y python3-dev python3-pip + - pip3 install Flask gunicorn pytest pytest-cov + - pytest tests --cov --cov-report term --cov-report html + +deploy job: + stage: deploy + script: + - apt-get update -qy + - apt-get install curl -y + - curl period.ahosking.com/reload?password=BananaHammocks \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f45a18c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM debian:jessie-slim + +RUN apt-get update && apt-get install -y \ +git \ +python3 \ +python3-pip + +RUN pip3 install -r requirements.txt + +ENV LC_ALL C.UTF-8 +ENV LANG C.UTF-8 + +WORKDIR /app + +COPY . /app \ No newline at end of file diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..f9eec91 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,2 @@ +gunicorn --bind=0.0.0.0:9060 --daemon reload:app +gunicorn --bind 0.0.0.0:9061 --reload --chdir period app:app \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e0d51f8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: '2.3' +services: + flask-reload: + build: + context: . + dockerfile: Dockerfile + command: bash deploy.sh + environment: + PYTHONPATH: . + ports: + - '9060:9060' + - '9061:9061' \ No newline at end of file diff --git a/reload.py b/reload.py new file mode 100644 index 0000000..2234bd1 --- /dev/null +++ b/reload.py @@ -0,0 +1,15 @@ +import os +from flask import request, Flask + +app = Flask(__name__) + +@app.route('/reload') +def reload(): + if request.args.get('password') == 'BananaHammocks': + try: + os.system('git pull origin master') + return 'success' + except: + return 'fail' + else: + return 'wrong password' \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..2f1915c --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ +# for pytest \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..25d3dc6 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,16 @@ +import pytest +from period import create_app + +@pytest.fixture +def app(): + app = create_app({ + 'TESTING': True + }) + +@pytest.fixture +def client(app): + return app.test_client() + +@pytest.fixture +def runner(app): + return app.test_cli_runner() \ No newline at end of file