Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
remove sqlite and cgo and add mysql and postgres support (#10)
Browse files Browse the repository at this point in the history
* remove sqlite and cgo. add postgres and mysql

* add sql tests

* add dialects

* use localhost postgres at tests

* convert alarm to model

* convert alarm to model and delete old test entities

* fix error

* fix error

* fix error
  • Loading branch information
PKuebler committed Aug 6, 2020
1 parent f0fa8f3 commit 42ecb7f
Show file tree
Hide file tree
Showing 8 changed files with 311 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ before:
- go mod download
builds:
- env:
- CGO_ENABLED=1
- CGO_ENABLED=0
goos:
- linux
- windows
Expand Down
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ go:
- master

env:
- GO111MODULE=on CGO_ENABLED=1
- GO111MODULE=on CGO_ENABLED=0 DB_DIALECT=postgres DB_PATH='host=localhost port=5432 user=postgres dbname=travis_ci_test sslmode=disable password='

services:
- postgresql

before_script:
- psql -c 'create database travis_ci_test;' -U postgres

script:
- go mod download
- go test ./... # replace this with your test script
- curl -sfL https://git.io/goreleaser | sh -s -- check # check goreleaser config for deprecations

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ FROM golang:1.14 as build
WORKDIR /go/src/app
ADD . /go/src/app

RUN CGO_ENABLED=1 go build -o /go/bin/bahn-bot
RUN CGO_ENABLED=0 go build -o /go/bin/bahn-bot

# Now copy it into our base image.
FROM gcr.io/distroless/base-debian10
FROM gcr.io/distroless/base
COPY --from=build /go/bin/bahn-bot /
CMD ["/bahn-bot", "bot"]
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,21 @@ All parameters can be overwritten by ENV variable.
"key": ""
},
"database": {
"dialect": "sqlite3",
"path": ":memory:"
"dialect": "postgres",
"path": "host=myhost port=myport user=gorm dbname=gorm password=mypassword"
},
"loglevel": "trace"
}
```

- `API_ENDPOINT` marudor endpoint
- `TELEGRAM_KEY` telegram bot key from [Telegram BotFahter](https://core.telegram.org/bots#6-botfather)
- `DB_DIALECT` currently only `sqlite3`
- `DB_DIALECT` currently only `mysql` or `postgres`
- `DB_PATH` database config path.
- sqlite3
- `:memory:` inmemory database
- `./path/to/databasefile` filebased
- mysql
- `user:password@/dbname?charset=utf8&parseTime=True&loc=Local`
- postgres
- `sslmode=disable host=myhost port=myport user=gorm dbname=gorm password=mypassword`
- `LOG_LEVEL` loglevel `info`, `trace`, `warn` or `error`

## Docker Setup
Expand All @@ -63,8 +64,8 @@ services:
environment:
- API_ENDPOINT=https://marudor.de/api
- TELEGRAM_KEY=
- DB_DIALECT=sqlite3
- "DB_PATH=:memory:"
- DB_DIALECT=mysql
- "DB_PATH=user:password@/dbname?charset=utf8&parseTime=True&loc=Local"
- LOG_LEVEL=info
```

Expand All @@ -77,7 +78,6 @@ services:
## ToDo

- Add interface > telegram tests
- Delete old chat states -> notify after delete
- SQL Database Repository tests

## License
Expand Down
4 changes: 2 additions & 2 deletions config_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"key": ""
},
"database": {
"dialect": "sqlite3",
"path": ":memory:"
"dialect": "postgres",
"path": "host=postgres port=myport user=bahn-bot dbname=bahn-bot password=supersecretpassword sslmode=disable"
},
"loglevel": "trace"
}
27 changes: 25 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,28 @@ services:
bot:
build: .
volumes:
- "./data:/data"
- "./config.json:/config.json"
- "./config.json:/config.json"
restart: always
depends_on:
- postgres

postgres:
image: postgres:latest
container_name: postgres
environment:
- POSTGRES_USER=bahn-bot
- POSTGRES_PASSWORD=supersecretpassword
- POSTGRES_DB=bahn-bot
volumes:
- ./data:/var/lib/postgresql/data

# mysql:
# image: mysql:5.7
# container_name: mysql
# environment:
# - MYSQL_USER=bahn-bot
# - MYSQL_PASSWORD=supersecretpassword
# - MYSQL_DATABASE=bahn-bot
# - MYSQL_ROOT_PASSWORD=supersecretpassword
# volumes:
# - ./data:/var/lib/mysql
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package main
import (
"context"

_ "github.com/jinzhu/gorm/dialects/sqlite"
_ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/jinzhu/gorm/dialects/postgres"

"github.com/pkuebler/bahn-bot/cmd"
)
Expand Down
Loading

0 comments on commit 42ecb7f

Please sign in to comment.