feat: don't use poetry in production deployments

This commit is contained in:
jo 2023-01-13 16:26:28 +01:00
parent efbdc027ab
commit 75c9b1eabe
No known key found for this signature in database
GPG Key ID: B2FEC9B22722B984
13 changed files with 77 additions and 122 deletions

View File

@ -0,0 +1 @@
Don't use poetry in production deployments

View File

@ -26,9 +26,9 @@ funkwhale_beat_chdir="/usr/local/www/funkwhale/api"
funkwhale_beat_user="funkwhale" funkwhale_beat_user="funkwhale"
funkwhale_beat_env="$(grep -v '^#' /usr/local/www/funkwhale/config/.env | xargs)" funkwhale_beat_env="$(grep -v '^#' /usr/local/www/funkwhale/config/.env | xargs)"
pidfile="/var/run/funkwhale/${name##funkwhale_}.pid" pidfile="/var/run/funkwhale/${name##funkwhale_}.pid"
command_interpreter="/usr/local/www/funkwhale/virtualenv/bin/python3" command_interpreter="/usr/local/www/funkwhale/venv/bin/python3"
command="/usr/local/www/funkwhale/virtualenv/bin/celery" command="/usr/local/www/funkwhale/venv/bin/celery"
command_args="\ command_args="\
--app funkwhale_api.taskapp \ --app funkwhale_api.taskapp \
beat \ beat \

View File

@ -25,9 +25,9 @@ load_rc_config "$name"
funkwhale_server_chdir="/usr/local/www/funkwhale/api" funkwhale_server_chdir="/usr/local/www/funkwhale/api"
funkwhale_server_user="funkwhale" funkwhale_server_user="funkwhale"
funkwhale_server_env="$(grep -v '^#' /usr/local/www/funkwhale/config/.env | xargs)" funkwhale_server_env="$(grep -v '^#' /usr/local/www/funkwhale/config/.env | xargs)"
command_interpreter="/usr/local/www/funkwhale/virtualenv/bin/python3" command_interpreter="/usr/local/www/funkwhale/venv/bin/python3"
command="/usr/local/www/funkwhale/virtualenv/bin/gunicorn" command="/usr/local/www/funkwhale/venv/bin/gunicorn"
command_args="\ command_args="\
config.asgi:application \ config.asgi:application \
--workers 4 \ --workers 4 \

View File

@ -26,9 +26,9 @@ funkwhale_worker_chdir="/usr/local/www/funkwhale/api"
funkwhale_worker_user="funkwhale" funkwhale_worker_user="funkwhale"
funkwhale_worker_env=$(grep -v '^#' /usr/local/www/funkwhale/config/.env | xargs) funkwhale_worker_env=$(grep -v '^#' /usr/local/www/funkwhale/config/.env | xargs)
pidfile="/var/run/funkwhale/${name##funkwhale_}.pid" pidfile="/var/run/funkwhale/${name##funkwhale_}.pid"
command_interpreter="/usr/local/www/funkwhale/virtualenv/bin/python3" command_interpreter="/usr/local/www/funkwhale/venv/bin/python3"
command="/usr/local/www/funkwhale/virtualenv/bin/celery" command="/usr/local/www/funkwhale/venv/bin/celery"
command_args="\ command_args="\
--app funkwhale_api.taskapp \ --app funkwhale_api.taskapp \
worker \ worker \

View File

