From 463ddc3f9dae99d2bfad734ebf3a58da2f2f0d8e Mon Sep 17 00:00:00 2001 From: Marcel <14852157+Marcel0024@users.noreply.github.com> Date: Mon, 24 Jun 2024 13:03:06 +0200 Subject: [PATCH] Create directory /data in dockerfile and point files to there Added troubleshooting --- FundaScraper/App/WebhookDB.cs | 2 -- FundaScraper/Constants.cs | 5 +++-- FundaScraper/Dockerfile | 6 ++++-- FundaScraper/FundaScraper.csproj | 2 +- README.md | 18 ++++++++++++++++-- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/FundaScraper/App/WebhookDB.cs b/FundaScraper/App/WebhookDB.cs index 136f3aa..02a17cb 100644 --- a/FundaScraper/App/WebhookDB.cs +++ b/FundaScraper/App/WebhookDB.cs @@ -46,8 +46,6 @@ private async Task SaveHistoryFile(DbModel model) { var json = JsonSerializer.Serialize(model); - Directory.CreateDirectory(Path.GetDirectoryName(WebhooksHistoryJson)!); - await File.WriteAllTextAsync(WebhooksHistoryJson, json); } } diff --git a/FundaScraper/Constants.cs b/FundaScraper/Constants.cs index 3887999..b163388 100644 --- a/FundaScraper/Constants.cs +++ b/FundaScraper/Constants.cs @@ -4,7 +4,8 @@ internal static class Constants { internal static class FileNames { - internal static string WebhooksHistoryJson = Path.Combine("/home", "app", "data", "webhooks-history.json"); - internal static string ResultsFilePath = Path.Combine("/home", "app", "data", "results.csv"); + private static string BasePath = Path.Combine("/", "data"); + internal static string WebhooksHistoryJson = Path.Combine(BasePath, "webhooks-history.json"); + internal static string ResultsFilePath = Path.Combine(BasePath, "results.csv"); } } diff --git a/FundaScraper/Dockerfile b/FundaScraper/Dockerfile index 59e2ade..a2f7b4e 100644 --- a/FundaScraper/Dockerfile +++ b/FundaScraper/Dockerfile @@ -12,9 +12,11 @@ RUN apt-get update \ ENV PUPPETEER_EXECUTABLE_PATH "/usr/bin/google-chrome-stable" +RUN mkdir -p /data +RUN chown -R app /data + USER app -RUN mkdir /home/app/data -WORKDIR /home/app +WORKDIR /app COPY ./publish . diff --git a/FundaScraper/FundaScraper.csproj b/FundaScraper/FundaScraper.csproj index 5a52c54..63300eb 100644 --- a/FundaScraper/FundaScraper.csproj +++ b/FundaScraper/FundaScraper.csproj @@ -6,7 +6,7 @@ enable enable Linux - 1.0.3 + 1.2.0 diff --git a/README.md b/README.md index 83298e1..d2ec756 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Note `--tty` and `--cap-add=SYS_ADMIN` are required. ```bash docker run --tty \ - -v /data/fundascraper:/home/app/data \ + -v /data/fundascraper:/data \ -e FUNDA_URL="https://www.funda.nl/zoeken/koop?selected_area=%5B%22amsterdam%22%5D&object_type=%5B%22house%22%5D&price=%22-450000%22" \ -e WEBHOOK_URL="http://homeassistantlocal.ip/api/webhook/123-redacted-key" \ ghcr.io/marcel0024/funda-scraper:latest @@ -43,7 +43,7 @@ services: - FUNDA_URL=https://www.funda.nl/zoeken/koop?selected_area=%5B%22amsterdam%22%5D&object_type=%5B%22house%22%5D&price=%22-450000%22 - WEBHOOK_URL=http://homeassistantlocal.ip/api/webhook/123-redacted-key volumes: - - /data/fundascraper:/home/app/data + - /data/fundascraper:/data ``` ## Environment Variables @@ -105,3 +105,17 @@ action: clickAction: "{{ trigger.json.url }}" mode: single ``` + + +## Troubleshoot/Common issues + +### UnauthorizedAccessException: Access to the path '/data/results.csv' is denied + +The app inside the container is running as non-root user. So the application is running as the predefined `app` user which has UID 64198. + +For it to be able to create files in the mounted directory, UID 64198 needs to be able to create files on the host in the `/data/fundascraper` directory (the one defined in the volume). + +You can do that by giving public write access on the host using `chmod o+w /data/fundascraper`. + +If that's too permissive, you can create a user on the host with UID 64198 and give that user group access to the directory. +