Skip to content

Commit

Permalink
Create directory /data in dockerfile and point files to there
Browse files Browse the repository at this point in the history
Added troubleshooting
  • Loading branch information
Marcel0024 committed Jun 24, 2024
1 parent d2a42ff commit 463ddc3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
2 changes: 0 additions & 2 deletions FundaScraper/App/WebhookDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
5 changes: 3 additions & 2 deletions FundaScraper/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
6 changes: 4 additions & 2 deletions FundaScraper/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 .

Expand Down
2 changes: 1 addition & 1 deletion FundaScraper/FundaScraper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<Version>1.0.3</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.

0 comments on commit 463ddc3

Please sign in to comment.