Skip to content

Commit 10cd540

Browse files
authored
Add update checker feature (#123)
* Add update chcker feature * Add option to disable update check
1 parent c3d0cc1 commit 10cd540

File tree

7 files changed

+53
-7
lines changed

7 files changed

+53
-7
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog
22

3+
## [v5.5.0](https://github.com/containeroo/SyncFlaer/tree/v5.5.0) (2022-05-02)
4+
5+
[All Commits](https://github.com/containeroo/SyncFlaer/compare/v5.4.2...v5.5.0)
6+
7+
**New features:**
8+
9+
- Added update checker. Can be disabled by setting `skipUpdateCheck` to `true`.
10+
11+
**Dependencies:**
12+
13+
- Bump several dependencies
14+
315
## [v5.4.2](https://github.com/containeroo/SyncFlaer/tree/v5.4.2) (2022-03-22)
416

517
[All Commits](https://github.com/containeroo/SyncFlaer/compare/v5.4.1...v5.4.2)

README.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
Synchronize Traefik host rules and/or Kubernetes Ingresses with Cloudflare®.
44

5-
![Docker Image Version (latest semver)](https://img.shields.io/docker/v/containeroo/syncflaer?sort=semver)
6-
![Docker Pulls](https://img.shields.io/docker/pulls/containeroo/syncflaer)
7-
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/containeroo/syncflaer)
8-
95
## Why?
106

117
- Dynamically create, update or delete Cloudflare® DNS records based on Traefik http rules and/or Kubernetes Ingresses (apiVersion: networking.k8s.io/v1)
@@ -163,6 +159,7 @@ If not specified, the following defaults apply:
163159

164160
| Name | Default Value |
165161
|--------------------------------|------------------------------------------------------------------------------------------------------------------------------------------|
162+
| `skipUpdateCheck` | `false` |
166163
| `ipProviders` | `["https://ifconfig.me/ip", "https://ipecho.net/plain", "https://myip.is/ip", "https://checkip.amazonaws.com", "https://api.ipify.org"]` |
167164
| `kubernetes.enabled` | `false` |
168165
| `managedRootRecord` | `true` |

cmd/syncflaer/main.go

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56
"github.com/cloudflare/cloudflare-go"
67
"github.com/containeroo/syncflaer/internal/kube"
8+
"github.com/google/go-github/v44/github"
79
"os"
810
"strconv"
911

@@ -12,7 +14,21 @@ import (
1214
log "github.com/sirupsen/logrus"
1315
)
1416

15-
const version string = "5.4.2"
17+
const version string = "5.5.0"
18+
19+
var latestVersion string
20+
21+
func checkVersionUpdate() {
22+
githubClient := github.NewClient(nil)
23+
latestRelease, _, err := githubClient.Repositories.GetLatestRelease(context.Background(), "containeroo", "syncflaer")
24+
if err != nil {
25+
log.Errorf("Failed to get latest release: %s", err)
26+
return
27+
}
28+
if latestRelease.GetTagName() != fmt.Sprintf("v%s", version) {
29+
latestVersion = latestRelease.GetTagName()
30+
}
31+
}
1632

1733
func main() {
1834
log.SetOutput(os.Stdout)
@@ -40,6 +56,10 @@ func main() {
4056

4157
config := internal.GetConfig(configFilePath)
4258

59+
if !*config.SkipUpdateCheck {
60+
go checkVersionUpdate()
61+
}
62+
4363
cf := internal.SetupCloudflareClient(&config.Cloudflare.APIToken)
4464
zoneIDs := internal.CreateCloudflareZoneMap(&config.Cloudflare.ZoneNames, cf)
4565
currentIP := internal.GetCurrentIP(&config.IPProviders)
@@ -109,4 +129,8 @@ func main() {
109129
}
110130

111131
slackHandler.SendSlackMessage(config)
132+
133+
if latestVersion != "" {
134+
log.Infof("New version available: %s, download here: https://github.com/containeroo/syncflaer/releases/tag/%s", latestVersion, latestVersion)
135+
}
112136
}

configs/config.yml

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
---
2+
# enable or disable update check
3+
skipUpdateCheck: false
4+
25
# a list of services that return the public IP
36
ipProviders:
47
- https://ifconfig.me/ip

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/containeroo/syncflaer
33
go 1.18
44

55
require (
6+
github.com/google/go-github/v44 v44.0.0
67
github.com/cloudflare/cloudflare-go v0.38.0
78
github.com/sirupsen/logrus v1.8.1
89
github.com/slack-go/slack v0.10.3

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,8 @@ github.com/google/go-containerregistry v0.0.0-20191015185424-71da34e4d9b3/go.mod
667667
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
668668
github.com/google/go-github/v28 v28.1.1/go.mod h1:bsqJWQX05omyWVmc00nEUql9mhQyv38lDZ8kPZcQVoM=
669669
github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI=
670+
github.com/google/go-github/v44 v44.0.0 h1:1Lfk2mhM7pTWqwGC6Ft16S3c2LBw8DLcw9TOhYoQ9zE=
671+
github.com/google/go-github/v44 v44.0.0/go.mod h1:CqZYQRxOcb81M+ufZB7duWNS0lFfas/r7cEAKpLBYww=
670672
github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
671673
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
672674
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=

internal/config.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import (
1212
)
1313

1414
type Configuration struct {
15-
IPProviders []string `yaml:"ipProviders"`
16-
Notifications struct {
15+
SkipUpdateCheck *bool `yaml:"skipUpdateCheck"`
16+
IPProviders []string `yaml:"ipProviders"`
17+
Notifications struct {
1718
Slack struct {
1819
WebhookURL string `yaml:"webhookURL"`
1920
Username string `yaml:"username"`
@@ -107,6 +108,7 @@ func GetConfig(configFilePath string) *Configuration {
107108

108109
// Set default values
109110
trueVar := true
111+
falseVar := false
110112
if config.ManagedRootRecord == nil {
111113
config.ManagedRootRecord = &trueVar
112114
log.Debugf("ManagedRootRecord is not set, defaulting to %t", *config.ManagedRootRecord)
@@ -138,6 +140,11 @@ func GetConfig(configFilePath string) *Configuration {
138140
log.Debugf("IP providers is empty, defaulting to %s", strings.Join(config.IPProviders, ", "))
139141
}
140142

143+
if config.SkipUpdateCheck == nil {
144+
config.SkipUpdateCheck = &falseVar
145+
log.Debugf("SkipUpdateCheck is not set, defaulting to %t", *config.SkipUpdateCheck)
146+
}
147+
141148
if config.Notifications.Slack.Username == "" {
142149
config.Notifications.Slack.Username = "SyncFlaer"
143150
log.Debugf("Slack username is empty, defaulting to %s", config.Notifications.Slack.Username)

0 commit comments

Comments
 (0)