SecFit (Secure Fitness) is a hybrid mobile application for fitness logging.

Related tags

Logging TDT4237-g18
Overview

SecFit

SecFit (Secure Fitness) is a hybrid mobile application for fitness logging.

Deploy with Docker

Prerequisites:

Docker

Git

Windows hosts must use Education or more advanced versions to run Docker
Download: https://innsida.ntnu.no/wiki/-/wiki/English/Microsoft+Windows+10

Install:

$ git clone https://gitlab.stud.idi.ntnu.no/kyleo/secfit.git
$ cd secfit/

Run:

$ docker-compose up --build
Hosts the application on http://localhost:9090 with default settings

Technology

  • deployment Docker
  • web Nginx
  • database Postgre SQL
  • backend Django 3 with Django REST framework
  • application
    • browser - HTML5/CSS/JS, Bootstrap v5 (no jQuery dependency)
    • mobile Apache Cordova (uses same website)
  • authentication JWT

Code and structure

.gitlab-ci.yml - gitlab ci requirements.txt - Python requirements package.json - Some node.js requirements, this is needed for cordova

  • secfit/ django project folder containing the project modules
    • / - generic structure of a django application
      • admins.py - file contaning definitions to connect models to the django admin panel
      • urls.py - contains mapping between urls and views
      • models.py - contains data models
      • permissions.py - contains custom permissions that govern access
      • serializers.py - contains serializer definitions for sending data between backend and frontend
      • parsers.py - contains custom parsers for parsing the body of HTTP requests
      • tests/ - contains tests for the module. View Testing in Django for more.
      • views.py - Controller in MVC. Methods for rendering and accepting user data
      • forms.py - definitions of forms. Used to render html forms and verify user input
      • settings.py - Contains important settings at the application and/or project level
      • Procfile - Procfile for backend heroku deployment
    • media/ - directory for file uploads (need to commit it for heroku)
    • comments/ - application handling user comments and reactions
    • secfit/ - The projects main module containing project-level settings.
    • users/ - application handling users and requests
    • workouts/ - application handling exercises and workouts
    • manage.py - entry point for running the project.
    • seed.json - contains seed data for the project to get it up and running quickly (coming soon)

Local setup

It's recommended to have a look at: https://www.djangoproject.com/start/ Just as important is the Django REST guide: https://www.django-rest-framework.org/

Create a virtualenv https://docs.python-guide.org/dev/virtualenvs/

Django

Installation with examples for Ubuntu. Windows and OSX is mostly the same

Fork the project and clone it to your machine.

Setup and activation of virtualenv (env that prevents python packages from being installed globaly on the machine)

Naviagate into the project folder, and create your own virtual environment

Install python requirements

pip install -r requirements.txt

Migrate database

python manage.py migrate

Create superuser

Create a local admin user by entering the following command:

python manage.py createsuperuser

Only username and password is required

Start the app

python manage.py runserver

Add initial data

You can add initial data either by going to the url the app is running on locally and adding /admin to the url.

Add some categories and you should be all set.

Or by entering

python manage.py loaddata seed.json

Cordova

Cordova CLI guide: https://cordova.apache.org/docs/en/latest/guide/cli/ If you want to run this as a mobile application

  • Navigate to the frontend directory
  • For android, do cordova run android
  • For ios, do cordova run ios
  • For browser, do cordova run browser

It's possible you will need to add the platforms you want to run and build. The following documentation can be used to run the application in an Android emulator:
https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html

Continuous integration

WARNING: Do not perform penetration testing on Heroku applications

Continuous integration will build the code pushed to master and push it to your heroku app so you get a live version of your latest code by just pushing your code to GitLab.

  1. Fork the project at GitLab
  2. Create a heroku account and an app for both the frontend and the backend.
  3. Select buildpacks for the two apps. The backend uses Python while the frontend uses node.js.
    • Settings > Buildpacks > Add buildpack
  4. Set the project in the .gitlab-cs.yml file by replacing with the name of the Heroku app you created - dpl --provider=heroku --app= --api-key=$HEROKU_STAGING_API_KEY
  5. Set varibles at GitLab
    • settings > ci > Environment Variables
    • HEROKU_STAGING_API_KEY = heroku > Account Settings > API Key
  6. Add heroku database for the backend
    • Resources > Add ons > search for postgres > add first option
  7. Set variables for the backend on Heroku. Settings > Config vars > Reveal vars
    • DATABASE_URL = Should be set by default. If not here is where you can find it: Resources > postgress > settings > view credentials > URI
    • IS_HEROKU = IS_HEROKU
    • PROCFILE = backend/secfit/Procfile
  8. Set variables for the frontend on heroku. Settings > Config vars > Reveal vars. Insert the URL for your backend app.
    • BACKEND_HOST = http:// .herokuapp.com
    • PROCFILE = frontend/Procfile
  9. Push the repository to both of the heroku applications https://devcenter.heroku.com/articles/git
    • git push git push HEAD:master
    • git push git push HEAD:master
  10. On GitLab go to CI / CD in the repository menu and select Run Pipeline if it has not already started. When both stages complete the app should be available on heroku. Staging will fail from timeout as Heroku does not give the propper response to end the job. But the log should state that the app was deployed.
  11. Setup the applications database.
  • Install heroku CLI by following: https://devcenter.heroku.com/articles/heroku-cli
  • Log in to the Heroku CLI by entering heroku login. This opens a webbrowser and you accept the login request.
  • Migrate database by entering heroku run python backend/secfit/manage.py migrate -a . Heroku run will run the folowing command on your heroku instance. Remember to replace with your app name
  • and create an admin account by running heroku run python backend/secfit/manage.py createsuperuser -a .
  • seed database heroku run python backend/secfit/manage.py loaddata seed.json -a
  1. On the frontend app, add a config variable for BACKEND_HOST = BACKEND_HOST

