Skip to content

Commit

Permalink
resolve confusion over which executable to run
Browse files Browse the repository at this point in the history
Some users reported that RAS was not picking up changes to their
settings files. This occurred when they would start the application
executable rather than the start script, which loads the environment
file before starting the application. When this happened, the
application loaded setting defaults.

To fix this issue, this commit does two things to ensure that users run
the application through the script:
- Move the binary into a bin/ subfolder
- Remove default settings entirely, so that the application exits with
  an error if no settings are applied.
  • Loading branch information
mk6i committed May 19, 2024
1 parent 9a120cd commit c716ac3
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 27 deletions.
6 changes: 3 additions & 3 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ before:

builds:
- id: linux
binary: retro_aim_server
binary: bin/retro_aim_server
goos:
- linux
goarch:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
20 changes: 12 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -25,4 +21,12 @@ goreleaser-docker:
--build-arg GO_RELEASER_CROSS_VERSION=$(GO_RELEASER_CROSS_VERSION) \
--file Dockerfile.goreleaser \
--tag $(DOCKER_IMAGE_TAG) \
.
.

.PHONY: release
release:
$(DOCKER_RUN) --clean

.PHONY: release-dry-run
release-dry-run:
$(DOCKER_RUN) --clean --skip=validate --skip=publish
2 changes: 1 addition & 1 deletion cmd/config_generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
20 changes: 10 additions & 10 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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."`
}
9 changes: 8 additions & 1 deletion docs/BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,11 @@ command from the root of the repository in a terminal:

```shell
go test -race ./...
```
```

## 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.
2 changes: 1 addition & 1 deletion scripts/run.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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%" (
Expand Down
2 changes: 1 addition & 1 deletion scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c716ac3

Please sign in to comment.