Skip to content

Commit

Permalink
Setup basic s3 integration for songs + extracted some keys to .env
Browse files Browse the repository at this point in the history
  • Loading branch information
forreya committed Feb 15, 2025
1 parent f8a96d4 commit c8af418
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 8 deletions.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ services:
- "2809:2809"
volumes:
- ./server:/server # bind mount
- ~/.aws/:/root/.aws:ro # make AWS configuration available through a temporary read-only volume
depends_on:
database:
condition: service_healthy
Expand Down
8 changes: 7 additions & 1 deletion server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,10 @@ $ source .venv/bin/activate // activates the virtual environment

The `requirements.txt` file contains the contents of the virtual environment. After generating the `requirements.txt` file, you can just delete the `.venv` folder.

2. Create Dockerfile
2. Create Dockerfile

### Setup AWS CLI Configuration

See: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-quickstart.html

Setup for 'long term credentials' using the guide above.
24 changes: 24 additions & 0 deletions server/music/migrations/0003_remove_track_url_track_s3_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 5.1.4 on 2025-01-26 12:32

import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('music', '0002_alter_track_channels_alter_track_featuring_artists'),
]

operations = [
migrations.RemoveField(
model_name='track',
name='url',
),
migrations.AddField(
model_name='track',
name='s3_key',
field=models.CharField(default=django.utils.timezone.now, max_length=200),
preserve_default=False,
),
]
18 changes: 18 additions & 0 deletions server/music/migrations/0004_alter_track_featuring_artists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1.4 on 2025-02-01 13:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('music', '0003_remove_track_url_track_s3_key'),
]

operations = [
migrations.AlterField(
model_name='track',
name='featuring_artists',
field=models.CharField(blank=True, max_length=500, null=True),
),
]
10 changes: 9 additions & 1 deletion server/music/serializer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
from rest_framework import serializers
from .models import Track
import os

class TrackSerializer(serializers.ModelSerializer):
s3_url = serializers.SerializerMethodField('get_s3_url')

def get_s3_url(self, track):
AWS_BUCKET_NAME = os.getenv('AWS_BUCKET_NAME')
AWS_BUCKET_REGION = os.getenv('AWS_BUCKET_REGION')
return f"http://{AWS_BUCKET_NAME}.s3.{AWS_BUCKET_REGION}.amazonaws.com/audio/{track.s3_key}"

class Meta:
model = Track
fields = '__all__'
fields = ['title', 'artist', 'featuring_artists', 's3_url']
3 changes: 2 additions & 1 deletion server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ Django==5.1.4
sqlparse==0.5.3
psycopg2-binary==2.9.10
djangorestframework==3.15.2
boto3==1.36.2
boto3==1.36.2
python-dotenv==1.0.1
11 changes: 6 additions & 5 deletions server/server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,25 @@
"""

from pathlib import Path
from dotenv import load_dotenv
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

load_dotenv(BASE_DIR / '.env')

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-wkoa^gdo7_tpgjme+ki3_wx3es&-qor+*=qvlo5*ff&m5!mha#'
SECRET_KEY = os.getenv('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = os.getenv('ENV_VAR', 'False').lower() in ('true', '1')

ALLOWED_HOSTS = ['0.0.0.0']
ALLOWED_HOSTS = ['0.0.0.0', 'localhost']

# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
Expand Down

0 comments on commit c8af418

Please sign in to comment.