Skip to content

Commit

Permalink
Bare flask + container skeleton
Browse files Browse the repository at this point in the history
Update the structure to match that of the other services.
  • Loading branch information
jpichon committed Dec 23, 2020
1 parent 16df542 commit 2bcbd2e
Show file tree
Hide file tree
Showing 29 changed files with 370 additions and 310 deletions.
53 changes: 46 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Byte-compiled / optimized / DLL files
*.pyc
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
Expand All @@ -15,15 +13,16 @@ dist/
downloads/
eggs/
.eggs/
./lib/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
.venv
Pipfile.lock
*~

# PyInstaller
Expand All @@ -44,21 +43,61 @@ htmlcov/
.cache
nosetests.xml
coverage.xml
*,cover
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# pyenv python configuration file
# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
.venv
venv/
ENV/
#Pipfile.lock

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
15 changes: 10 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
# This file will be regenerated if you run travis_pypi_setup.py

language: python
python:
- 3.6
- 3.8
matrix:
include:
- python: 3.8
- python: 3.9

# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install: pip install -U tox-travis
install:
- pip install pipenv
- pipenv install --dev

# command to run tests, e.g. python setup.py test
script: tox
script:
- pipenv run flake8 service
- pipenv run pytest service

# After you create the Github repo and add it to Travis, run the
# travis_pypi_setup.py script to finish PyPI deployment setup
Expand Down
28 changes: 15 additions & 13 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,26 @@ Ready to contribute? Here's how to set up `rtls` for local development.

3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development::

$ mkvirtualenv rtls
$ cd rtls/
$ python setup.py develop
First, go into the pipenv virtual environment::

$ pipenv update --dev
$ pipenv shell

Running the local development server::

(pkg_syncer)[]$ cd ./service
(pkg_syncer)[]$ python main.py

4. Create a branch for local development::

$ git checkout -b name-of-your-bugfix-or-feature

Now you can make your changes locally.

5. When you're done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox::
5. When you're done making changes, check that your changes pass flake8 and the tests::

$ flake8 rtls tests
$ python setup.py test or py.test
$ tox

To get flake8 and tox, just pip install them into your virtualenv.
(rtls)[]$ flake8 service
(rtls)[]$ pytest service

6. Commit your changes and push your branch to GitHub::

Expand All @@ -101,14 +104,13 @@ Before you submit a pull request, check that it meets these guidelines:
2. If the pull request adds functionality, the docs should be updated. Put
your new functionality into a function with a docstring, and add the
feature to the list in README.rst.
3. The pull request should work for Python 3.6 and 3.7. Check
3. The pull request should work for Python 3.8. Check
https://travis-ci.org/release-depot/rtls/pull_requests
and make sure that the tests pass for all supported Python versions.

Tips
----

To run a subset of tests::

To run a single test::

$ python -m unittest tests.test_rtls
(rtls)[]$ service/tests/test_rtls.py::test_rtls
15 changes: 15 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
ansible-bender = "*"
autopep8 = "*"
flake8 = "*"
pylint = "*"
pytest = "*"
selinux = "*"

[packages]
rtls = {editable = true, path = "./service"}
34 changes: 31 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,39 @@ RTLS, or Real Time Locator System, is an abstraction layer for tracking changes
* Free software: MIT license
* Documentation: https://rtls.readthedocs.io.

API
---

Features
--------
Test call - /rtls/[package]/[changeId] (GET)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Test call::

$ curl localhost:8080/rtls/mypackage/I123456
{"msg": "Test with mypackage"}

Development
-----------

See **CONTRIBUTING.rst**.

Container image creation
~~~~~~~~~~~~~~~~~~~~~~~~

Building the container image::

$ pipenv shell
$ ansible-bender build ./build.yml

Running the container image::

$ podman run -d --name rtls -p 8080:80 localhost/rtls:latest

Reading the container logs::

$ podman logs rtls
$ podman exec -it rtls cat /var/log/nginx/error.log | less

* TODO

Credits
-------
Expand Down
23 changes: 23 additions & 0 deletions build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
- name: rtls build
hosts: all
vars:
www_root: '/var/www/rtls/service'
ansible_bender:
base_image: 'registry.fedoraproject.org/fedora:latest'
cache_tasks: False
layering: False
target_image:
name: rtls
environment:
PIPENV_VENV_IN_PROJECT: 'True'
entrypoint: "{{ www_root }}/service_run.sh"
working_dir: "{{ www_root }}"
tasks:
- name: Setup the base
include_role:
name: base

- name: Setup the app
include_role:
name: app
12 changes: 0 additions & 12 deletions requirements_dev.txt

This file was deleted.

38 changes: 38 additions & 0 deletions roles/app/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---

- name: Setting up the app directory
file:
path: "{{ www_root }}"
state: directory

- name: Copy app code
copy:
src: "{{ playbook_dir }}/service"
dest: "{{ app_root }}"

- name: Copy python packaging files
copy:
src: "{{ item }}"
dest: "{{ app_root }}"
loop:
- "{{ playbook_dir }}/service/setup.py"
- "{{ playbook_dir }}/service/requirements.txt"

- name: Copy Pipenv files
copy:
src: "{{ item }}"
dest: "{{ www_root }}"
mode: preserve
loop:
- "{{ playbook_dir }}/Pipfile"

- name: Setup venv
shell:
cmd: "pipenv update"
chdir: "{{ app_root }}"

- name: Copy files
template:
src: templates/service_run.j2
dest: "{{ app_root }}/service_run.sh"
mode: 'o+x'
9 changes: 9 additions & 0 deletions roles/app/templates/service_run.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#! /bin/bash

source {{ www_root }}/.venv/bin/activate
cd {{ www_root }}
nginx
# Timeout value is in seconds
gunicorn wsgi:app \
--bind 127.0.0.1:8000 \
--timeout 300
3 changes: 3 additions & 0 deletions roles/app/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---

app_root: '{{ www_root }}'
4 changes: 4 additions & 0 deletions roles/base/files/proxy_params
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
9 changes: 9 additions & 0 deletions roles/base/files/rtls.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
server {
listen 80;
server_name server_domain_or_IP;

location / {
include proxy_params;
proxy_pass http://127.0.0.1:8000;
}
}
35 changes: 35 additions & 0 deletions roles/base/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---

- name: Install packages
dnf:
name:
- pipenv
- nginx
- python38
state: present
install_weak_deps: no

- name: Clean dnf metadata
shell: 'dnf clean all'
args:
warn: no

- name: Remove dnf cache
file:
path: /var/lib/dnf
state: absent

- name: Set up base directory for apps
file:
path: "{{ www_root }}"
state: directory

- name: Copy nginx config
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: nginx
group: nginx
loop:
- {'src': 'rtls.conf', 'dest': '/etc/nginx/conf.d'}
- {'src': 'proxy_params', 'dest': '/etc/nginx'}
7 changes: 0 additions & 7 deletions rtls/__init__.py

This file was deleted.

3 changes: 0 additions & 3 deletions rtls/rtls.py

This file was deleted.

Loading

0 comments on commit 2bcbd2e

Please sign in to comment.