You will also need the heroku multi-procfile buildpack: https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-multi-procfile. In general, for this application to work (beyond locally), you will need to set the BACKEND_HOST to the URL of the REST API backend.

Reset Database

heroku pg:reset DATABASE_URL -a

You might also like...
TraceLog is a highly configurable, flexible, portable, and simple to use debug logging system for Swift and Objective-C applications running on Linux, macOS, iOS, watchOS, and tvOS.

Please star this github repository to stay up to date. TraceLog Introduction TraceLog is a highly configurable, flexible, portable, and simple to use

A flexible logging library written in Swift

Puppy Puppy is a flexible logging library written in Swift 🐶 It supports multiple transports(console, file, syslog, and oslog) as loggers. It not onl

In-App iOS Debugging Tool With Enhanced Logging, Networking Info, Crash reporting And More.
In-App iOS Debugging Tool With Enhanced Logging, Networking Info, Crash reporting And More.

The debugger tool for iOS developer. Display logs, network request, device informations, crash logs while using the app. Easy accessible with its bubble head button 🔘 . Easy to integrate in any apps, to handle development or testing apps easier. First version, there is plenty of room for improvement.

An extensible logging framework for Swift
An extensible logging framework for Swift

Log is a powerful logging framework that provides built-in themes and formatters, and a nice API to define your owns. Get the most out of Log by insta

Logging utility for Swift and Objective C
Logging utility for Swift and Objective C

Swell - Swift Logging A logging utility for Swift and Objective C. ##Features Turn on logging during development, turn them off when building for the

A powerful input-agnostic swift logging framework made to speed up development with maximum readability.
A powerful input-agnostic swift logging framework made to speed up development with maximum readability.

The Swift logging framework. Atlantis is an extremely powerful logging framework that I've created for everyday use, including enterprise development

Most natural Swift logging

Evergreen Most natural Swift logging Evergreen is a logging framework written in Swift. It is designed to work just as you would expect, yet so versat

Simple, lightweight and flexible debug logging framework written in Swift

AELog Simple, lightweight and flexible debug logging minion written in Swift If you find yourself in upcoming statements, then you probably want to us

A fast & simple, yet powerful & flexible logging framework for Mac and iOS
A fast & simple, yet powerful & flexible logging framework for Mac and iOS

CocoaLumberjack CocoaLumberjack is a fast & simple, yet powerful & flexible logging framework for macOS, iOS, tvOS and watchOS. How to get started Fir

Owner
Erik Turøy Midtun
Erik Turøy Midtun
Twitter Logging Service is a robust and performant logging framework for iOS clients

Twitter Logging Service Background Twitter created a framework for logging in order to fulfill the following requirements: fast (no blocking the main

Twitter 290 Nov 15, 2022
A logging backend for swift-log that sends logging messages to Logstash (eg. the ELK stack)

LoggingELK LoggingELK is a logging backend library for Apple's swift-log The LoggingELK library provides a logging backend for Apple's apple/swift-log

null 17 Nov 15, 2022
Convenient & secure logging during development & release in Swift 3, 4 & 5

Colorful, flexible, lightweight logging for Swift 3, Swift 4 & Swift 5. Great for development & release with support for Console, File & cloud platfor

SwiftyBeaver 5.6k Jan 4, 2023
Simple logging for simples needs.

Simple logging for simples needs.

native.dev.br 0 May 30, 2022
Class for logging excessive blocking on the main thread

Watchdog Class for logging excessive blocking on the main thread. It watches the main thread and checks if it doesn’t get blocked for more than define

Wojtek Lukaszuk 1.8k Dec 6, 2022
CleanroomLogger provides an extensible Swift-based logging API that is simple, lightweight and performant

CleanroomLogger CleanroomLogger provides an extensible Swift-based logging API that is simple, lightweight and performant. The API provided by Cleanro

null 1.3k Dec 8, 2022
Willow is a powerful, yet lightweight logging library written in Swift.

Willow Willow is a powerful, yet lightweight logging library written in Swift. Features Requirements Migration Guides Communication Installation Cocoa

Nike Inc. 1.3k Nov 16, 2022
Swift Logging Utility for Xcode & Google Docs

QorumLogs Swift Logging Utility in Xcode & Google Docs

Goktug Yilmaz 777 Jul 15, 2022
A lightweight logging framework for Swift

HeliumLogger Provides a lightweight logging implementation for Swift which logs to standard output. Features Logs output to stdout by default. You can

Kitura 174 Nov 30, 2022
A lightweight logging framework for Swift

HeliumLogger Provides a lightweight logging implementation for Swift which logs to standard output. Features Logs output to stdout by default. You can

Kitura 174 Nov 30, 2022