Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/use up to date dependencies #23

Merged
merged 15 commits into from
Jun 24, 2024
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
43 changes: 5 additions & 38 deletions .github/.goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ builds:
goarch:
- amd64
- arm64
hooks:
post: "go run main.go update latest"
changelog:
use: git
groups:
Expand All @@ -45,7 +47,8 @@ dockers:
goos: linux
goarch: amd64
image_templates:
- "ghcr.io/{{ .Env.GITHUB_ORG }}/{{ .ProjectName }}:{{ .Version }}-amd64"
- "ghcr.io/{{ .Env.GITHUB_ORG }}/{{ .ProjectName }}:latest"
- "ghcr.io/{{ .Env.GITHUB_ORG }}/{{ .ProjectName }}:{{ .Version }}"
build_flag_templates:
- "--pull"
- "--platform=linux/amd64"
Expand All @@ -54,40 +57,4 @@ dockers:
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
extra_files:
- tzdata
- use: buildx
goos: linux
goarch: arm64
image_templates:
- "ghcr.io/{{ .Env.GITHUB_ORG }}/{{ .ProjectName }}:{{ .Version }}-arm64v8"
build_flag_templates:
- "--pull"
- "--platform=linux/arm64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
extra_files:
- tzdata
docker_manifests:
- name_template: ghcr.io/{{ .Env.GITHUB_ORG }}/{{ .ProjectName }}:{{ .Version }}
image_templates:
- ghcr.io/{{ .Env.GITHUB_ORG }}/{{ .ProjectName }}:{{ .Version }}-amd64
- ghcr.io/{{ .Env.GITHUB_ORG }}/{{ .ProjectName }}:{{ .Version }}-arm64v8
# nfpms:
# - id: packages
# maintainer:
# # Formats to be generated.
# formats:
# - deb
# - rpm
# # contents:
# # # for updstart
# # - src: path/to/local/bar.conf
# # dst: /etc/bar.conf
# # type: "config|noreplace"
# # # for logging
# # - dst: /some/dir
# # type: dir
# # file_info:
# # mode: 0700
- tzdata
9 changes: 9 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
updates:
# Enable version updates for github-actions
- package-ecosystem: "github-actions"
# Look for a `Dockerfile` in the `root` directory
directory: "/"
# Check for updates once a month
schedule:
interval: "monthly"
6 changes: 3 additions & 3 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fetch-depth: 2
- uses: actions/setup-go@v2
with:
go-version: "1.18"
go-version: "1.22"
- name: Run coverage
run: make test-ci
- name: Upload coverage to Codecov
Expand All @@ -26,10 +26,10 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.21
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest
version: latest
4 changes: 0 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ on:
- "LICENSE"
- "docs"
- "Makefile"
branches:
- "main"
tags:
- "v*"
workflow_dispatch:

permissions:
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
geo2tz
dist
release
release

coverage.*
*.zip
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ endif
test: test-all

test-all:
@go test -v $(GOPACKAGES) -coverprofile .testCoverage.txt
@go test -v $(GOPACKAGES) -race -covermode=atomic -coverprofile coverage.txt

test-coverage:
go test -mod=readonly -coverprofile=coverage.out -covermode=atomic -timeout 30s $(GOPACKAGES) && \
go tool cover -html=coverage.out

test-ci:
go run main.go update current
go test -coverprofile=coverage.txt -covermode=atomic -race -mod=readonly $(GOPACKAGES)

bench: bench-all
Expand All @@ -43,7 +48,7 @@ go.sum: go.mod

lint:
@echo "--> Running linter"
@golangci-lint run --config .github/.golangci.yaml
golangci-lint run --config .github/.golangci.yaml
@go mod verify

debug-start:
Expand All @@ -63,6 +68,6 @@ k8s-rollback:
update-tzdata:
@echo "--> Updating timzaone data"
@echo build binary
goreleaser build --single-target --config .github/.goreleaser.yaml --snapshot --clean -o dist/geo2tz
./scripts/update-tzdata.sh
goreleaser build --single-target --config .github/.goreleaser.yaml --snapshot --clean -o geo2tz
./geo2tz update latest
@echo done
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Geo2Tz

