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

feat(BUX-420): go version and workflows update and config fix for k8s #390

Merged
merged 9 commits into from
Jan 4, 2024
7 changes: 7 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ jobs:
# a pull request then we can check out the head.
fetch-depth: 2

# GH Actions runner uses go1.20 by default, so we need to install our own version.
# https://github.com/github/codeql-action/issues/1842#issuecomment-1704398087
- name: Install Go from go.mod
uses: actions/setup-go@v5
with:
go-version-file: go.mod

# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.19
go-version-file: go.mod
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5.0.0
with:
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
# GH Actions runner uses go1.20 by default, so we need to install our own version.
# https://github.com/github/codeql-action/issues/1842#issuecomment-1704398087
- name: Install Go from go.mod
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Write go list
run: go list -json -m all > go.list
- name: Ask Nancy
Expand All @@ -38,16 +44,15 @@ jobs:
needs: [yamllint, asknancy]
strategy:
matrix:
go-version: [1.19.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v4
go-version-file: go.mod
- name: Cache code
uses: actions/cache@v3
with:
Expand Down
4 changes: 2 additions & 2 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

// main method starts everything for the BUX Server
// @title BUX: Server
// @version v0.5.16
// @version v0.8.0
// @securityDefinitions.apikey bux-auth-xpub
// @in header
// @name bux-auth-xpub
Expand Down Expand Up @@ -84,7 +84,7 @@ func main() {
txn.End()

// Listen and serve
services.Logger.Debug().Msgf("starting %s server version %s at port %s...", config.ApplicationName, config.Version, appConfig.Server.Port)
services.Logger.Debug().Msgf("starting %s server version %s at port %d...", config.ApplicationName, config.Version, appConfig.Server.Port)
appServer.Serve()

<-idleConnectionsClosed
Expand Down
181 changes: 93 additions & 88 deletions config.example.yaml
Original file line number Diff line number Diff line change
@@ -1,105 +1,110 @@
auth:
admin_key: xpub661MyMwAqRbcFrBJbKwBGCB7d3fr2SaAuXGM95BA62X41m6eW2ehRQGW4xLi9wkEXUGnQZYxVVj4PxXnyrLk7jdqvBAs1Qq9gf6ykMvjR7J
require_signing: false
scheme: xpub
signing_disabled: true
admin_key: xpub661MyMwAqRbcFrBJbKwBGCB7d3fr2SaAuXGM95BA62X41m6eW2ehRQGW4xLi9wkEXUGnQZYxVVj4PxXnyrLk7jdqvBAs1Qq9gf6ykMvjR7J
require_signing: false
scheme: xpub
signing_disabled: true
cache:
cluster:
coordinator: memory
prefix: bux_cluster_
redis: null
engine: freecache
# Prefixed with "_", because it's unused by default
_redis:
dependency_mode: true
max_active_connections: 0
max_connection_lifetime: 1m0s
max_idle_connections: 10
max_idle_timeout: 10s
url: redis://localhost:6379
use_tls: false
cluster:
coordinator: memory
prefix: bux_cluster_
redis: null
engine: freecache
# Prefixed with "_", because it's unused by default
_redis:
dependency_mode: true
max_active_connections: 0
max_connection_lifetime: 1m0s
max_idle_connections: 10
max_idle_timeout: 10s
url: redis://localhost:6379
use_tls: false
db:
datastore:
debug: false
engine: sqlite
table_prefix: xapi
# Prefixed with "_", because it's unused by default
_mongodb:
database_name: xapi
debug: false
max_connection_idle_time: 0s
max_connection_time: 0s
max_idle_connections: 0
max_open_connections: 0
table_prefix: ""
transactions: false
uri: mongodb://localhost:27017/xapi
# Prefixed with "_", because it's unused by default
_sql:
debug: false
driver: postgresql
host: localhost
max_connection_idle_time: 0s
max_connection_time: 0s
max_idle_connections: 0
max_open_connections: 0
name: xapi
password: ""
port: "5432"
replica: false
skip_initialize_with_version: true
table_prefix: ""
time_zone: UTC
tx_timeout: 10s
user: postgres
sqlite:
database_path: ./bux.db
debug: false
max_connection_idle_time: 0s
max_connection_time: 0s
max_idle_connections: 0
max_open_connections: 0
shared: true
table_prefix: ""
datastore:
debug: false
engine: sqlite
table_prefix: xapi
# Prefixed with "_", because it's unused by default
_mongodb:
database_name: xapi
debug: false
max_connection_idle_time: 0s
max_connection_time: 0s
max_idle_connections: 0
max_open_connections: 0
table_prefix: ""
transactions: false
uri: mongodb://localhost:27017/xapi
# Prefixed with "_", because it's unused by default
_sql:
debug: false
driver: postgresql
host: localhost
max_connection_idle_time: 0s
max_connection_time: 0s
max_idle_connections: 0
max_open_connections: 0
name: xapi
password: ""
port: "5432"
replica: false
skip_initialize_with_version: true
table_prefix: ""
time_zone: UTC
tx_timeout: 10s
user: postgres
sqlite:
database_path: ./bux.db
debug: false
max_connection_idle_time: 0s
max_connection_time: 0s
max_idle_connections: 0
max_open_connections: 0
shared: true
table_prefix: ""
debug: true
debug_profiling: true
disable_itc: true
# Prefixed with "_", because it's unused by default
graphql:
enabled: false
enabled: false
import_block_headers: ""
# Prefixed with "_", because it's unused by default
_new_relic:
domain_name: domain.com
enabled: false
license_key: BOGUS-LICENSE-KEY-1234567890987654321234
domain_name: domain.com
enabled: false
license_key: BOGUS-LICENSE-KEY-1234567890987654321234
nodes:
broadcast_client_apis: []
minercraft_api: mAPI
minercraft_custom_apis: []
use_mapi_fee_quotes: true
broadcast_client_apis: []
minercraft_api: mAPI
minercraft_custom_apis:
- minerid: 03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270
apis:
- token: mainnet_3af382fadbc448b15cc4133242ac2621
url: https://merchantapi.taal.com
type: mAPI
use_mapi_fee_quotes: true
# Prefixed with "_", because it's unused by default
_notifications:
enabled: false
webhook_endpoint: ""
enabled: false
webhook_endpoint: ""
paymail:
# Prefixed with "_", because it's unused by default
_beef:
pulse_auth_token: mQZQ6WmxURxWz5ch
pulse_url: http://localhost:8080/api/v1/chain/merkleroot/verify
use_beef: false
default_from_paymail: from@domain.com
default_note: bux Address Resolution
domain_validation_enabled: true
domains:
- localhost
enabled: true
sender_validation_enabled: true
# Prefixed with "_", because it's unused by default
_beef:
pulse_auth_token: mQZQ6WmxURxWz5ch
pulse_url: http://localhost:8080/api/v1/chain/merkleroot/verify
use_beef: false
default_from_paymail: from@domain.com
default_note: bux Address Resolution
domain_validation_enabled: false
domains:
- localhost
enabled: true
sender_validation_enabled: false
request_logging: true
server:
idle_timeout: 1m0s
port: "3003"
read_timeout: 15s
write_timeout: 15s
server_config:
idle_timeout: 1m0s
port: 3003
read_timeout: 15s
write_timeout: 15s
task_manager:
factory: memory
factory: memory
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type AppConfig struct {
// RequestLogging is flag for enabling logging in go-api-router.
RequestLogging bool `json:"request_logging" mapstructure:"request_logging"`
// Server is a general configuration for bux-server.
Server *ServerConfig `json:"server" mapstructure:"server"`
Server *ServerConfig `json:"server_config" mapstructure:"server_config"`
dorzepowski marked this conversation as resolved.
Show resolved Hide resolved
// TaskManager is a configuration for Task Manager in bux.
TaskManager *TaskManagerConfig `json:"task_manager" mapstructure:"task_manager"`
}
Expand Down Expand Up @@ -228,7 +228,7 @@ type ServerConfig struct {
// WriteTimeout is the maximum duration for server write timeout.
WriteTimeout time.Duration `json:"write_timeout" mapstructure:"write_timeout"`
// Port is the port that the server should use.
Port string `json:"port" mapstructure:"port"`
Port int `json:"port" mapstructure:"port"`
}

// GetUserAgent will return the outgoing user agent
Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestAppConfig_Validate(t *testing.T) {

t.Run("server - no port", func(t *testing.T) {
app, _, txn := baseTestConfig(t)
app.Server.Port = ""
app.Server.Port = 0
err := app.Validate(txn)
assert.Error(t, err)
})
Expand Down
4 changes: 2 additions & 2 deletions config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func getPaymailDefaults() *PaymailConfig {
Domains: []string{"localhost"},
DomainValidationEnabled: true,
Enabled: true,
SenderValidationEnabled: true,
SenderValidationEnabled: false,
}
}

Expand All @@ -157,6 +157,6 @@ func getServerDefaults() *ServerConfig {
IdleTimeout: 60 * time.Second,
ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second,
Port: "3003",
Port: 3003,
}
}
10 changes: 10 additions & 0 deletions config/load.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"encoding/json"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -39,6 +40,15 @@ func Load(logger *zerolog.Logger) (appConfig *AppConfig, err error) {
return nil, err
}

if appConfig.Debug {
cfg, err := json.MarshalIndent(appConfig, "", " ")
if err != nil {
logger.Error().Msg("Unable to decode App Config to json")
} else {
fmt.Printf("loaded config: %s", cfg)
}
Comment on lines +44 to +49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. as we have a struct with config, why don't you just use Printf("loaded config: %v", appConfig)?
  2. Why you're doing fmt.Printf instead of using a logger?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Because it will print it in one-liner.
  2. Because it will print it in one-liner πŸ˜„

Doing it this way, we print it as a formatted json which makes it MUCH easier to look at quickly and seeing if everything is okay. This is also shown only when when debug flag is selected. That's why I decided to make an exception here and use the standard fmt.Printf function.

}

return appConfig, nil
}

Expand Down
7 changes: 5 additions & 2 deletions config/validate_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"

validation "github.com/go-ozzo/ozzo-validation"
"github.com/go-ozzo/ozzo-validation/is"
)

// Validate checks the configuration for specific rules
Expand All @@ -20,10 +19,14 @@ func (s *ServerConfig) Validate() error {
return errors.New("Write timeout needs to be set for server configuration")
}

if s.Port < 10 || s.Port > 65535 {
return errors.New("Server port outside of bounds")
}

return validation.ValidateStruct(s,
validation.Field(&s.IdleTimeout, validation.Required),
validation.Field(&s.ReadTimeout, validation.Required),
validation.Field(&s.WriteTimeout, validation.Required),
validation.Field(&s.Port, validation.Required, is.Digit, validation.Length(2, 6)),
validation.Field(&s.Port, validation.Required),
)
}
Loading
Loading