Przeglądaj źródła

resolve confusion over which executable to run

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.
Mike 2 lat temu
rodzic
commit
c716ac3032
8 zmienionych plików z 38 dodań i 27 usunięć
  1. 3 3
      .goreleaser.yaml
  2. 12 8
      Makefile
  3. 1 1
      cmd/config_generator/main.go
  4. 2 2
      cmd/server/main.go
  5. 10 10
      config/config.go
  6. 8 1
      docs/BUILD.md
  7. 1 1
      scripts/run.cmd
  8. 1 1
      scripts/run.sh

+ 3 - 3
.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:

+ 12 - 8
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) \
-		.
+		.
+
+.PHONY: release
+release:
+	$(DOCKER_RUN) --clean
+
+.PHONY: release-dry-run
+release-dry-run:
+	$(DOCKER_RUN) --clean --skip=validate --skip=publish

+ 1 - 1
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)

+ 2 - 2
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)
 	}
 

+ 10 - 10
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."`
 }

+ 8 - 1
docs/BUILD.md

@@ -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.

+ 1 - 1
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%" (

+ 1 - 1
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