[![Build Status](https://travis-ci.com/noandrea/geo2tz.svg?branch=master)](https://travis-ci.com/noandrea/geo2tz) [![GoDoc](https://godoc.org/github.com/noandrea/geo2tz?status.svg)](https://godoc.org/github.com/noandrea/geo2tz) [![Go Report Card](https://goreportcard.com/badge/github.com/noandrea/geo2tz)](https://goreportcard.com/report/github.com/noandrea/geo2tz)
[![QA](https://github.com/noandrea/geo2tz/actions/workflows/quality.yml/badge.svg)](https://github.com/noandrea/geo2tz/actions/workflows/quality.yml) [![GoDoc](https://godoc.org/github.com/noandrea/geo2tz?status.svg)](https://godoc.org/github.com/noandrea/geo2tz) [![Go Report Card](https://goreportcard.com/badge/github.com/noandrea/geo2tz)](https://goreportcard.com/report/github.com/noandrea/geo2tz)

A self-host-able service to get the timezone given geo-coordinates (lat/long)

It does it by exposing the library from [github.com/evanoberholster/timezoneLookup](https://github.com/evanoberholster/timezoneLookup)
A self-host-able service to get the timezone given geo-coordinates (lat/lng)

Timezone data comes from [github.com/evansiroky/timezone-boundary-builder](https://github.com/evansiroky/timezone-boundary-builder) (release [2023b](https://github.com/evansiroky/timezone-boundary-builder/releases/tag/2023b))

Expand Down Expand Up @@ -217,8 +215,26 @@ spec:

## Development notes

To update the timezone database, set the version of the database in the `scripts/update-tzdata.sh` script and run:
To update the timezone database you have a few options:

1. update to the latest version

```console
geo2tz update latest
```

2. update to a specific version

```console
make update-tzdata
geo2tz update 2023b
```


the `update` command will download the timezone geojson zip and generate a version file in the `tzdata` directory, the version file is used to track the current version of the database.


## Tests and known issues

Automated tests are executed for coordinates with a precision between 1.11m (4 decimals) and 11.1m (5 decimals), the test file is `db/testdata/coordinates.json`.

Some of the location are marked with `err` since they produce incorrect results, this is due to the fact that the timezone boundaries often overlaps. If you have additional test cases that you think are relevant, please open an issue or a PR.
91 changes: 0 additions & 91 deletions cmd/build.go

This file was deleted.

18 changes: 12 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ import (
"log"
"strings"

"github.com/noandrea/geo2tz/v2/web"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/noandrea/geo2tz/v2/server"
)

var cfgFile string
var debug bool
var settings server.ConfigSchema
var settings web.ConfigSchema

type RuntimeVersion struct {
Version string
Commit string
Date string
BuiltBy string
}

// rootCmd represents the base command when called without any subcommands.
var rootCmd = &cobra.Command{
Expand All @@ -25,8 +31,8 @@ var rootCmd = &cobra.Command{

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute(v string) error {
rootCmd.Version = v
func Execute(v RuntimeVersion) error {
rootCmd.Version = v.Version

if err := initConfig(); err != nil {
return err
Expand All @@ -50,7 +56,7 @@ func initConfig() error {
viper.AddConfigPath("/etc/geo2tz")
viper.SetConfigName("config")
}
server.Defaults()
web.Defaults()
viper.SetEnvPrefix("GEO2TZ")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv() // read in environment variables that match
Expand Down
13 changes: 9 additions & 4 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/spf13/cobra"

"github.com/noandrea/geo2tz/v2/server"
"github.com/noandrea/geo2tz/v2/web"
)

// startCmd represents the start command.
Expand All @@ -33,10 +33,15 @@ func start(*cobra.Command, []string) {
\_____|\___|\___/____|\__/___| version %s
`, rootCmd.Version)
// Start server
server, err := web.NewServer(settings)
if err != nil {
log.Println("Error creating the server ", err)
os.Exit(1)
}
go func() {
if err := server.Start(settings); err != nil {
if err = server.Start(); err != nil {
log.Println("Error starting the server ", err)
return
os.Exit(1)
}
}()

Expand All @@ -46,7 +51,7 @@ func start(*cobra.Command, []string) {
quit := make(chan os.Signal, signalChannelLength)
signal.Notify(quit, os.Interrupt)
<-quit
if err := server.Teardown(); err != nil {
if err = server.Teardown(); err != nil {
log.Println("error stopping server: ", err)
}
fmt.Print("Goodbye")
Expand Down
Loading
Loading