Skip to content
This repository has been archived by the owner on Dec 26, 2024. It is now read-only.

feat: add update command #72

Merged
merged 5 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: '1.21'
cache: true

- name: Test
Expand All @@ -44,7 +44,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: '1.21'
cache: true

- name: Run GoReleaser build
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# build app
FROM golang:1.19-alpine3.16 AS app-builder
FROM golang:1.21-alpine3.19 AS app-builder

ARG VERSION=dev
ARG REVISION=dev
Expand Down Expand Up @@ -34,7 +34,6 @@ VOLUME ["${CONFIG_DIR}"]
# install packages
RUN apk add --no-cache tzdata shadow bash curl wget jq grep sed coreutils findutils unzip p7zip ca-certificates


COPY --from=app-builder /src/bin/omegabrr /usr/bin/

# make folders
Expand Down
24 changes: 24 additions & 0 deletions cmd/omegabrr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"github.com/autobrr/omegabrr/internal/processor"
"github.com/autobrr/omegabrr/internal/scheduler"

"github.com/blang/semver"
"github.com/rhysd/go-github-selfupdate/selfupdate"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/rs/zerolog/pkgerrors"
Expand All @@ -41,6 +43,7 @@ Commands:
run Run omegabrr service on schedule
generate-token Generate an API Token (optionally call with --length <number>)
version Print version info
update Update omegabrr to latest version.
help Show this help message

Flags:
Expand Down Expand Up @@ -128,6 +131,27 @@ func main() {
}
fmt.Printf("Latest release: %v\n", rel.TagName)

case "update":
v, err := semver.ParseTolerant(version)
if err != nil {
log.Error().Err(err).Msg("could not parse version")
return
}

latest, err := selfupdate.UpdateSelf(v, "autobrr/omegabrr")
if err != nil {
log.Error().Err(err).Msg("Binary update failed")
return
}

if latest.Version.Equals(v) {
// latest version is the same as current version. It means current binary is up-to-date.
log.Info().Msgf("Current binary is the latest version: %s", version)
} else {
log.Info().Msgf("Successfully updated to version: %s", latest.Version)
}
break

case "generate-token":
key, err := apitoken.GenerateToken(*length)
if err != nil {
Expand Down
14 changes: 13 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
module github.com/autobrr/omegabrr

go 1.19
go 1.21

require (
github.com/blang/semver v3.5.1+incompatible
github.com/fatih/color v1.9.0
github.com/go-chi/chi/v5 v5.0.8
github.com/go-chi/render v1.0.2
github.com/knadh/koanf v1.5.0
github.com/pkg/errors v0.9.1
github.com/rhysd/go-github-selfupdate v1.2.3
github.com/robfig/cron/v3 v3.0.1
github.com/rs/zerolog v1.29.0
github.com/spf13/pflag v1.0.5
Expand All @@ -19,13 +21,23 @@ require (
github.com/ajg/form v1.5.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-github/v30 v30.1.0 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/tcnksm/go-gitconfig v0.1.2 // indirect
github.com/ulikunitz/xz v0.5.9 // indirect
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
golang.org/x/sys v0.14.0 // indirect
google.golang.org/appengine v1.4.0 // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading