mirror of
https://github.com/ordinary-dev/phoenix
synced 2024-09-19 19:30:28 +05:00
Add more settings, update readme and Dockerfile
This commit is contained in:
parent
e24a3a754c
commit
37e8663ac2
2
.env
2
.env
|
@ -1,3 +1,5 @@
|
|||
P_SECRETKEY="super-secret-key"
|
||||
P_DBPATH="db.sqlite3"
|
||||
P_LOGLEVEL="debug"
|
||||
P_ENABLEGINLOGGER="true"
|
||||
P_PRODUCTION="false"
|
||||
|
|
|
@ -22,7 +22,8 @@ COPY assets ./assets
|
|||
COPY templates ./templates
|
||||
|
||||
RUN mkdir /var/lib/phoenix
|
||||
ENV PHOENIX_DB_PATH=/var/lib/phoenix/db.sqlite3
|
||||
ENV P_DBPATH="/var/lib/phoenix/db.sqlite3"
|
||||
ENV P_PRODUCTION="true"
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
|
|
|
@ -7,9 +7,13 @@ import (
|
|||
)
|
||||
|
||||
type Config struct {
|
||||
SecretKey string `required:"true"`
|
||||
DBPath string `required:"true"`
|
||||
LogLevel string `default:"warning"`
|
||||
SecretKey string `required:"true"`
|
||||
DBPath string `required:"true"`
|
||||
LogLevel string `default:"warning"`
|
||||
EnableGinLogger bool `default:"false"`
|
||||
Production bool `default:"true"`
|
||||
DefaultUsername string
|
||||
DefaultPassword string
|
||||
}
|
||||
|
||||
func GetConfig() (*Config, error) {
|
||||
|
|
10
main.go
10
main.go
|
@ -30,6 +30,16 @@ func main() {
|
|||
logrus.Fatalf("%v", err)
|
||||
}
|
||||
|
||||
// Create the first user
|
||||
if cfg.DefaultUsername != "" && cfg.DefaultPassword != "" {
|
||||
if database.CountAdmins(db) < 1 {
|
||||
_, err := database.CreateAdmin(db, cfg.DefaultUsername, cfg.DefaultPassword)
|
||||
if err != nil {
|
||||
logrus.Errorf("%v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
engine := views.GetGinEngine(cfg, db)
|
||||
engine.Run(":8080")
|
||||
}
|
||||
|
|
15
readme.md
15
readme.md
|
@ -11,7 +11,16 @@ Self-hosted start page without the extra stuff.
|
|||
|
||||
## Configuration
|
||||
Service settings can be set through environment variables.
|
||||
- `PHOENIX_DB_PATH` - path to the sqlite database.
|
||||
|
||||
| Variable | Description | Default |
|
||||
| --- | --- | --- |
|
||||
| P_DBPATH | Path to the sqlite database. | Docker: `/var/lib/phoenix/db.sqlite3` |
|
||||
| P_SECRETKEY | A long and random secret string used for authorization. | |
|
||||
| P_LOGLEVEL | Log level settings: `debug`, `info`, `warning`, `error`, `fatal` | `warning` |
|
||||
| P_ENABLEGINLOGGER | Enable gin's logging middleware. Can create a lot of logs. | `false` |
|
||||
| P_PRODUCTION | Is this instance running in production mode? | `true` |
|
||||
| P_DEFAULTUSERNAME | Data for the first user. | |
|
||||
| P_DEFAULTPASSWORD | Data for the first user. | |
|
||||
|
||||
## Docker-compose example
|
||||
```yml
|
||||
|
@ -22,6 +31,10 @@ services:
|
|||
- phoenix:/var/lib/phoenix
|
||||
ports:
|
||||
- 80:8080
|
||||
environment:
|
||||
P_SECRETKEY: "your-random-string"
|
||||
P_DEFAULTUSERNAME: "admin"
|
||||
P_DEFAULTPASSWORD: "super-password"
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
|
|
|
@ -7,7 +7,16 @@ import (
|
|||
)
|
||||
|
||||
func GetGinEngine(cfg *config.Config, db *gorm.DB) *gin.Engine {
|
||||
engine := gin.Default()
|
||||
if cfg.Production {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
|
||||
engine := gin.New()
|
||||
engine.Use(gin.Recovery())
|
||||
if cfg.EnableGinLogger {
|
||||
engine.Use(gin.Logger())
|
||||
}
|
||||
|
||||
engine.LoadHTMLGlob("templates/*")
|
||||
engine.Static("/assets", "./assets")
|
||||
|
||||
|
|
Loading…
Reference in a new issue