diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 1ac1d349..5eb47332 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -6,7 +6,7 @@ before: builds: - id: linux - binary: retro_aim_server + binary: bin/retro_aim_server goos: - linux goarch: @@ -21,7 +21,7 @@ builds: {{- if eq .Arch "amd64"}}CC=x86_64-linux-gnu-gcc{{- end }} {{- if eq .Arch "arm"}}CC=arm-linux-gnueabihf-gcc{{- end }} - id: macos - binary: retro_aim_server + binary: bin/retro_aim_server goos: - darwin goarch: @@ -34,7 +34,7 @@ builds: {{- if eq .Arch "amd64"}}CC=o64-clang{{- end }} {{- if eq .Arch "arm64"}}CC=oa64-clang{{- end }} - id: windows - binary: retro_aim_server + binary: bin/retro_aim_server goos: - windows goarch: diff --git a/Makefile b/Makefile index 93671ba4..8d251912 100644 --- a/Makefile +++ b/Makefile @@ -10,13 +10,9 @@ DOCKER_RUN := @docker run \ --workdir /go/src/retro-aim-server \ $(DOCKER_IMAGE_TAG) -.PHONY: release -release: - $(DOCKER_RUN) --clean - -.PHONY: release-dry-run -release-dry-run: - $(DOCKER_RUN) --clean --skip=validate --skip=publish +.PHONY: config +config: + go generate ./config .PHONY: goreleaser-docker goreleaser-docker: @@ -25,4 +21,12 @@ goreleaser-docker: --build-arg GO_RELEASER_CROSS_VERSION=$(GO_RELEASER_CROSS_VERSION) \ --file Dockerfile.goreleaser \ --tag $(DOCKER_IMAGE_TAG) \ - . \ No newline at end of file + . + +.PHONY: release +release: + $(DOCKER_RUN) --clean + +.PHONY: release-dry-run +release-dry-run: + $(DOCKER_RUN) --clean --skip=validate --skip=publish \ No newline at end of file diff --git a/cmd/config_generator/main.go b/cmd/config_generator/main.go index bf4fe68a..66b9300c 100644 --- a/cmd/config_generator/main.go +++ b/cmd/config_generator/main.go @@ -60,7 +60,7 @@ func main() { } varName := field.Tag.Get("envconfig") - val := field.Tag.Get("default") + val := field.Tag.Get("val") if err := writeAssignment(f, keywords.assignment, varName, val); err != nil { fmt.Fprintf(os.Stderr, "error writing to file: %s\n", err.Error()) os.Exit(1) diff --git a/cmd/server/main.go b/cmd/server/main.go index bab6d5a7..5994466b 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -21,13 +21,13 @@ func main() { var cfg config.Config err := envconfig.Process("", &cfg) if err != nil { - _, _ = fmt.Fprintf(os.Stderr, "unable to process app config: %s", err.Error()) + _, _ = fmt.Fprintf(os.Stderr, "unable to process app config: %s\n", err.Error()) os.Exit(1) } feedbagStore, err := state.NewSQLiteUserStore(cfg.DBPath) if err != nil { - _, _ = fmt.Fprintf(os.Stderr, "unable to create feedbag store: %s", err.Error()) + _, _ = fmt.Fprintf(os.Stderr, "unable to create feedbag store: %s\n", err.Error()) os.Exit(1) } diff --git a/config/config.go b/config/config.go index 2610fc63..4a58e9b6 100644 --- a/config/config.go +++ b/config/config.go @@ -3,14 +3,14 @@ package config //go:generate go run github.com/mk6i/retro-aim-server/cmd/config_generator windows settings.bat //go:generate go run github.com/mk6i/retro-aim-server/cmd/config_generator unix settings.env type Config struct { - AlertPort string `envconfig:"ALERT_PORT" default:"5194" description:"The port that the Alert service binds to."` - AuthPort string `envconfig:"AUTH_PORT" default:"5190" description:"The port that the auth service binds to."` - BOSPort string `envconfig:"BOS_PORT" default:"5191" description:"The port that the BOS service binds to."` - ChatNavPort string `envconfig:"CHAT_NAV_PORT" default:"5193" description:"The port that the chat nav service binds to."` - ChatPort string `envconfig:"CHAT_PORT" default:"5192" description:"The port that the chat service binds to."` - DBPath string `envconfig:"DB_PATH" default:"oscar.sqlite" description:"The path to the SQLite database file. The file and DB schema are auto-created if they doesn't exist."` - DisableAuth bool `envconfig:"DISABLE_AUTH" default:"true" description:"Disable password check and auto-create new users at login time. Useful for quickly creating new accounts during development without having to register new users via the management API."` - FailFast bool `envconfig:"FAIL_FAST" default:"false" description:"Crash the server in case it encounters a client message type it doesn't recognize. This makes failures obvious for debugging purposes."` - LogLevel string `envconfig:"LOG_LEVEL" default:"info" description:"Set logging granularity. Possible values: 'trace', 'debug', 'info', 'warn', 'error'."` - OSCARHost string `envconfig:"OSCAR_HOST" default:"127.0.0.1" description:"The hostname that AIM clients connect to in order to reach OSCAR services (auth, BOS, BUCP, etc). Make sure the hostname is reachable by all clients. For local development, the default loopback address should work provided the server and AIM client(s) are running on the same machine. For LAN-only clients, a private IP address (e.g. 192.168..) or hostname should suffice. For clients connecting over the Internet, specify your public IP address and ensure that TCP ports 5190-5194 are open on your firewall."` + AlertPort string `envconfig:"ALERT_PORT" required:"true" val:"5194" description:"The port that the Alert service binds to."` + AuthPort string `envconfig:"AUTH_PORT" required:"true" val:"5190" description:"The port that the auth service binds to."` + BOSPort string `envconfig:"BOS_PORT" required:"true" val:"5191" description:"The port that the BOS service binds to."` + ChatNavPort string `envconfig:"CHAT_NAV_PORT" required:"true" val:"5193" description:"The port that the chat nav service binds to."` + ChatPort string `envconfig:"CHAT_PORT" required:"true" val:"5192" description:"The port that the chat service binds to."` + DBPath string `envconfig:"DB_PATH" required:"true" val:"oscar.sqlite" description:"The path to the SQLite database file. The file and DB schema are auto-created if they doesn't exist."` + DisableAuth bool `envconfig:"DISABLE_AUTH" required:"true" val:"true" description:"Disable password check and auto-create new users at login time. Useful for quickly creating new accounts during development without having to register new users via the management API."` + FailFast bool `envconfig:"FAIL_FAST" required:"true" val:"false" description:"Crash the server in case it encounters a client message type it doesn't recognize. This makes failures obvious for debugging purposes."` + LogLevel string `envconfig:"LOG_LEVEL" required:"true" val:"info" description:"Set logging granularity. Possible values: 'trace', 'debug', 'info', 'warn', 'error'."` + OSCARHost string `envconfig:"OSCAR_HOST" required:"true" val:"127.0.0.1" description:"The hostname that AIM clients connect to in order to reach OSCAR services (auth, BOS, BUCP, etc). Make sure the hostname is reachable by all clients. For local development, the default loopback address should work provided the server and AIM client(s) are running on the same machine. For LAN-only clients, a private IP address (e.g. 192.168..) or hostname should suffice. For clients connecting over the Internet, specify your public IP address and ensure that TCP ports 5190-5194 are open on your firewall."` } diff --git a/docs/BUILD.md b/docs/BUILD.md index 0a32065a..5d21053b 100644 --- a/docs/BUILD.md +++ b/docs/BUILD.md @@ -82,4 +82,11 @@ command from the root of the repository in a terminal: ```shell go test -race ./... -``` \ No newline at end of file +``` + +## Config File Generation + +The config files `config/settings.bat` and `config/settings.env` are generated programmatically from the +[Config](../config/config.go) struct using `go generate`. If you want to add or remove application configuration +options, first edit the Config struct and then generate the configuration files by running `make config` from the +project root. Do not edit the config files by hand. diff --git a/scripts/run.cmd b/scripts/run.cmd index 35dbd2ef..3ae1493f 100644 --- a/scripts/run.cmd +++ b/scripts/run.cmd @@ -7,7 +7,7 @@ rem as this script, the script can be run from any directory. set SCRIPT_DIR=%~dp0 set ENV_FILE=%SCRIPT_DIR%settings.bat -set EXEC_FILE=%SCRIPT_DIR%retro_aim_server.exe +set EXEC_FILE=%SCRIPT_DIR%bin\retro_aim_server.exe rem Load the settings file. if exist "%ENV_FILE%" ( diff --git a/scripts/run.sh b/scripts/run.sh index 76ed66e4..02dfffb1 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -6,7 +6,7 @@ set -e SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) ENV_FILE="$SCRIPT_DIR/settings.env" -EXEC_FILE="$SCRIPT_DIR/retro_aim_server" +EXEC_FILE="$SCRIPT_DIR/bin/retro_aim_server" # Load the settings file. if [ -f "$ENV_FILE" ]; then