Skip to content

Instantly share code, notes, and snippets.

@AndBondStyle
Last active March 27, 2018 09:16
Show Gist options
  • Save AndBondStyle/05df95e204fde44523fc4fe174e239cd to your computer and use it in GitHub Desktop.
Save AndBondStyle/05df95e204fde44523fc4fe174e239cd to your computer and use it in GitHub Desktop.

AnySync — Internet media synchronizer

Try it live: any-sync.herokuapp.com

Working stack

  • Python — Main programming language
  • Django — Web backend framework
  • Channels — Async stuff for Django
  • FFmpeg — Video & audio processing
  • PostgreSQL — Primary database
  • Redis — Cache database and message broker
  • AWS S3 — Static and media files CDN
  • Bootstrap — Web frontend library
  • Heroku — Cloud application platform
  • Sentry — Error tracking platform

Installation

  • Install Python 3.6+ from python.org
  • Install and configure virtualenv (optional)
  • Install dependencies via pip install -r config/requirements/dev.txt
  • Install FFmpeg via ffmpeg.org

After these steps everything will "just work", but only with development settings. In order to deploy this project on Heroku or production server, you need to setup some extra services and environment variables described below.

Extra services

AWS S3 — Static and media files storage aka CDN

Highly recommended for production (especially Heroku). Other serving options: Whitenoise middleware, Apache or Nginx. Below is shortened and simplified setup instructions originally taken from this article. The last thing to mention is that AWS S3 is completely free (with some reasonable limitations, of course) for the first year of usage.

  • Create an AWS account: aws.amazon.com
  • Create S3 bucket and remember its region and name: guide
  • Allow read-only access: guide (2nd topic)
  • Create an account for programmatic access:
    • Via AWS console open IAM > Users
    • Click "Add user", enter suitable name (e.g. "bucket-admin") and check "Programmatic access" option
    • At the next step, select "Attach existing policies" and click "Create policy"
    • In the opened tab, click "Import managed policy" and search for "AmazonS3FullAccess"
    • After importing, switch to "JSON" tab and replace "Resource" by following:
      • "Resource": ["arn:aws:s3:::bucket", "arn:aws:s3:::bucket/*"]
      • Where "bucket" should be your bucket name, of course
    • Enter policy name (e.g. "bucket-full-access") and submit
    • Returning to account tab, click "Refresh" and search for created policy
    • Finish account registration and save "Access key ID" and "Secret access key" values
  • Configure related environment variables:
    • AWS_BUCKET_NAME
    • AWS_REGION_NAME
    • AWS_ACCESS_KEY_ID
    • AWS_SECRET_ACCESS_KEY

Environment variables

Note on deploying

The first thing you should do on production server is to set DJANGO_SETTINGS_MODULE to config.settings.pro. The reason is that manage.py script uses config.settings.dev by default (as it's very handy for local development) but you definitely don't want it to act like that on production. See [deploying] section for more information.

Below is a full list of variables this project depends on. Please pay attention to some values marked with ⚠️ Warning sign. Detailed explanation is available via link attached to variable name. Special cast types are described in django-environ documentation.

Variable name Cast type Development default Production default
DJANGO_SETTINGS_MODULE str config.settings.dev ⚠️ config.settings.dev
ENV_FILE str dev.env <none>
VERSION str dev ⚠️ <none>
DATABASE_URL database sqlite:///sqlite.db ⚠️ <none>
REDIS_URL str <none> ⚠️ <none>
EMAIL_URL email filemail:// ⚠️ <none>
DJANGO_DEBUG bool True False
DJANGO_ADMIN_URL str ^admin/ ⚠️ <none>
DJANGO_SECRET_KEY str super-secret-key ⚠️ <none>
DJANGO_ALLOWED_HOSTS list * ⚠️ <none>
DJANGO_USE_AWS bool False True
AWS_BUCKET_NAME str <none> ⚠️ <none>
AWS_REGION_NAME str <none> ⚠️ <none>
AWS_ACCESS_KEY_ID str <none> ⚠️ <none>
AWS_SECRET_ACCESS_KEY str <none> ⚠️ <none>

License

AnySync is open-sourced software licensed under the MIT license

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment