build: support selecting environment config file

This commit is contained in:
Eric 1549169735@qq.com
2026-08-19 22:01:54 +08:00
parent 5ac8086ce2
commit f93d093928
5 changed files with 65 additions and 4 deletions

View File

@@ -2,8 +2,12 @@ WEB_DIR := web
SDK_DIR := sdk
ARCH ?= $(shell go env GOARCH)
GOOS ?= $(shell go env GOOS)
CONFIG_DIR ?= configs
CONFIG_FILE ?=
ENV_FILE ?= config.yml
BUILD_DIR ?= bin
.PHONY: web-install web-build sdk-install sdk-build build test vet check seed-pet-doctor docker-config docker-up docker-down docker-logs
.PHONY: web-install web-build sdk-install sdk-build build run test vet check seed-pet-doctor docker-config docker-up docker-down docker-logs
web-install:
cd $(WEB_DIR) && npm install
@@ -18,7 +22,15 @@ sdk-build:
cd $(SDK_DIR) && npm run build
build: web-build sdk-build
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(ARCH) go build -o bin/main .
@test -f $(CONFIG_DIR)/config.yml || (echo "missing base config: $(CONFIG_DIR)/config.yml"; exit 1)
@test -f $(CONFIG_DIR)/$(ENV_FILE) || (echo "missing environment file: $(CONFIG_DIR)/$(ENV_FILE)"; exit 1)
mkdir -p $(BUILD_DIR)/configs
cp $(CONFIG_DIR)/config.yml $(BUILD_DIR)/configs/config.yml
@if [ "$(ENV_FILE)" != "config.yml" ]; then cp $(CONFIG_DIR)/$(ENV_FILE) $(BUILD_DIR)/configs/$(ENV_FILE); fi
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(ARCH) go build -o $(BUILD_DIR)/main .
run: build
./$(BUILD_DIR)/main -config-dir $(if $(CONFIG_FILE),$(CONFIG_DIR),$(BUILD_DIR)/configs) $(if $(CONFIG_FILE),-config-file $(CONFIG_FILE),)
test:
go test ./...