Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add postgres docker-compose file #308

Merged
merged 4 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ or use docker compose
mkdir -p /opt/workout-tracker
cd /opt/workout-tracker

# Download the compose.yaml
curl https://raw.githubusercontent.com/jovandeginste/workout-tracker/master/compose.yaml --output compose.yaml
# Download the docker compose file (sqlite or postgres)
curl https://raw.githubusercontent.com/jovandeginste/workout-tracker/master/docker-compose.sqlite.yaml --output docker-compose.yaml # or
curl https://raw.githubusercontent.com/jovandeginste/workout-tracker/master/docker-compose.postgres.yaml --output docker-compose.yaml

# Start the server
docker compose up -d
```
> **_NOTE:_** If using postgres, additional environment variables have to be set before running. See [postgres configuration](#postgres) for details.

### Natively

Expand Down Expand Up @@ -250,6 +252,20 @@ If no users are in the database (eg. when starting with an empty database), a
default `admin` user is created with password `admin`. You should change this
password in a production environment.

### <a name="postgres"></a>Postgres

If postgres is used as database, following environment variables have to be set **before** running `docker compose`:
```bash
export DB_USER=wt
export DB_PASSWORD=change-me
export DB_NAME=wt
docker compose -f docker-compose.postgres.yaml up

# or:

DB_USER=wt DB_PASSWORD=change-me DB_NAME=wt docker compose -f docker-compose.postgres.yaml up
```

## API usage

The API is documented using
Expand Down
52 changes: 52 additions & 0 deletions docker-compose.postgres.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
services:
workout-tracker:
image: ghcr.io/jovandeginste/workout-tracker:master
container_name: wt-app
restart: unless-stopped
ports:
# Host Port:Container Port
- 8080:8080
networks:
- workout-tracker
environment:
## Neccessary parameters for postgres
- WT_DATABASE_DRIVER=postgres
- WT_DSN=host=db user=$DB_USER password=$DB_PASSWORD dbname=$DB_NAME port=5432 sslmode=disable TimeZone=Europe/Vienna
## Additional (optional) parameters
# - WT_BIND=[::]:8080
# - WT_LOGGING=true
# - WT_DEBUG=true
# - WT_REGISTRATION_DISABLED=true
# - WT_SOCIALS_DISABLED=true
# - WT_REGISTRATION_DISABLED=true
# - WT_SOCIALS_DISABLED=true
# - WT_JWT_ENCRYPTION_KEY=my-secret-key
depends_on:
db:
condition: service_healthy

db:
image: postgres:16-alpine
container_name: wt-db
restart: unless-stopped
shm_size: 128mb
volumes:
# Store database files in a local directory.
- ./data:/var/lib/postgresql/data
networks:
- workout-tracker
healthcheck:
test: ["CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"]
interval: 5s
timeout: 5s
retries: 5
environment:
# Env parameters DB_USER, DB_PASSWORD and DB_NAME have to be set before running docker-compose!
- POSTGRES_USER=$DB_USER
- POSTGRES_PASSWORD=$DB_PASSWORD
- POSTGRES_DB=$DB_NAME
- PGUSER=$DB_USER

networks:
workout-tracker:
external: false
3 changes: 2 additions & 1 deletion compose.yaml → docker-compose.sqlite.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
version: "3.8"
services:
workout-tracker:
image: ghcr.io/jovandeginste/workout-tracker:master
container_name: wt-app
restart: unless-stopped
ports:
# Host Port:Container Port
- 8080:8080
volumes:
# Mount local directory for sqlite database
- ./data:/data
environment:
- WT_JWT_ENCRYPTION_KEY=my-secret-key
Loading