Skip to content

Commit

Permalink
feat(docker): add dockerfile for goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
RobBrazier committed Dec 6, 2024
1 parent dc9533f commit 9f67976
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ archives:
- goos: windows
format: zip

dockers:
- image_templates:
- "ghcr.io/robbrazier/readflow"
extra_files:
- packaging/entrypoint.sh

# nfpms:
# - package_name: readflow
# vendor: Rob Brazier
Expand Down
1 change: 1 addition & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
go = "latest"
"ubi:go-task/task" = "latest"
"npm:gql-sdl" = "latest"
goreleaser = "latest"
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM docker.io/alpine:3
ENV READFLOW_DOCKER="1"
ENV SOURCE="database"
ENV COLUMN_CHAPTER="false"
ENV TARGETS="anilist,hardcover"

ENV DATABASE_CALIBRE="/data/metadata.db"
ENV DATABASE_CALIBREWEB="/data/app.db"
ENV CRON_SCHEDULE="@hourly"

COPY packaging/entrypoint.sh /
RUN chmod +x /entrypoint.sh && \
apk add --no-cache supercronic
COPY readflow /bin

ENTRYPOINT ["/entrypoint.sh"]

CMD ["supercronic", "-no-reap", "/tmp/crontab"]
3 changes: 3 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func init() {
func initConfig() {
configFile := config.GetConfigPath(&cfgFile)
err := config.LoadConfig(configFile)
if os.Getenv("READFLOW_DOCKER") == "1" {
err = config.LoadConfigFromEnv()
}
if err != nil {
if errors.Is(err, os.ErrNotExist) {
log.Warnf("Config file doesn't seem to exist! Please run `%s setup -c \"%s\"` to populate the configuration", internal.NAME, cfgFile)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.23.2
require (
github.com/Khan/genqlient v0.7.0
github.com/adrg/xdg v0.5.1
github.com/caarlos0/env/v11 v11.2.2
github.com/charmbracelet/bubbles v0.20.0
github.com/charmbracelet/huh v0.6.0
github.com/charmbracelet/log v0.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/caarlos0/env/v11 v11.2.2 h1:95fApNrUyueipoZN/EhA8mMxiNxrBwDa+oAZrMWl3Kg=
github.com/caarlos0/env/v11 v11.2.2/go.mod h1:JBfcdeQiBoI3Zh1QRAWfe+tpiNTmDtcCj/hHHHMx0vc=
github.com/catppuccin/go v0.2.0 h1:ktBeIrIP42b/8FGiScP9sgrWOss3lw0Z5SktRoithGA=
github.com/catppuccin/go v0.2.0/go.mod h1:8IHJuMGaUUjQM82qBrGNBv7LFq6JI3NnQCF6MOlZjpc=
github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQWD9LIutE=
Expand Down Expand Up @@ -151,8 +153,6 @@ modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4=
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
modernc.org/sortutil v1.2.0 h1:jQiD3PfS2REGJNzNCMMaLSp/wdMNieTbKX920Cqdgqc=
modernc.org/sortutil v1.2.0/go.mod h1:TKU2s7kJMf1AE84OoiGppNHJwvB753OYfNl2WRb++Ss=
modernc.org/sqlite v1.33.1 h1:trb6Z3YYoeM9eDL1O8do81kP+0ejv+YzgyFo+Gwy0nM=
modernc.org/sqlite v1.33.1/go.mod h1:pXV2xHxhzXZsgT/RtTFAPY6JJDEvOTcTdwADQCCWD4k=
modernc.org/sqlite v1.34.2 h1:J9n76TPsfYYkFkZ9Uy1QphILYifiVEwwOT7yP5b++2Y=
modernc.org/sqlite v1.34.2/go.mod h1:dnR723UrTtjKpoHCAMN0Q/gZ9MT4r+iRvIBb9umWFkU=
modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=
Expand Down
14 changes: 7 additions & 7 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ package config
type Config struct {
Columns ColumnConfig `yaml:"columns"`
Databases DatabaseConfig `yaml:"databases"`
Source string `yaml:"source"`
Targets []string `yaml:"targets"`
Source string `yaml:"source" env:"SOURCE"`
Targets []string `yaml:"targets" env:"TARGETS"`
Tokens TokenConfig `yaml:"tokens"`
}

// ColumnConfig represents the columns configuration
type ColumnConfig struct {
Chapter string `yaml:"chapter"`
Chapter string `yaml:"chapter" env:"COLUMN_CHAPTER"`
}

// DatabaseConfig represents the database paths configuration
type DatabaseConfig struct {
Calibre string `yaml:"calibre"`
CalibreWeb string `yaml:"calibreweb"`
Calibre string `yaml:"calibre" env:"DATABASE_CALIBRE"`
CalibreWeb string `yaml:"calibreweb" env:"DATABASE_CALIBREWEB"`
}

// TokenConfig represents the API tokens configuration
type TokenConfig struct {
Anilist string `yaml:"anilist"`
Hardcover string `yaml:"hardcover"`
Anilist string `yaml:"anilist" env:"TOKEN_ANILIST"`
Hardcover string `yaml:"hardcover" env:"TOKEN_HARDCOVER"`
}

var (
Expand Down
6 changes: 6 additions & 0 deletions internal/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/RobBrazier/readflow/internal"
"github.com/adrg/xdg"
"github.com/caarlos0/env/v11"
"github.com/charmbracelet/log"
"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -38,6 +39,11 @@ func GetConfigPath(override *string) string {

}

func LoadConfigFromEnv() error {
err := env.Parse(&config)
return err
}

func LoadConfig(path string) error {
log.Debug("Loading config from", "file", path)
data, err := os.ReadFile(path)
Expand Down
3 changes: 0 additions & 3 deletions internal/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ func (a *syncAction) Sync() ([]SyncResult, error) {

func (a *syncAction) processTarget(t target.SyncTarget, reads []source.BookContext, wg *sync.WaitGroup) {
defer wg.Done()
// user := t.GetCurrentUser()
// log.Debug("current user for", "target", t.GetName(), "user", user)

for _, book := range reads {
name := book.Current.BookName
log := log.With("target", t.GetName(), "book", name)
Expand Down
15 changes: 15 additions & 0 deletions packaging/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env sh

set -e

cronjob="$CRON_SCHEDULE /bin/readflow sync"
echo "$cronjob" > /tmp/crontab
chmod 644 /tmp/crontab

# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ] || [ "$1" == "sync" ]; then
set -- /bin/readflow "$@"
fi

exec "$@"

0 comments on commit 9f67976

Please sign in to comment.