blastbeng / spotisub

Spotify to subsonic Playlist Generator and Importer
MIT License
103 stars 5 forks source link

Bug: Couldn't write to Cache #22

Closed TheMBeat closed 1 month ago

blastbeng commented 1 month ago

Need more info.

TheMBeat commented 1 month ago

I used the Docker compose file. Started the container and then called first_run.sh. Open the URL, confirm and enter the new URL. An error occurs when saving the credentials.

blastbeng commented 1 month ago

I used the Docker compose file. Started the container and then called first_run.sh. Open the URL, confirm and enter the new URL. An error occurs when saving the credentials.

Can you share this error? Also make sure to give the correct chown and chmod permissions to the cache dir.

TheMBeat commented 1 month ago

Sure, but not until tonight. This is the first time I've had problems with it on my Ubuntu Home Server. Other containers can write to the volume without problems.

blastbeng commented 1 month ago

Sure, but not until tonight. This is the first time I've had problems with it on my Ubuntu Home Server. Other containers can write to the volume without problems.

Ok, then i will need a log of the container and the command you are executing just remember to hide your api keys

TheMBeat commented 1 month ago

Here is the compose-file:

name: subtify
services:
  subtify:
    cpu_shares: 50
    command: []
    container_name: subtify
    deploy:
      resources:
        limits:
          memory: 1024M
    entrypoint:
      - ./entrypoint.sh
    environment:
      - PGID=1000
      - PUID=1000
      - SPOTIPY_CLIENT_ID=XXXXXXXX
      - SPOTIPY_CLIENT_SECRET=XXXXXXXXX
      - SPOTIPY_REDIRECT_URI=http://127.0.0.1:8080/
      - SUBSONIC_API_HOST=XXXXXXXX
      - SUBSONIC_API_PASS=XXXXXXX
      - SUBSONIC_API_PORT=4533
      - SUBSONIC_API_USER=XXXXX
      - TZ=Europe/Berlin
    hostname: subtify
    healthcheck:
      test:
        - CMD
        - curl
        - -f
        - http://127.0.0.1:50811/utils/healthcheck
      timeout: 5s
      interval: 15s
      retries: 12
    image: blastbeng/subtify:latest
    ports:
      - target: 50811
        published: "50811"
        protocol: tcp
    privileged: true
    restart: always
    user: 1000:1000
    volumes:
      - type: bind
        source: /DATA/AppData/subtify_data
        target: /home/user/subtify/cache
    devices: []
    cap_add: []
    network_mode: bridge
x-casaos:
  author: self
  category: self
  hostname: ""
  icon: ""
  index: /
  is_uncontrolled: false
  port_map: "50811"
  scheme: http
  store_app_id: subtify
  title:
    custom: Subtify
  1. Start the Container with sudo docker compose up -d
  2. Run the Command sudo docker exec -it subtify ./first_run.sh --interactive --tty
  3. Open the given URL -> then Paste the redirected URL and get an Error Couldn't write token to cache at: /home/user/subtify/cache/spotipy_cache
Aerglonus commented 1 month ago

Here is the compose-file:

name: subtify
services:
  subtify:
    cpu_shares: 50
    command: []
    container_name: subtify
    deploy:
      resources:
        limits:
          memory: 1024M
    entrypoint:
      - ./entrypoint.sh
    environment:
      - PGID=1000
      - PUID=1000
      - SPOTIPY_CLIENT_ID=XXXXXXXX
      - SPOTIPY_CLIENT_SECRET=XXXXXXXXX
      - SPOTIPY_REDIRECT_URI=http://127.0.0.1:8080/
      - SUBSONIC_API_HOST=XXXXXXXX
      - SUBSONIC_API_PASS=XXXXXXX
      - SUBSONIC_API_PORT=4533
      - SUBSONIC_API_USER=XXXXX
      - TZ=Europe/Berlin
    hostname: subtify
    healthcheck:
      test:
        - CMD
        - curl
        - -f
        - http://127.0.0.1:50811/utils/healthcheck
      timeout: 5s
      interval: 15s
      retries: 12
    image: blastbeng/subtify:latest
    ports:
      - target: 50811
        published: "50811"
        protocol: tcp
    privileged: true
    restart: always
    user: 1000:1000
    volumes:
      - type: bind
        source: /DATA/AppData/subtify_data
        target: /home/user/subtify/cache
    devices: []
    cap_add: []
    network_mode: bridge
x-casaos:
  author: self
  category: self
  hostname: ""
  icon: ""
  index: /
  is_uncontrolled: false
  port_map: "50811"
  scheme: http
  store_app_id: subtify
  title:
    custom: Subtify
  1. Start the Container with sudo docker compose up -d
  2. Run the Command sudo docker exec -it subtify ./first_run.sh --interactive --tty
  3. Open the given URL -> then Paste the redirected URL and get an Error Couldn't write token to cache at: /home/user/subtify/cache/spotipy_cache

Not enough permissions, either add the permissions to the directory on the container chmod -R 777 ./cache or create the cache directory on the host before starting the container, I noticed the container creates the directory as root that's why its not able to write to it.

blastbeng commented 1 month ago

Here is the compose-file:

