Add Gitlab CI and tests

This commit is contained in:
Alexander Hosking 2022-04-14 22:47:27 -04:00
parent 68bd36e7e8
commit 1866aedd9e
8 changed files with 83 additions and 0 deletions

2
.coveragerc Normal file
View File

@ -0,0 +1,2 @@
[run]
source = period

20
.gitlab-ci.yml Normal file
View File

@ -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

15
Dockerfile Normal file
View File

@ -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

2
deploy.sh Normal file
View File

@ -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

12
docker-compose.yml Normal file
View File

@ -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'

15
reload.py Normal file
View File

@ -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'

1
tests/__init__.py Normal file
View File

@ -0,0 +1 @@
# for pytest

16
tests/conftest.py Normal file
View File

@ -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()