Merge branch 'docker'
This commit is contained in:
commit
63ec3010c5
|
@ -0,0 +1,13 @@
|
||||||
|
FROM golang:1.18-alpine
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY go.mod ./
|
||||||
|
COPY go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
ADD . .
|
||||||
|
|
||||||
|
RUN go build -o /gte-daemon ./cmd/daemon/service.go
|
||||||
|
|
||||||
|
CMD ["/gte-daemon"]
|
|
@ -18,7 +18,7 @@ func main() {
|
||||||
fmt.Println(err, "could not open config file")
|
fmt.Println(err, "could not open config file")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
config := configuration.New(configFile)
|
config := configuration.NewFromFile(configFile)
|
||||||
|
|
||||||
cmd, err := command.Parse(os.Args[1:], config)
|
cmd, err := command.Parse(os.Args[1:], config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"time"
|
"time"
|
||||||
|
@ -18,21 +17,11 @@ import (
|
||||||
func main() {
|
func main() {
|
||||||
logger := log.New(os.Stdout)
|
logger := log.New(os.Stdout)
|
||||||
|
|
||||||
configPath := flag.String("c", "~/.config/gte/gte.conf", "path to configuration file")
|
config := configuration.NewFromEnvironment()
|
||||||
daysAhead := flag.Int("d", 6, "generate for this amount of days from now")
|
cfgCopy := *config
|
||||||
flag.Parse()
|
cfgCopy.IMAPPassword = "***"
|
||||||
|
cfgCopy.SMTPPassword = "***"
|
||||||
logger.With(log.Fields{
|
logger.WithField("config", cfgCopy).Info("started")
|
||||||
"config": *configPath,
|
|
||||||
"daysAhead": *daysAhead,
|
|
||||||
}).Info("started")
|
|
||||||
|
|
||||||
configFile, err := os.Open(*configPath)
|
|
||||||
if err != nil {
|
|
||||||
logger.WithErr(err).Error("could not open config file")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
config := configuration.New(configFile)
|
|
||||||
|
|
||||||
msgStore := mstore.NewIMAP(config.IMAP())
|
msgStore := mstore.NewIMAP(config.IMAP())
|
||||||
mailSend := msend.NewSSLSMTP(config.SMTP())
|
mailSend := msend.NewSSLSMTP(config.SMTP())
|
||||||
|
@ -40,7 +29,7 @@ func main() {
|
||||||
disp := storage.NewDispatcher(mailSend)
|
disp := storage.NewDispatcher(mailSend)
|
||||||
|
|
||||||
inboxProc := process.NewInbox(repo)
|
inboxProc := process.NewInbox(repo)
|
||||||
recurProc := process.NewRecur(repo, disp, *daysAhead)
|
recurProc := process.NewRecur(repo, disp, config.DaysAhead)
|
||||||
|
|
||||||
go Run(inboxProc, recurProc, logger)
|
go Run(inboxProc, recurProc, logger)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
# fly.toml file generated for gte-daemon on 2022-09-14T15:53:30+02:00
|
||||||
|
|
||||||
|
app = "gte-daemon"
|
||||||
|
kill_signal = "SIGINT"
|
||||||
|
kill_timeout = 5
|
||||||
|
processes = []
|
||||||
|
|
||||||
|
[build]
|
||||||
|
dockerfile = "Dockerfile.daemon"
|
||||||
|
|
||||||
|
[env]
|
||||||
|
IMAP_URL = "imap.fastmail.com:993"
|
||||||
|
IMAP_FOLDER_PREFIX = "GTE/"
|
||||||
|
SMTP_URL = "smtp.fastmail.com:465"
|
||||||
|
GTE_TO_NAME = "gte"
|
||||||
|
GTE_FROM_NAME = "gte"
|
||||||
|
GTE_DAYS_AHEAD = 6
|
||||||
|
|
||||||
|
[experimental]
|
||||||
|
allowed_public_ports = []
|
||||||
|
auto_rollback = true
|
||||||
|
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -33,13 +35,14 @@ type Configuration struct {
|
||||||
ToAddress string
|
ToAddress string
|
||||||
|
|
||||||
LocalDBPath string
|
LocalDBPath string
|
||||||
|
DaysAhead int
|
||||||
}
|
}
|
||||||
|
|
||||||
type LocalConfiguration struct {
|
type LocalConfiguration struct {
|
||||||
MinSyncInterval time.Duration
|
MinSyncInterval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(src io.Reader) *Configuration {
|
func NewFromFile(src io.Reader) *Configuration {
|
||||||
conf := &Configuration{}
|
conf := &Configuration{}
|
||||||
scanner := bufio.NewScanner(src)
|
scanner := bufio.NewScanner(src)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
|
@ -81,6 +84,25 @@ func New(src io.Reader) *Configuration {
|
||||||
return conf
|
return conf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewFromEnvironment() *Configuration {
|
||||||
|
days, _ := strconv.Atoi(os.Getenv("GTE_DAYS_AHEAD"))
|
||||||
|
|
||||||
|
return &Configuration{
|
||||||
|
IMAPURL: os.Getenv("IMAP_URL"),
|
||||||
|
IMAPUsername: os.Getenv("IMAP_USER"),
|
||||||
|
IMAPPassword: os.Getenv("IMAP_PASSWORD"),
|
||||||
|
IMAPFolderPrefix: os.Getenv("IMAP_FOLDER_PREFIX"),
|
||||||
|
SMTPURL: os.Getenv("SMTP_URL"),
|
||||||
|
SMTPUsername: os.Getenv("SMTP_USER"),
|
||||||
|
SMTPPassword: os.Getenv("SMTP_PASSWORD"),
|
||||||
|
ToName: os.Getenv("GTE_TO_NAME"),
|
||||||
|
ToAddress: os.Getenv("GTE_TO_ADDRESS"),
|
||||||
|
FromName: os.Getenv("GTE_FROM_NAME"),
|
||||||
|
FromAddress: os.Getenv("GTE_FROM_ADDRESS"),
|
||||||
|
DaysAhead: days,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Configuration) IMAP() *mstore.IMAPConfig {
|
func (c *Configuration) IMAP() *mstore.IMAPConfig {
|
||||||
return &mstore.IMAPConfig{
|
return &mstore.IMAPConfig{
|
||||||
IMAPURL: c.IMAPURL,
|
IMAPURL: c.IMAPURL,
|
||||||
|
|
|
@ -78,7 +78,7 @@ func TestNew(t *testing.T) {
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
test.Equals(t, tc.exp, configuration.New(strings.NewReader(tc.source)))
|
test.Equals(t, tc.exp, configuration.NewFromFile(strings.NewReader(tc.source)))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue