forked from stardew-valley-dedicated-server/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
163 lines (139 loc) · 5.71 KB
/
Makefile
File metadata and controls
163 lines (139 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
.PHONY: docs
# Load configuration
-include .env
# Function to strip single/double quotes using Make functions
define strip_quotes
$(subst ",,$(subst ',,$($(1))))
endef
# Disable printing directory traversal on task start/end
MAKEFLAGS += --no-print-directory
# Constants
IMAGE_NAME=sdvd/server
TEST_CLIENT_IMAGE_NAME=sdvd/test-client
IMAGE_VERSION ?= local
DOCKERFILE_PATH=docker/Dockerfile
TEST_CLIENT_DOCKERFILE_PATH=docker/Dockerfile.test-client
# Build configuration (Debug for local, Release for CI/production)
BUILD_CONFIGURATION ?= Debug
# Docker build progress output (plain, tty, auto, quiet)
DOCKER_PROGRESS ?= plain
# Export IMAGE_VERSION for usage in docker compose commands
export IMAGE_VERSION
# Export make variables as actual environment variables,
# so that we can pass them as docker secrets during build
export STEAM_USERNAME := $(call strip_quotes,STEAM_USERNAME)
export STEAM_PASSWORD := $(call strip_quotes,STEAM_PASSWORD)
export STEAM_REFRESH_TOKEN := $(call strip_quotes,STEAM_REFRESH_TOKEN)
# Cross-platform ISO 8601 UTC timestamp (safe for use with filenames etc.)
ifeq ($(OS),Windows_NT)
TIMESTAMP := $(shell powershell -NoProfile -Command "(Get-Date).ToUniversalTime().ToString('yyyy-MM-ddTHH-mm-ss')")Z
else
TIMESTAMP := $(shell date -u '+%Y-%m-%dT%H-%M-%S')Z
endif
# Install development dependencies
install:
@echo Installing development dependencies...
@npm ci
@echo Setup complete. Git hooks are now active.
# Build docker image (downloads game during build for mod compilation)
build:
@echo Building image `$(IMAGE_NAME):$(IMAGE_VERSION)` with BUILD_CONFIGURATION=$(BUILD_CONFIGURATION)...
@docker buildx build \
--platform=linux/amd64 \
--build-arg BUILD_CONFIGURATION=$(BUILD_CONFIGURATION) \
-t $(IMAGE_NAME):$(IMAGE_VERSION) \
$(if $(filter-out local,$(IMAGE_VERSION)),-t $(IMAGE_NAME):latest) \
--secret id=steam_username,env=STEAM_USERNAME \
--secret id=steam_password,env=STEAM_PASSWORD \
--secret id=steam_refresh_token,env=STEAM_REFRESH_TOKEN \
-f $(DOCKERFILE_PATH) \
--load \
--progress=$(DOCKER_PROGRESS) \
.
@echo Build complete.
# Build test client docker image (for containerized E2E tests)
build-test-client:
@echo Building test client image `$(TEST_CLIENT_IMAGE_NAME):$(IMAGE_VERSION)`...
@docker buildx build \
--platform=linux/amd64 \
-t $(TEST_CLIENT_IMAGE_NAME):$(IMAGE_VERSION) \
--secret id=steam_username,env=STEAM_USERNAME \
--secret id=steam_password,env=STEAM_PASSWORD \
--secret id=steam_refresh_token,env=STEAM_REFRESH_TOKEN \
-f $(TEST_CLIENT_DOCKERFILE_PATH) \
--load \
--progress=$(DOCKER_PROGRESS) \
.
@echo Test client build complete.
# Build and run everything
up: build
@echo Starting server `$(IMAGE_NAME):$(IMAGE_VERSION)`...
@docker compose up -d --build
@echo Server is now running. Use `make cli` or `make logs` to view output.
setup:
@docker compose run --rm -it steam-auth setup
@echo Server is now set up. Use `make cli` or `make logs` to view output.
restart:
@echo Restarting server `$(IMAGE_NAME):$(IMAGE_VERSION)`...
@docker compose restart
@echo Server restarted. Use `make cli` or `make logs` to view output.
# Stop the server
down:
@echo Stopping server...
@docker compose down --remove-orphans
# Attach to interactive split-pane server CLI
cli:
@docker compose exec server attach-cli
# View server logs (escape sequence to reset colors)
logs:
@docker compose logs -f
-@bun -e "process.stdout.write('\x1b[0m')"
dumplogs:
@echo "Writing logs to logs_$(TIMESTAMP).txt"
@docker compose logs > "logs_$(TIMESTAMP).txt"
# Start docs dev server (extracts OpenAPI spec from Docker image first)
docs:
@echo Extracting OpenAPI spec from $(IMAGE_NAME):$(IMAGE_VERSION) image...
@bun -e "require('fs').mkdirSync('docs/assets', { recursive: true })"
-@bun -e "try{require('child_process').execSync('docker rm -f openapi-extract',{stdio:'ignore'})}catch(e){}"
@docker create --name openapi-extract $(IMAGE_NAME):$(IMAGE_VERSION)
@docker cp openapi-extract:/data/openapi.json docs/assets/openapi.json
@docker rm openapi-extract
@echo OpenAPI spec ready.
@bun --cwd=./docs run dev
# Clean up everything, including all volumes
clean:
@echo Cleaning up...
@IMAGE_VERSION=$(IMAGE_VERSION) docker compose down -v
-@docker rmi $(IMAGE_NAME):$(IMAGE_VERSION) $(IMAGE_NAME):latest
# Run tests. Use FILTER to run specific tests:
# make test FILTER=PasswordProtection
# make test FILTER="Login_WithCorrectPassword"
# make test (runs all tests)
FILTER ?=
export COLUMNS=160
test:
@dotnet tool restore
@dotnet test ./tests/JunimoServer.Tests/ --settings ./tests/JunimoServer.Tests/JunimoServer.Tests.runsettings $(if $(FILTER),--filter "$(FILTER)")
@echo Generating test report...
@dotnet TrxToExtentReport -t ./TestResults/TestResults.trx -o ./TestResults/TestReport.html
# Show help
help:
@echo Stardew Valley Dedicated Server
@echo ""
@echo Targets:
@echo " make install - Install development dependencies (commitlint, git hooks)"
@echo " make setup - Run first-time Steam authentication and game download"
@echo " make up - Build and start server"
@echo " make build - Build docker image"
@echo " make logs - View server logs"
@echo " make dumplogs - Dump server logs to file on host"
@echo " make cli - Attach to interactive server console (tmux-based)"
@echo " make down - Stop the server"
@echo " make docs - Start docs dev server (requires built image)"
@echo " make clean - Remove ALL containers, volumes and images"
@echo " make test - Run E2E tests (use FILTER=X to filter, e.g. FILTER=PasswordProtection)"
@echo " make build-test-client - Build test client container image (for E2E tests)"
@echo ""
@echo Note: Use GitHub Actions for building and pushing release images
.DEFAULT_GOAL := help