rr- / szurubooru

Image board engine, Danbooru-style.
GNU General Public License v3.0
704 stars 178 forks source link

Unable to upload: PermissionError: [Errno 13] Permission denied: '/data/temporary-uploads' #216

Closed wychwitch closed 5 years ago

wychwitch commented 5 years ago

Hello! I'm sorry for always posting on here but this time I'm extremely close to getting this working.

I recently gave up trying to run this on my raspberry pi 1 and decided to test it on my pi 3, and after configuring everything for armv7 it finally worked! However, I'm running into a strange permission error.

Here's the full stack trace of an error, and this pops up every time I try to upload a picture. ``` client_1 | 2018/12/27 15:19:56 [warn] 18#18: *1 a client request body is buffered to a temporary file /var/tmp/nginx/client_body/0000000001, client: 192.168.1.9, server: , request: "POST /api/uploads HTTP/1.1", host: "192.168.1.28:8080", referrer: "http://192.168.1.28:8080/upload" api_1 | [2018-12-27 15:19:57] szurubooru.middleware.request_logger POST /uploads (user=Testy-chan, queries=1) api_1 | [2018-12-27 15:19:57] waitress Exception when serving /uploads api_1 | Traceback (most recent call last): api_1 | File "/usr/local/lib/python3.6/site-packages/waitress/channel.py", line 338, in service api_1 | task.service() api_1 | File "/usr/local/lib/python3.6/site-packages/waitress/task.py", line 169, in service api_1 | self.execute() api_1 | File "/usr/local/lib/python3.6/site-packages/waitress/task.py", line 399, in execute api_1 | app_iter = self.channel.server.application(env, start_response) api_1 | File "/opt/app/szurubooru/rest/app.py", line 99, in application api_1 | response = handler(ctx, match.groupdict()) api_1 | File "/opt/app/szurubooru/api/upload_api.py", line 11, in create_temporary_file api_1 | token = file_uploads.save(content) api_1 | File "/opt/app/szurubooru/func/file_uploads.py", line 29, in save api_1 | files.save(path, content) api_1 | File "/opt/app/szurubooru/func/files.py", line 40, in save api_1 | os.makedirs(os.path.dirname(full_path), exist_ok=True) api_1 | File "/usr/local/lib/python3.6/os.py", line 220, in makedirs api_1 | mkdir(name, mode) api_1 | PermissionError: [Errno 13] Permission denied: '/data/temporary-uploads' ```
an image of the site-side error, in case that is needed as well.

My first instinct is to simply run `chmod -R 777 /data/` to get it working, however the only place I could see was to put it under the VOLUME line in the server/Dockerfile, and it didn't work. Here is my hardware: ``` OS: HypriotOS (v2.0.1) [Raspbian Stretch] Hardware: Raspberry Pi 3 (ARMv7) ``` and in case you need it, here are all my modified config files:

