Code Monkey home page Code Monkey logo

lyria's Introduction

Lyria Music Player

This music player was built using Django. In addition to the actual Django project, this repository contains the following additional types of files:

  • Terraform files - for provisioning infrastructure on AWS
  • Docker files (Dockerfile, compose.yml, .dockerignore)
  • Configuration files (Nginx and GUnicorn)
  • bucketActions - boto3 scripts for easy bucket admin tasks
  • CI/CD pipeline (GitHub Actions) - workflow files in .github/workflows with scripts in ci_scripts/

Basic File Structure

  • .github
    • workflows
      • RunContainers.yml
      • CreateImage.yml
    • ci_scripts
      • create_ami.py
      • create_env.py
      • get_staging_server_ip.py
      • start_staging_server.py
      • stop_staging_server.py
    • README.md
  • bucketActions
    • addSong.py
    • listObjectKeys.py
    • replaceFile.py
  • lyria
    • init.py
    • asgi.py
    • settings.py
    • urls.py
    • wsgi.py
  • player
    • init.py
    • admin.py
    • apps.py
    • migrations
      • init.py
    • models.py
    • templates
      • index.html
    • tests.py
    • urls.py
    • views.py
  • requirements
    • ci-requirements.txt
    • docker-requirements.txt
  • terraform
    • blue
      • main.tf
      • outputs.tf
      • providers.tf
      • variables.tf
    • dns_records
      • main.tf
      • providers.tf
      • variables.tf
    • green
      • main.tf
      • outputs.tf
      • providers.tf
      • variables.tf
    • README.md
  • manage.py
  • .dockerignore
  • Dockerfile
  • compose.yml
  • gunicorn.conf.py
  • nginx.conf
  • .gitignore

.env File

For local development, an .env file must be included in the root directory with the following environment variables:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_STORAGE_BUCKET_NAME
  • AWS_S3_REGION_NAME
  • CLOUDFRONT_URL
  • SECRET_KEY (Django secret key)
  • DEBUG (True or False)
  • SONG_ORDER (list indexes)

DO NOT COMMIT THIS FILE. Include the .env file in .gitignore

DO NOT USE YOUR ADMIN USER FOR AWS KEYS. Create a user with read only access to your S3 bucket, and generate keys for that user.

For production, use an IAM role instead of keys altogether.

Environment Variables in CI Pipeline

The following environment variables must be included in the GitHub repository secrets:

  • AWS_ACCESS_KEY_ID

  • AWS_SECRET_ACCESS_KEY

  • SECRET_KEY

    • The AWS keys are separate from the ones used in the .env file. These keys are for the CI/CD pipeline to start and stop a staging server, as well as create and tag images. The policy should look like this:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "ec2:StartInstances",
                "ec2:CreateTags",
                "ec2:CreateImage",
                "ec2:StopInstances",
                "ec2:DescribeInstanceStatus"
            ],
            "Resource": "arn:aws:ec2:us-east-2:<aws_account_number>:instance/<instance_id>"
        },
        {
            "Sid": "VisualEditor1",
            "Effect": "Allow",
            "Action": [
                "ec2:DescribeInstances",
                "ec2:DescribeInstanceStatus",
                "ec2:CreateImage",
                "ec2:DescribeImages",
                "ec2:CreateTags"
            ],
            "Resource": "*"
        }
    ]
}

A .env file is created in the CI/CD pipeline to start containers on a running instance, then removed after the containers are running. Fill in environment variables in RunContainers.yml and CreateImage.yml.

Infrastructure configured ouside of Terraform

AWS S3 Bucket: For storing music files

Folder structure
    - songs
        - Song_Title_1
            - audio_file.mp3
            - image_file.mp3
        - Song_Title_2
            - audio_file.mp3
            - image_file.mp3

CloudFront Distribution: For serving audio and image files from storage bucket

SSL Certificate from AWS ACM

Domain name from AWS Route53

Basic Development Workflow

  1. Django is is developed locally, using the actual S3 bucket that will be used in production
  2. Docker is used to containerize the application with further testing
  3. CI Pipeline is used to build an AMI with running containers
  4. New AMI is used to update launch template in the Terraform configuration

These are very broad steps, but generally show a user how to use this repository to build and customize Lyria the way I did.

Article Links

I have not documented this entire project, but I do a few articles documenting key aspects. I will try to add more in the future.

Broad Overview of Entire Project

GitHub Actions Pipeline

lyria's People

Contributors

krisaff84 avatar

Stargazers

 avatar Kenny Brast avatar

Watchers

 avatar

Forkers

dejavxtrem

lyria's Issues

Manual approval required for workflow run 1: Approve new AMI ID for deployment ami-0f3126a734db2d3d3

Please review and approve the following Terraform plan:

PK�����ҸuX�	tfplanUT��}��e�|kl\�y(%���7�5��:��ܫ��p�D�<�}#( Ŗ�TI�Iq���`Μ9�c�=�df��%�M�h��A�F� ER0z�"%�DQ�l������N��

Once approved, the new AMI will pushed to production in the green environment.

Workflow is pending manual review.
URL: https://github.com/KrisAff84/Lyria/actions/runs/1

Required approvers: [KrisAff84]

Respond "approved", "approve", "lgtm", "yes" to continue workflow or "denied", "deny", "no" to cancel.

Update README to reflect new repository structure

lyria-dev folder needs to be changed to ci_scripts

Now, two requirements files are located in a requirements folder: docker-requirements.txt and ci-requirements.txt

Place .github/workflows in file structure

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.