add docker and config for fly.io

This commit is contained in:
Erik Winter 2022-09-14 16:14:18 +02:00
parent e49c3b8bdc
commit 180d92d5b7
6 changed files with 66 additions and 20 deletions

13
Dockerfile.daemon Normal file
View File

@ -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"]

View File

@ -18,7 +18,7 @@ func main() {
fmt.Println(err, "could not open config file")
os.Exit(1)
}
config := configuration.New(configFile)
config := configuration.NewFromFile(configFile)
cmd, err := command.Parse(os.Args[1:], config)
if err != nil {

View File

@ -1,7 +1,6 @@
package main
import (
"flag"
"os"
"os/signal"
"time"
@ -18,21 +17,11 @@ import (
func main() {
logger := log.New(os.Stdout)
configPath := flag.String("c", "~/.config/gte/gte.conf", "path to configuration file")
daysAhead := flag.Int("d", 6, "generate for this amount of days from now")
flag.Parse()
logger.With(log.Fields{
"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)
config := configuration.NewFromEnvironment()
cfgCopy := *config
cfgCopy.IMAPPassword = "***"
cfgCopy.SMTPPassword = "***"
logger.WithField("config", cfgCopy).Info("started")
msgStore := mstore.NewIMAP(config.IMAP())
mailSend := msend.NewSSLSMTP(config.SMTP())
@ -40,7 +29,7 @@ func main() {
disp := storage.NewDispatcher(mailSend)
inboxProc := process.NewInbox(repo)
recurProc := process.NewRecur(repo, disp, *daysAhead)
recurProc := process.NewRecur(repo, disp, config.DaysAhead)
go Run(inboxProc, recurProc, logger)

22
fly.toml Normal file
View File

@ -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

View File

@ -4,6 +4,8 @@ import (
"bufio"
"errors"
"io"
"os"
"strconv"
"strings"
"time"
@ -33,13 +35,14 @@ type Configuration struct {
ToAddress string
LocalDBPath string
DaysAhead int
}
type LocalConfiguration struct {
MinSyncInterval time.Duration
}
func New(src io.Reader) *Configuration {
func NewFromFile(src io.Reader) *Configuration {
conf := &Configuration{}
scanner := bufio.NewScanner(src)
for scanner.Scan() {
@ -81,6 +84,25 @@ func New(src io.Reader) *Configuration {
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 {
return &mstore.IMAPConfig{
IMAPURL: c.IMAPURL,

View File

@ -78,7 +78,7 @@ func TestNew(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)))
})
}
}