Giter Site home page Giter Site logo

mems / macports-webapp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from macports/macports-webapp

0.0 1.0 0.0 7.01 MB

Web application to display information about ports, build history and installation statistics

Home Page: https://ports.macports.org/

License: BSD 2-Clause "Simplified" License

Python 51.02% HTML 39.98% Tcl 1.80% CSS 0.45% JavaScript 6.05% Dockerfile 0.65% Shell 0.05%

macports-webapp's Introduction

Introduction

Goal

This is a web application that:

  1. Displays general information about all the ports.
  2. Fetches and displays build history of the ports.
  3. Collects and displays installation statistics (system configurations and installed ports) from users who opt-in by installing the port mpstats.

It aims at being an all-one-place for users to find relevant ports and for maintainers to monitor their ports and understand their user base. The app is running in production at ports.macports.org.

More info at docs/1-INFORMATION.md

Architecture

The web application is based on the Django Framework utilising a PostgreSQL database.

The app is supposed to be deployed in a docker container with nginx and uWSGI serving the content.

This web application has been implemented during the Google Summer of Code 2019 mentored by the MacPorts organisation.

Student: Arjun Salyan
Mentors: Mojca Miklavec, Umesh Singla


Running the App

The repository contains Docker configuration which can be used to the build docker image, however, the app can be run without using the docker container. Both ways are discussed below:

1. Run inside Docker Container

It is the recommended way, the Docker Image of the app is pre-configured to run the migrations and collectstatic. However, the commands to populate the database with the initial data and to start the cron jobs need to be run manually.

The image can be pulled from Docker Hub or can be built locally:

docker pull arjunsalyan/macports-webapp

or build the image

docker build -t macports-webapp .

After the image has been built or pulled, run it using an env file that contains environment variables. Create a file env in the root of the project and supply the information as shown in the format below. A sample env file is supplied in the root of the repository: env.sample, you may rename it to env and insert the values to the variables.

env: (Contains environment variables)

DB_NAME=
DB_USER=
DB_PASSWORD=
DB_HOST=
DB_PORT= [default: '5432']
SECRET_KEY=

NOTE: If you want to connect to a database running on your host machine, then use host.docker.internal instead of localhost in the variable DB_HOST.

  1. Now run the image:
docker run -d -p 80:80 --env-file=env --name=macports-webapp macports-webapp

and visit 127.0.0.1:80 to see if everything looks fine. Sometimes, it may take 10-15 seconds for the site to display the layout properly because migrations and collectstatic commands are running in the background. There will not be any contents in the site because the database is empty, but it should load up nicely with empty sections.

  1. Populate the database with the initial data using the command:
docker exec macports-webapp python3 /code/app/manage.py autoload-initial-data

This command should be run only on an empty database. It fetches the latest PortIndex.json file from rsync server and populates an empty database.

After starting the command, take a break. The process can take quiet a while, generally it should finish within 30 minutes but can vary based on the connection between your database and app.

  1. Start the cron jobs (only after the previous command finishes):
docker exec macports-webapp supervisorctl start cron

This would start two cron jobs:

  1. Fetch build history once every hour by using app's command: python3 manage.py fetch-build-history
  2. Run updates on the portindex every three hours, command: python3 manage.py update-portinfo

After you see the message: cron: started, your app is ready. It would automatically keep itself updated.

All other commands supported by the app can be run using:

docker exec macports-webapp [command]

2. Run Without Docker

The /app directory is a standalone Django-app which can be run normally like any other django application.

Setup the Database

For security reasons, we discourage writing the database credentials into the app/MacPorts/settings.py file. It is recommended that you setup environment variables to connect to the app. The app requires following environment variables:

DB_NAME=
DB_USER=
DB_PASSWORD=
DB_HOST=
SECRET_KEY=

The variables are self explanatory. Use them to connect to your database.

If you do not want to supply environment variables then you may directly supply these credentials in the settings file: app/MacPorts/settings.py (not recommended).

Make Migrations

  • Make migrations
python3 manage.py makemigrations

  • Run the migrations
python3 manage.py migrate

Populate Initial Data in the Database

  • Put the file portindex.json or <filename> in the root of the project. To generate this file, you need to run portindex2json.tcl.
  • Run python3 manage.py load <filename> to populate the Ports, Categories and Maintainers tables. If you do not supply <filename>, the default portindex.json will be used.
  • Run python3 manage.py fetch-build-history to fetch few recent builds from the buildbot.

Start the Server

Start the server after running collectstatic

python3 manage.py collectstatic
python3 manage.py runserver

Updating the Database

  • Put the new json file in the root of the project.
  • Run python3 manage.py update <filename> to update the database.

If you do not supply <filename> then the default portindex.json will be used. This command supports both differential and full updates, depending upon the nature of the JSON file provided to it.

macports-webapp's People

Contributors

amake avatar arjunsalyan avatar dependabot-preview[bot] avatar dependabot[bot] avatar me-diru avatar mojca avatar neverpanic avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.