Skip to content

Commit 1e98b8b

Browse files
authored
Merge pull request #23 from wikimediabrasil/video-download-toolforge
Video download feature
2 parents 50aa038 + a274b3b commit 1e98b8b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+860
-4075
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ jobs:
2424
with:
2525
python-version: ${{ matrix.python-version }}
2626

27+
- name: Install system dependencies
28+
run: |
29+
sudo apt update
30+
sudo apt install -y librsvg2-bin ffmpeg
31+
2732
- name: Install dependencies
2833
run: |
2934
python -m pip install --upgrade pip
30-
pip install -r src/requirements.txt
31-
pip install -r src/requirements-dev.txt
35+
pip install -r requirements.txt
36+
pip install -r requirements-dev.txt
3237
3338
- name: Run tests
3439
env:
3540
SECRET_KEY: dummysecretkey
3641
DEBUG: True
37-
run: |
38-
cd src
39-
python3 manage.py test
42+
run: python3 manage.py test

.github/workflows/toolforge-deploy.yml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,13 @@ jobs:
2323
key: ${{ secrets.SSH_PRIVATE_KEY }}
2424
port: ${{ vars.SSH_PORT }}
2525
request_pty: true
26+
command_timeout: 30m
2627
script: |
2728
set -xe
28-
become infographics git -C ./www/python/src pull origin main
29-
become infographics webservice node18 shell -- npm --prefix ./www/python/client/ install
30-
become infographics webservice --mem 1Gi node18 shell -- npm --prefix ./www/python/client/ run build
31-
become infographics mkdir -p ./www/python/src/web/templates
32-
become infographics mkdir -p ./www/python/src/web/static/frontend
33-
become infographics cp ./www/python/client/dist/index.html ./www/python/src/web/templates/index.html
34-
become infographics rm -rf ./www/python/src/web/static/frontend/assets
35-
become infographics cp -r ./www/python/client/dist/assets ./www/python/src/web/static/frontend/assets
36-
become infographics webservice python3.11 shell -- webservice-python-bootstrap
37-
become infographics webservice python3.11 shell -- ./www/python/venv/bin/python ./www/python/src/manage.py migrate
38-
become infographics webservice python3.11 shell -- ./www/python/venv/bin/python ./www/python/src/manage.py collectstatic --noinput --clear
39-
become infographics webservice python3.11 restart
40-
become infographics webservice python3.11 status
29+
become infographics toolforge envvars create DEBUG "True"
30+
become infographics toolforge envvars create MEDIA_ROOT "/data/project/infographics/media"
31+
become infographics toolforge build clean -y
32+
become infographics toolforge build start https://github.com/wikimediabrasil/wiki_infographics
33+
become infographics toolforge jobs run --image tool-infographics/tool-infographics:latest --command "migrate" --no-filelog --wait --mount=all migrate
34+
become infographics toolforge webservice stop
35+
become infographics toolforge webservice buildservice start --mount all --mem 3Gi --cpu 2

.gitignore

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# Django collected static files
2-
/src/static
2+
/static
3+
4+
# Generated files
5+
/media
36

47
# Static files and templates from frontend code
5-
/src/web/static/frontend
6-
/src/web/templates/index.html
8+
/web/templates/index.html
9+
/web/static/frontend/assets
710

811
.DS_*
912
*.log

Aptfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ffmpeg
2+
librsvg2-bin

Dockerfile

Lines changed: 0 additions & 29 deletions
This file was deleted.

Procfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
web: gunicorn --bind=0.0.0.0:8000 --workers=4 --timeout 120 --log-level debug --forwarded-allow-ips=* infographics.wsgi:application
2+
migrate: python manage.py migrate

README.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,64 @@ The tool is composed of a Django backend and a React frontend, both on this repo
66

77
## Running locally
88

9-
To run the tool locally, you need Docker and Docker Compose.
9+
To run the tool locally, have NodeJS, Python, `rsvg-convert` and `ffmpeg` installed. You need two terminals.
10+
11+
In one of them, run the frontend
1012

1113
```bash
12-
docker-compose up --build
14+
npm install
15+
npm run dev
16+
```
17+
18+
And open your browser at <http://localhost:5173/web/infographics/>.
19+
20+
For the backend, run
21+
22+
```bash
23+
python3 manage.py runserver
1324
```
1425

1526
Open the app at <http://localhost:7840>.
1627

1728
If you make any changes, you can kill the process and run again, or restart the app container with `docker-compose up -d --build --force-recreate app`.
1829

30+
1931
## License
2032

2133
This project is licensed under the [MIT License](https://opensource.org/license/mit) - see the LICENSE file for details.
34+
35+
## Toolforge deployment
36+
37+
Since we need apt packages we are using [Toolforge's custom builds feature](https://wikitech.wikimedia.org/wiki/Help:Toolforge/Building_container_images) so that we can have `ffmpeg` and `rsvg-convert` utilities installed.
38+
39+
On toolforge, run the following to clean build space, build the image, run migrations and start the server.
40+
41+
```bash
42+
toolforge build clean -y
43+
toolforge build start https://github.com/wikimediabrasil/wiki_infographics
44+
toolforge jobs run --image tool-infographics/tool-infographics:latest --command "migrate" --wait --mount=all migrate
45+
toolforge webservice buildservice restart --mount all
46+
```
47+
48+
We are using `--mount=all` because we're still using SQLite and we need a directory to store the videos.
49+
50+
Set environment variables with `toolforge envvars create <VARIABLE> <VALUE>`.
51+
52+
## Running locally with buildpack
53+
54+
This is the way to build the image locally:
55+
56+
```bash
57+
sudo pack build --builder tools-harbor.wmcloud.org/toolforge/heroku-builder:22 --buildpack heroku/nodejs --buildpack heroku/python --buildpack heroku/procfile --buildpack fagiani/apt infographics
58+
sudo docker run -e PORT=8000 -e DEBUG=True -e SECRET_KEY=123 -p 8000:8000 -it --entrypoint 'bash' infographics
59+
```
60+
61+
Inside the container, you can run `migrate` or `web`. The binaries are not directly available to the path, these fixes are necessary when entering bash:
62+
63+
```bash
64+
source /layers/fagiani_apt/apt/.profile.d/000_apt.sh
65+
cp -r /layers/fagiani_apt/apt/usr/lib/x86_64-linux-gnu/*/* /layers/fagiani_apt/apt/usr/lib/x86_64-linux-gnu/
66+
```
67+
68+
Then it is possible to run `web` and have `ffmpeg` and `rsvg-convert` installed.
69+
File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from django.apps import AppConfig
22

33

4-
class QueryConfig(AppConfig):
4+
class ApiConfig(AppConfig):
55
default_auto_field = 'django.db.models.BigAutoField'
6-
name = 'query'
6+
name = 'api'

0 commit comments

Comments
 (0)