Skip to content

Commit

Permalink
Using environment variables in Dockerfile to configure run parameters #2
Browse files Browse the repository at this point in the history
  • Loading branch information
strombringer committed Sep 22, 2024
1 parent 86cd77d commit 2fa1a98
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ RUN apk add poppler-utils
ENV PATH="/opt/venv/bin:$PATH"
COPY process_timesheet.py /app/

CMD ["sh", "-c", "for f in /data/*.pdf; do pdftotext -layout \"$f\" - | python ./process_timesheet.py; done"]
ENV TIMESHEET_QUOTA="70"
ENV TIMESHEET_DATEFORMAT="%d.%m.%Y"
ENV TIMESHEET_FORMAT="text"

CMD ["sh", "-c", "for f in /data/*.pdf; do pdftotext -layout \"$f\" - | python ./process_timesheet.py -q ${TIMESHEET_QUOTA} -d ${TIMESHEET_DATEFORMAT} -f ${TIMESHEET_FORMAT}; done"]
30 changes: 24 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,31 @@ docker run -t -v ${pwd}:/data strombringer/timesheet

The `-t` parameter is only needed for the highlighting of the current home office quota. Skip it, if you don't need that.

#### Parameters (WIP - currently only usable directly with the Python script)
#### Parameters

|Name|Default|Description|
|--|--|--|
| quota | 70 | Home Office quota |
| dateformat | %d.%m.%Y | Date format of the dates in the first line of the input files (e.g. 01.07.2024|
| format | text \| json | text = nicely formatted report table, json = all values of the report as a json document|
| Name | Python Shortcut | Environment Variable (Docker) | Default | Description |
|--|--|--|--|--|
| -quota | -q | TIMESHEET_QUOTA | 70 | Home Office quota |
| -dateformat | -d | TIMESHEET_DATEFORMAT | %d.%m.%Y | Date format of the dates in the first line of the input files (e.g. 01.07.2024|
| -format | -f | TIMESHEET_FORMAT |text \| json | text = nicely formatted report table, json = all values of the report as a json document|

Use the keys from `Name` or `Python Shortcut` as arguments when calling the Python script directly:

```bash
cat output.txt | python process_timesheet.py -f json -quota 50 | jq .
```

or environment variables when using the Docker container

```bash
docker run -t -v $(pwd)/data:/data -e TIMESHEET_QUOTA=50 timesheet
```

or an environment file (see `config.env.tpl`) with Docker

```bash
docker run -t -v $(pwd)/data:/data --env-file config.env timesheet
```

## Contributing

Expand Down
3 changes: 3 additions & 0 deletions config.env.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
TIMESHEET_QUOTA=70
TIMESHEET_DATEFORMAT=%d.%m.%Y
TIMESHEET_FORMAT=text

0 comments on commit 2fa1a98

Please sign in to comment.