name: subtify
services:
  subtify:
    cpu_shares: 50
    command: []
    container_name: subtify
    deploy:
      resources:
        limits:
          memory: 1024M
    entrypoint:
      - ./entrypoint.sh
    environment:
      - PGID=1000
      - PUID=1000
      - SPOTIPY_CLIENT_ID=XXXXXXXX
      - SPOTIPY_CLIENT_SECRET=XXXXXXXXX
      - SPOTIPY_REDIRECT_URI=http://127.0.0.1:8080/
      - SUBSONIC_API_HOST=XXXXXXXX
      - SUBSONIC_API_PASS=XXXXXXX
      - SUBSONIC_API_PORT=4533
      - SUBSONIC_API_USER=XXXXX
      - TZ=Europe/Berlin
    hostname: subtify
    healthcheck:
      test:
        - CMD
        - curl
        - -f
        - http://127.0.0.1:50811/utils/healthcheck
      timeout: 5s
      interval: 15s
      retries: 12
    image: blastbeng/subtify:latest
    ports:
      - target: 50811
        published: "50811"
        protocol: tcp
    privileged: true
    restart: always
    user: 1000:1000
    volumes:
      - type: bind
        source: /DATA/AppData/subtify_data
        target: /home/user/subtify/cache
    devices: []
    cap_add: []
    network_mode: bridge
x-casaos:
  author: self
  category: self
  hostname: ""
  icon: ""
  index: /
  is_uncontrolled: false
  port_map: "50811"
  scheme: http
  store_app_id: subtify
  title:
    custom: Subtify
  1. Start the Container with sudo docker compose up -d
  2. Run the Command sudo docker exec -it subtify ./first_run.sh --interactive --tty
  3. Open the given URL -> then Paste the redirected URL and get an Error Couldn't write token to cache at: /home/user/subtify/cache/spotipy_cache

Not enough permissions, either add the permissions to the directory on the container chmod -R 777 ./cache or create the cache directory on the host before starting the container, I noticed the container creates the directory as root that's why its not able to write to it.

Dunno why this happens, in my local env the folder gets created correctly with the correct user permission

anyways you should update to the latest release, project has been renamed today and a lot of things have been changed to the code

Aerglonus commented 1 month ago

Dunno why this happens, in my local env the folder gets created correctly with the correct user permission

It creates the directory without issues if you're not mounting it from the host https://github.com/blastbeng/spotisub/blob/442dc91dca810db99a9daeb7f22a4d2380ed2e47/docker-compose.yml#L19-L20 If you mount it either needs to be created before running the compose or change the permissions later.

It would be helpful to add creating the cache directory as a step on the Install Spotisub using Docker since not mounting it will require running the first_run.sh every time the container is rebuild.

blastbeng commented 1 month ago

Dunno why this happens, in my local env the folder gets created correctly with the correct user permission

It creates the directory without issues if you're not mounting it from the host

https://github.com/blastbeng/spotisub/blob/442dc91dca810db99a9daeb7f22a4d2380ed2e47/docker-compose.yml#L19-L20

If you mount it either needs to be created before running the compose or change the permissions later.

It would be helpful to add creating the cache directory as a step on the Install Spotisub using Docker since not mounting it will require running the first_run.sh every time the container is rebuild.

I will release a script who does:

  1. create the cache dir.
  2. pull and run the docker image
  3. execute the init script inside the container
  4. restart the docker image

That should solve this issue. Am I wrong?

TheMBeat commented 1 month ago

I think there should be an other solution. Other container have no problems.

And of course i will try the new docker compose.

blastbeng commented 1 month ago

@TheMBeat @Aerglonus

The next release will have an install script: https://github.com/blastbeng/spotisub/blob/dev/install_scripts/install_spotisub_docker.sh

This will simplify a lot the install process.

blastbeng commented 1 month ago

That's cool, but I do it by hand.

An other question is, must I use lidarr?

Look at the README, lidarr is just an option if you enable spotdl.

When spotdl enabled and lidarr enabled, songs that aren't found in your subsonic library will be download trough spotdl but only if the matching artist is found as monitored in your lidarr database.

When spotdl enabled and lidarr disabled, spotdl will download everything that is missing from your subsonic library.

So take care enabling spotdl/lidarr because if you have a lot of items in your playlists and followed artists, it will download a lot of songs!

Anyway we are going off topic now, I will leave this issue open until the next release where I will release the install script.

blastbeng commented 1 month ago

Released install script in v0.2.2

Aerglonus commented 1 month ago

The next release will have an install script: https://github.com/blastbeng/spotisub/blob/dev/install_scripts/install_spotisub_docker.sh

This will simplify a lot the install process.

Is there a reason to run the container as an user? This could be simplified by not switching to user on the build before running the entrypoint.sh and handling directory creation/permissions on the entrypoint for the cache directory or any other directory.

I can make a PR for this.

blastbeng commented 1 month ago

The next release will have an install script: https://github.com/blastbeng/spotisub/blob/dev/install_scripts/install_spotisub_docker.sh This will simplify a lot the install process.

Is there a reason to run the container as an user? This could be simplified by not switching to user on the build before running the entrypoint.sh and handling directory creation/permissions on the entrypoint for the cache directory or any other directory.

I can make a PR for this.

I was used to make my docker files doing everything as root user, but then I discovered that usually it's bad habit to do that

In that case I never had permission errors, is this what you suggest?

Anyway if you think that will solve the problem for most users, make PR and we will sort this out

EDIT: One of my other Dockerfiles

https://github.com/blastbeng/discord-tts-bot/blob/main/api/Dockerfile.api

EDIT: Look at the development branch. I am editing the Dockerfile, if you want to create a PR open it on that branch.

blastbeng commented 1 month ago

Definitively solved in https://github.com/blastbeng/spotisub/pull/43