Skip to content

Commit

Permalink
Enable persistence of sql database in container (#13)
Browse files Browse the repository at this point in the history
- Add /data folder and config for sqlite database in Dockerfile
- add /data from docker to exported volumes
- Fix UID in Dockerfile
  • Loading branch information
kekonn authored Sep 29, 2023
1 parent eb36f0b commit 6b45cb6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
9 changes: 5 additions & 4 deletions Docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN apt-get update \
&& rm -rf /var/lib/apt/lists/*

ARG APP_NAME
ARG UID=10001
ARG UID=1001
RUN adduser \
--disabled-password \
--gecos "" \
Expand All @@ -34,12 +34,11 @@ RUN adduser \
--uid "${UID}" \
appuser

RUN mkdir /config /app
RUN mkdir /config /app /data
COPY ./Docker/config.toml /config/config.toml
RUN chown ${UID}:${UID} /config/config.toml /app
RUN chown -R ${UID}:${UID} /config /app /data

ENV TZ=Etc/UTC \
APP_USER=appuser \
CONFIG=/config/config.toml \
RUST_BACKTRACE=0 \
RUST_LOG="info,sqlx::query=warn"
Expand All @@ -51,4 +50,6 @@ RUN chown -R $APP_USER:$APP_USER /app

USER appuser

VOLUME [ "/data" ]

CMD ["/app/fercord"]
3 changes: 2 additions & 1 deletion Docker/config.toml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
job_interval_min = 1
job_interval_min = 1
database_url = "sqlite:///data/fercord.db?mode=rwc"
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
A discord bot written in Rust, for personal use.

## Configuration
### When running locally/directly

You can specify the location of the config file by setting the `CONFIG` environment variable (i.e.: `CONFIG=$XDG_CONFIG_HOME/fercord/config.toml`) or if not specified we look in `.config/config.toml` in the current working directory.

Example `config.toml`:

```toml
discord_token = "your-bot-token"
database_url = "postgres://fercord:fercord@localhost/fercord"
database_url = "sqlite://fercord.db"
redis_url = "redis://localhost/"
job_interval_min = 1
shard_key = "c69b7bb6-0ca4-40da-8bad-26d9d4d2fb50"
Expand Down Expand Up @@ -38,6 +43,8 @@ This means the following environment variables HAVE to be specified in order for

If you want a different job interval, you can specify it through `FERCORD_JOB_INTERVAL_MIN`.

The sqlite database is placed in the `/data` directory and called `fercord.db`. The container exposes `/data` as a volume, so it will persist between updates etc.

### RUST_LOG

The default value for `RUST_LOG` in the container is `info,sqlx::query=warn`. You can override this, but if you choose to, please copy the value for `sqlx::query`.
Expand Down

0 comments on commit 6b45cb6

Please sign in to comment.