Package: cectf-server
# cectf-server[![Build Status](https://travis-ci.com/cectf/cectf-server.svg?branch=master)](https://travis-ci.com/cectf/cectf-server)The backend server code for the CECTF project.This project was built using [Python 3](https://www.python.org/) and [Flask](https://www.fullstackpython.com/flask.html), a relatively lightweight Python web server. A number of Flask plugins are also used, like [Flask-Security](https://pythonhosted.org/Flask-Security/), [Flask-CORS](https://flask-cors.readthedocs.io/en/latest/), and [Flask-SQLAlchemy](https://flask-sqlalchemy.palletsprojects.com/en/2.x/) (and of course [SQLAlchemy](https://www.sqlalchemy.org/)). [MariaDB](https://mariadb.org/) (an open source MySQL implementation) is used as the database.cectf-server currently handles all API requests from the [cectf-fronted](https://github.com/cectf/cectf-frontend) client, including user authentication, administrative actions from the UI dashboard, and of course the actual CTF.## InstallationNavigate to the project repository and run./setup_workspace.sh. This will set up the python virtual environment and install the python dependencies.You will need to install MariaDB (https://mariadb.com/downloads/#aptyum) and have it running on localhost. For testing purposes, the usertraviswith no password needs to be created (CREATE USER ‘travis’@’localhost’ IDENTIFIED BY ‘’;).Rundb_setup.shto set up thetestdatabase. This will create all the necessary tables and insert some dummy data.## CLIThere are a handful of administration tools available in the Flask CLI. To access it, run these commands to activate the virtual environment, then set up the environment variables required to target the correct Flask application:` source venv/bin/activate export FLASK_APP=cectf_server export FLASK_ENV=development `Runflask –helpfor a list of available Flask commands.## Development DeploymentAfter setting up the Flask CLI as described above, you can runflask runto launch the development server. It is configured to run onhttp://127.0.0.1:5001by default. This can be useful to inspect the API manually, but I found it difficult to use this development server with the [cectf-fronted](https://github.com/cectf/cectf-frontend) client.I recommend setting up nginx to host both cectf-server and [cectf-fronted](https://github.com/cectf/cectf-frontend) simultaneously. cectf-server can be deployed using uWSGI, a gateway protocol that allows web servers to communicate with generic web applications.Runrun.shto launch the Flask server as a uWSGI application. The configuration for this deployment can be found indev_deploy/uwsgi.ini. It is currently configured to connect to the socket filedev_deploy/cectf_server.sock.You will need to install nginx on your machine, then fill out thedev_deploy/nginx.conffile and add it to your nginx installation.## ConfigurationConfiguration can be done by adding variables toinstance/config.py. Here is a sample configuration file:` SECRET_KEY = 'dev' SECURITY_PASSWORD_SALT = 'salty' SQLALCHEMY_DATABASE_URI ='mysql+pymysql://travis@localhost/dev'CECTF_PRODUCTION = False `## TestingThere are some additional dependencies required for testing. Enter the virtual environment, then runpip install pytest coverageto install them.You will need to runpip install -e .to install the project in the local virtual environment (the-eensures that it is updated as the project is modified). This allowspytestto import the project. This step only needs to be performed once.Runpytestto run all tests, orpytest tests/test_file.pyto run a specific test file.To generate a code coverage report, runcoverage run -m pytestorcoverage run -m pytest tests/test_file.py.coveragewill usepytestto run all the tests, then store the coverage data in a.coveragefile. Runcoverage reportto get the report in the command line, or runcoverage htmlto generate an interactive HTML page inhtmlcov/index.html.## ReleasingThis project is managed by [Travis CI](https://travis-ci.com/cectf/cectf-server). Any commits to any branch (specificallydev) are tested automatically.To cut a release of the project:Ensure thedevbranch is up to date and has been pushed and tested by [Travis CI](https://travis-ci.com/cectf/cectf-server).Mergedevintomaster.Opensetup.py, find the line that saysversion=’a.b.c’,, and increment it to the next minor (or major) version number.Commit your change.Rungit tag -a <a.b.c> -m “A quick summary of what is new in this release”, where<a.b.c>is your new version number, and the commit message is meaningful.Rungit push origin master –tagto push your changes to master as well as your new tag.Ensure that the [Travis CI](https://travis-ci.com/cectf/cectf-server) completes successfully.Check that a new release was uploaded to [PyPI](https://pypi.org/project/cectf-server/).My [production deployment](https://ctf.chiquito.us) uses the latest tag on [PyPI](https://pypi.org/project/cectf-server/) to build a docker image which is then deployed on a cluster of Raspberry Pis.