Add music from funkwhale/catalog to gitpod instance

This commit is contained in:
wvffle 2022-07-01 21:51:36 +00:00
parent d56fd3e11e
commit 271c74e6d2
3 changed files with 52 additions and 1 deletions

View File

@ -28,8 +28,22 @@ tasks:
docker-compose run --rm api python manage.py createsuperuser --no-input --username gitpod --email gitpod@example.com
docker-compose run --rm api python manage.py fw users set --password "gitpod" gitpod --no-input
# Compile frontent
# Compile frontend locales
docker-compose run --rm front yarn run i18n-compile
# Login with cURL to create actors
docker-compose up -d nginx
gp ports await 8000
python .gitpod/init_actor.py
# Import music
git clone https://dev.funkwhale.audio/funkwhale/catalog.git
sudo mv catalog/music data
sudo chown -R root:root data/music
rm -rf catalog
LIBRARY_ID=`cat .gitpod/create_library.py | docker-compose run --rm -T api python manage.py shell -i python`
docker-compose run --rm api python manage.py import_files $LIBRARY_ID "/music/" --recursive --noinput --in-place
docker-compose stop
command: |
docker-compose up -d nginx
docker-compose up front api

17
.gitpod/create_library.py Normal file
View File

@ -0,0 +1,17 @@
from funkwhale_api.music.models import Library
from django.contrib.auth import get_user_model
actor = get_user_model().objects.get(username='gitpod').actor
try:
library = Library.objects.get(actor=actor)
except:
# Create library
library = Library()
library.actor = actor
library.description = 'Libre music to build a starter catalog for your instance'
library.name = 'funkwhale/catalog'
library.privacy_level = 'everyone'
library.save()
print(str(library.uuid))

20
.gitpod/init_actor.py Normal file
View File

@ -0,0 +1,20 @@
import subprocess
import requests
INSTANCE_URL = subprocess.check_output(['gp', 'url', '8000']).decode()[:-1]
# Login to initialize user actor
req = requests.Session()
res = req.get(INSTANCE_URL + '/login')
token = res.cookies['csrftoken']
req.post(INSTANCE_URL + '/api/v1/users/login', data={
'username': 'gitpod',
'password': 'gitpod'
}, headers={
'Referer': INSTANCE_URL + '/login',
'X-CSRFTOKEN': token
})
req.get(INSTANCE_URL)