@ -5,7 +5,7 @@ NAME="funkwhalebeat"
PIDFILE="/var/run/$NAME.pid" PIDFILE="/var/run/$NAME.pid"
USER="funkwhale" USER="funkwhale"
WORKDIR="/srv/funkwhale/api" WORKDIR="/srv/funkwhale/api"
Celery="/srv/funkwhale/virtualenv/bin/celery" Celery="/srv/funkwhale/venv/bin/celery"
BEAT_ARGS="--app funkwhale_api.taskapp beat --loglevel INFO" BEAT_ARGS="--app funkwhale_api.taskapp beat --loglevel INFO"
depend() { depend() {

View File

@ -5,7 +5,7 @@ NAME="funkwhaleserver"
PIDFILE="/var/run/$NAME.pid" PIDFILE="/var/run/$NAME.pid"
USER="funkwhale" USER="funkwhale"
DAEMON_ARGS="config.asgi:application --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 127.0.0.1:5000" DAEMON_ARGS="config.asgi:application --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 127.0.0.1:5000"
Gunicorn="/srv/funkwhale/virtualenv/bin/gunicorn" Gunicorn="/srv/funkwhale/venv/bin/gunicorn"
WORKDIR="/srv/funkwhale/api" WORKDIR="/srv/funkwhale/api"
depend() { depend() {

View File

@ -5,7 +5,7 @@ NAME="funkwhaleworker"
PIDFILE="/var/run/$NAME.pid" PIDFILE="/var/run/$NAME.pid"
USER="funkwhale" USER="funkwhale"
WORKDIR="/srv/funkwhale/api" WORKDIR="/srv/funkwhale/api"
Celery="/srv/funkwhale/virtualenv/bin/celery" Celery="/srv/funkwhale/venv/bin/celery"
WORKER_ARGS="--app funkwhale_api.taskapp worker --loglevel INFO" WORKER_ARGS="--app funkwhale_api.taskapp worker --loglevel INFO"
depend() { depend() {

View File

@ -8,7 +8,11 @@ User=funkwhale
# adapt this depending on the path of your funkwhale installation # adapt this depending on the path of your funkwhale installation
WorkingDirectory=/srv/funkwhale/api WorkingDirectory=/srv/funkwhale/api
EnvironmentFile=/srv/funkwhale/config/.env EnvironmentFile=/srv/funkwhale/config/.env
ExecStart=/srv/funkwhale/.local/bin/poetry run celery -A funkwhale_api.taskapp beat -l INFO
ExecStart=/srv/funkwhale/venv/bin/celery \
--app funkwhale_api.taskapp \
beat \
--loglevel INFO
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View File

@ -8,6 +8,12 @@ User=funkwhale
# adapt this depending on the path of your funkwhale installation # adapt this depending on the path of your funkwhale installation
WorkingDirectory=/srv/funkwhale/api WorkingDirectory=/srv/funkwhale/api
EnvironmentFile=/srv/funkwhale/config/.env EnvironmentFile=/srv/funkwhale/config/.env
ExecStart=/srv/funkwhale/.local/bin/poetry run gunicorn config.asgi:application -w ${FUNKWHALE_WEB_WORKERS} -k uvicorn.workers.UvicornWorker -b ${FUNKWHALE_API_IP}:${FUNKWHALE_API_PORT}
ExecStart=/srv/funkwhale/venv/bin/gunicorn \
config.asgi:application \
--workers ${FUNKWHALE_WEB_WORKERS} \
--worker-class uvicorn.workers.UvicornWorker \
--bind ${FUNKWHALE_API_IP}:${FUNKWHALE_API_PORT}
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View File

@ -9,8 +9,12 @@ User=funkwhale
WorkingDirectory=/srv/funkwhale/api WorkingDirectory=/srv/funkwhale/api
Environment="CELERYD_CONCURRENCY=0" Environment="CELERYD_CONCURRENCY=0"
EnvironmentFile=/srv/funkwhale/config/.env EnvironmentFile=/srv/funkwhale/config/.env
ExecStart=/srv/funkwhale/.local/bin/poetry run celery -A funkwhale_api.taskapp worker -l INFO --concurrency=${CELERYD_CONCURRENCY}
ExecStart=/srv/funkwhale/venv/bin/celery \
--app funkwhale_api.taskapp \
worker \
--loglevel INFO \
--concurrency=${CELERYD_CONCURRENCY}
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View File

@ -30,7 +30,12 @@ Celery uses a `prefork` pool by default. This enables the server to process many
2. Add the `--pool=solo` flag to the `ExecStart` line of your unit file. 2. Add the `--pool=solo` flag to the `ExecStart` line of your unit file.
```{code-block} text ```{code-block} text
ExecStart=/srv/funkwhale/.local/bin/poetry run celery -A --pool=solo funkwhale_api.taskapp worker -l INFO --concurrency=${CELERYD_CONCURRENCY} ExecStart=/srv/funkwhale/venv/bin/celery \
--app funkwhale_api.taskapp \
--pool solo \
worker \
--loglevel INFO \
--concurrency=${CELERYD_CONCURRENCY}
``` ```
3. Restart the Celery service. 3. Restart the Celery service.

View File

@ -122,31 +122,25 @@ Once you've created the directory structure you can download Funkwhale. Funkwhal
You're done! These commands put the software in the correct location for Funkwhale to serve them. You're done! These commands put the software in the correct location for Funkwhale to serve them.
## 4. Install Python dependencies ## 4. Install the Funkwhale API
The Funkwhale API is written in Python. You need to install the API's dependencies to run the software. We use [Poetry](https://python-poetry.org) to handle Python dependencies. The Funkwhale API is written in Python. You need to install the API's package to run the software:
1. Install Poetry. Follow the steps in this wizard to set it up. 1. Setup a Python virtual environment:
```{code-block} sh ```{code-block} sh
curl -sSL https://install.python-poetry.org | python3 - cd /srv/funkwhale
sudo python3 -m venv venv
sudo venv/bin/pip install --upgrade pip wheel
``` ```
2. Add Poetry to your `$PATH`. This allows you to use `poetry` commands. 2. Install the Funkwhale API package and dependencies:
```{code-block} sh ```{code-block} sh
export "PATH=$HOME/.local/bin:$PATH" >> ~/.bashrc sudo venv/bin/pip install --editable ./api
echo 'export "PATH=$HOME/.local/bin:$PATH"' >> ~/.bashrc
``` ```
3. Set up poetry in your `/srv/funkwhale/api` directory. You're done!
```{code-block} sh
cd /srv/funkwhale/api
sudo poetry install
```
You're done! Poetry installs all Python dependencies.
## 5. Set up your environment file ## 5. Set up your environment file
@ -369,34 +363,28 @@ grep '${' /etc/nginx/sites-enabled/funkwhale.conf
To enable your users to connect to your pod securely, you need to set up {abbr}`TLS (Transport Layer Security)`. To do this, we recommend using the <acme.sh> script. To enable your users to connect to your pod securely, you need to set up {abbr}`TLS (Transport Layer Security)`. To do this, we recommend using the <acme.sh> script.
1. Log in as the superuser account to run these commands. 1. Create the `/etc/certs` folder to store the certificates.
```{code-block} sh ```{code-block} sh
su sudo mkdir /etc/certs
``` ```
2. Create the `/etc/certs` folder to store the certificates. 2. Download and run `acme.sh`. Replace `my@example.com` with your email address.
```{code-block} sh ```{code-block} sh
mkdir /etc/certs curl https://get.acme.sh | sudo sh -s email=my@example.com
``` ```
3. Download and run `acme.sh`. Replace `my@example.com` with your email address. 3. Generate a certificate. Replace `example.com` with your Funkwhale pod name. Use `/srv/funkwhale/front` as your web root folder.
```{code-block} sh ```{code-block} sh
curl https://get.acme.sh | sh -s email=my@example.com sudo acme.sh --issue -d example.com -w /srv/funkwhale/front
``` ```
4. Generate a certificate. Replace `example.com` with your Funkwhale pod name. Use `/srv/funkwhale/front` as your web root folder. 4. Install the certificate to your Nginx config. Replace `example.com` with your Funkwhale pod name.
```{code-block} sh ```{code-block} sh
acme.sh --issue -d example.com -w /srv/funkwhale/front sudo acme.sh --install-cert -d example.com \
```
5. Install the certificate to your Nginx config. Replace `example.com` with your Funkwhale pod name.
```{code-block} sh
acme.sh --install-cert -d example.com \
--key-file /etc/certs/key.pem \ --key-file /etc/certs/key.pem \
--fullchain-file /etc/certs/cert.pem \ --fullchain-file /etc/certs/cert.pem \
--reloadcmd "service nginx force-reload" --reloadcmd "service nginx force-reload"

View File

@ -2,78 +2,37 @@
If you installed Funkwhale following the [Debian guide](../installation_docs/debian.md), follow these steps to upgrade. If you installed Funkwhale following the [Debian guide](../installation_docs/debian.md), follow these steps to upgrade.
:::{dropdown} Upgrading to a new version of Python ## Cleanup old funkwhale files
:icon: alert
:color: warning
If you upgrade your Python version, you need to update your virtualenv. Python is updated with each new version of Debian. 1. Stop the Funkwhale services.
To upgrade your virtualenv:
1. Change to your api directory.
```{code-block} sh
cd /srv/funkwhale/api
```
2. Rerun `poetry install` to reinstall your dependencies in a new virtualenv.
```{code-block} sh
poetry install
```
:::
## Download the updated files
1. SSH into your server.
2. Log in as your `funkwhale` user.
```{code-block} sh
su funkwhale
```
3. Navigate to your Funkwhale directory.
```{code-block} sh
cd /srv/funkwhale
```
4. Stop the Funkwhale services.
```{code-block} sh ```{code-block} sh
sudo systemctl stop funkwhale.target sudo systemctl stop funkwhale.target
``` ```
5. Export the Funkwhale version you want to update to. You'll use this in the rest of the commands in this guide. 2. Navigate to your Funkwhale directory.
```{code-block} sh
cd /srv/funkwhale
```
3. Remove the old files.
```{code-block} sh
sudo rm -Rf api/* front/* venv
```
## Download Funkwhale
1. Export the Funkwhale version you want to update to. You'll use this in the rest of the commands in this guide.
```{parsed-literal} ```{parsed-literal}
export FUNKWHALE_VERSION={sub-ref}`version` export FUNKWHALE_VERSION={sub-ref}`version`
``` ```
6. Download the API files for your chosen Funkwhale version. 2. Follow the [3. Download Funkwhale](../installation_docs/debian.md#3-download-funkwhale) installation section.
```{code-block} sh 3. Follow the [4. Install the Funkwhale API](../installation_docs/debian.md#4-install-the-funkwhale-api) installation section.
curl -L -o "api-$FUNKWHALE_VERSION.zip" "https://dev.funkwhale.audio/funkwhale/funkwhale/-/jobs/artifacts/$FUNKWHALE_VERSION/download?job=build_api"
```
7. Extract the downloaded archive to a new directory.
```{code-block} sh
unzip "api-$FUNKWHALE_VERSION.zip" -o api_new
```
8. Remove the old `api` directory and move the extracted directory to the `api` directory.
```{code-block} sh
rm -rf api/ && mv api_new api
```
9. Remove the downloaded archive file.
```{code-block} sh
rm api-$FUNKWHALE_VERSION.zip
```
## Update your Funkwhale instance ## Update your Funkwhale instance
@ -85,31 +44,19 @@ Once you have downloaded the new files, you can update your Funkwhale instance.
sudo api/install_os_dependencies.sh install sudo api/install_os_dependencies.sh install
``` ```
2. Enter the `api` directory to run the following commands. 2. Collect the new static files to serve.
```{code-block} sh ```{code-block} sh
cd api sudo venv/bin/funkwhale-manage collectstatic --no-input
``` ```
3. Install all Python dependencies using `poetry`. 3. Apply new database migrations.
```{code-block} sh ```{code-block} sh
poetry install sudo -u funkwhale venv/bin/funkwhale-manage migrate
``` ```
4. Collect the new static files to serve. 4. Restart the Funkwhale services.
```{code-block} sh
poetry run python3 manage.py collectstatic --no-input
```
5. Apply new database migrations.
```{code-block} sh
poetry run python3 manage.py migrate
```
6. Restart the Funkwhale services.
```{code-block} sh ```{code-block} sh
sudo systemctl start funkwhale.target sudo systemctl start funkwhale.target