client/Dockerfile ``` FROM arm32v7/node:9 as builder WORKDIR /opt/app COPY package.json ./ RUN npm install COPY . ./ ARG BUILD_INFO="docker-latest" ARG CLIENT_BUILD_ARGS="" RUN BASE_URL="__BASEURL__" node build.js --gzip ${CLIENT_BUILD_ARGS} FROM tobi312/rpi-nginx:alpine WORKDIR /var/www RUN \ # Create init file echo "#!/bin/sh" >> /init && \ echo 'sed -i "s|__BACKEND__|${BACKEND_HOST}|" /etc/nginx/nginx.conf' >> /ini t && \ echo 'sed -i "s|__BASEURL__|${BASE_URL:-/}|g" /var/www/index.htm /var/www/ma nifest.json' >> /init && \ echo 'exec nginx' >> /init && \ chmod a+x /init CMD ["/init"] VOLUME ["/data"] COPY nginx.conf.docker /etc/nginx/nginx.conf COPY --from=builder /opt/app/public/ . ```
server/Dockerfile ``` FROM scratch as approot WORKDIR /opt/app COPY alembic.ini wait-for-es generate-thumb ./ COPY szurubooru/ ./szurubooru/ COPY config.yaml.dist ./ FROM python:3.6-slim WORKDIR /opt/app ARG PUID=1000 ARG PGID=1000 ARG PORT=6666 RUN \ # Set users mkdir -p /opt/app /data && \ groupadd -g ${PGID} app && \ useradd -d /opt/app -M -c '' -g app -r -u ${PUID} app && \ chown -R app:app /opt/app /data && \ # Create init file echo "#!/bin/sh" >> /init && \ echo "set -e" >> /init && \ echo "cd /opt/app" >> /init && \ echo "./wait-for-es" >> /init && \ echo "alembic upgrade head" >> /init && \ echo "exec waitress-serve --port ${PORT} szurubooru.facade:app" \ >> /init && \ chmod a+x /init && \ # Install ffmpeg apt-get -yqq update && \ apt-get -yq install --no-install-recommends ffmpeg libpq-dev make gcc libffi -dev zlib1g-dev libjpeg-dev libtiff-dev libfreetype6-dev liblcms2-dev libwebp-de v tcl-dev && \ rm -rf /var/lib/apt/lists/* && \ # Install waitress pip3 install --no-cache-dir waitress COPY --chown=app:app requirements.txt ./requirements.txt RUN pip3 install --no-cache-dir -r ./requirements.txt # done to minimize number of layers in final image COPY --chown=app:app --from=approot / / VOLUME ["/data/"] EXPOSE ${PORT} USER app CMD ["/init"] ```
docker-compose.yaml ``` ## Example Docker Compose configuration ## ## Use this as a template to set up docker-compose, or as guide to set up other ## orchestration services version: '2' services: api: build: context: ./server depends_on: - sql - elasticsearch environment: ## These should be the names of the dependent containers listed above, ## or FQDNs/IP addresses if these services are running outside of Docker POSTGRES_HOST: sql ESEARCH_HOST: elasticsearch ## Credentials for database: POSTGRES_USER: szuru POSTGRES_PASSWORD: [Password} ## Commented Values are Default: #POSTGRES_DB: defaults to same as POSTGRES_USER #POSTGRES_PORT: 5432 #ESEARCH_PORT: 9200 #ESEARCH_INDEX: szurubooru #LOG_SQL: 0 (1 for verbose SQL logs) volumes: - "${MOUNT_DATA}:/data" - "./server/config.yaml:/opt/app/config.yaml" client: build: context: ./client args: BUILD_INFO: depends_on: - api environment: BACKEND_HOST: api volumes: - "${MOUNT_DATA}:/data:ro" ports: - "${PORT}:80" sql: image: postgres:alpine restart: unless-stopped environment: POSTGRES_USER: szuru POSTGRES_PASSWORD: [password] volumes: - "${MOUNT_SQL}:/var/lib/postgresql/data" elasticsearch: image: ind3x/rpi-elasticsearch environment: ## Specifies the Java heap size used ## Read ## https://www.elastic.co/guide/en/elasticsearch/reference/current/docker .html ## for more info ES_JAVA_OPTS: -Xms512m -Xmx512m volumes: - index:/usr/share/elasticsearch/data volumes: index: # Scratch space for ElasticSearch index, will be rebuilt if lost ```
sgsunder commented 5 years ago

You need to chown -R 1000:1000 the mountpoint for the data directory ($MOUNT_DATA in .env), but you need to do this on the host machine, not inside the container

wychwitch commented 5 years ago

Yep that was it! Thank you so much for all of your help, it works flawlessly now!

neobooru commented 4 years ago

I guess it is documented on the wiki (https://github.com/rr-/szurubooru/wiki/Common-errors), but I too didn't know that we had a wiki. Maybe it'd be a good idea to move all documentation to either the doc/ folder or to the wiki?