Skip to content

Commit 2a26bc8

Browse files
authored
Move runtime ownership into druid-cli (#76)
* feat: refactor runtime for container backends * feat: move runtime ownership to druid cli * chore: trim unused runtime helpers * chore: sloppy draft * feat: add namespace support for runtime resources - Introduced a new `namespace` field in the OpenAPI specification for runtime resources, applicable to Kubernetes backends. - Updated the runtime supervisor and related services to handle the new namespace parameter during scroll creation and management. - Enhanced error handling and logging in the runtime daemon for better observability. - Refactored related tests to accommodate the namespace changes and ensure proper functionality. * feat: enhance runtime scroll creation with UUID generation and timeout settings - Added UUID generation for runtime scroll IDs when omitted during creation, ensuring unique identifiers. - Implemented a timeout for HTTP clients in the OpenAPI client to improve reliability. - Updated OpenAPI specifications and related documentation to reflect changes in ID handling. - Refactored error handling in the runtime supervisor to manage scroll creation more effectively. - Enhanced tests to cover new functionality and ensure robustness in scroll management. * feat: implement worker callback configuration for runtime daemon - Introduced a new `RuntimeWorkerCallbackConfig` structure to manage callback settings for the runtime daemon. - Enhanced the `runRuntimeDaemon` function to load environment variables and configure worker callbacks dynamically. - Added `openWorkerCallbackListener` function to handle TCP listener creation for worker callbacks. - Updated the Docker backend to support worker callback defaults and URL generation after listener setup. - Added unit tests for the new callback listener functionality and its integration with the runtime daemon. * feat: enhance runtime command handling with routing and error management - Added support for routing assignments in the runtime command structure, allowing for better management of network configurations. - Introduced a new error type for non-retryable command errors, improving error handling in the queue manager and procedure launcher. - Updated the Docker backend to utilize routing information during container creation and command execution. - Enhanced unit tests to validate the new routing functionality and error handling improvements. * refactor(runtime): slim daemon backends * fix(runtime): retry incomplete materialization * test: fix docker runtime integration checks * test: avoid docker e2e port and cleanup conflicts * test: make docker integration cleanup reliable * test: fix runtime cleanup races * test: load worker image into kind * fix: harden runtime daemon
1 parent bd692b8 commit 2a26bc8

296 files changed

Lines changed: 27103 additions & 16235 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.docker/druid-install-command.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ fi
1010
BASEDIR=$(dirname "$0")
1111

1212
wget --show-progress -q -O $BASEDIR/druid https://github.com/highcard-dev/druid-cli/releases/$URL_PATH/druid
13-
wget --show-progress -q -O $BASEDIR/druid_rcon https://github.com/highcard-dev/druid-cli/releases/$URL_PATH/druid_rcon
14-
wget --show-progress -q -O $BASEDIR/druid_rcon_web_rust https://github.com/highcard-dev/druid-cli/releases/$URL_PATH/druid_rcon_web_rust
1513
wget --show-progress -q -O $BASEDIR/entrypoint.sh https://github.com/highcard-dev/druid-cli/releases/$URL_PATH/entrypoint.sh
16-
chmod +x $BASEDIR/druid $BASEDIR/druid_rcon $BASEDIR/druid_rcon_web_rust
14+
chmod +x $BASEDIR/druid
1715

1816
# Modify the PATH variable to prioritize /app/resources
1917
export PATH=$BASEDIR:$PATH

.docker/entrypoint.sh

Lines changed: 9 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env bash
22

33
set -e
4-
SD="./"
54
input=$@
65

76
# Global args derived from envs that apply to multiple commands
@@ -16,123 +15,24 @@ then
1615
global_args+=("--config=$DRUID_CONFIG")
1716
fi
1817

19-
# Migrate legacy .scroll layout:
20-
# Before: .scroll/<scroll files> + <serverfiles>
21-
# After: <scroll files> + data/<serverfiles>
22-
if [ -d "${SD}.scroll" ]; then
23-
echo "Migrating legacy .scroll layout..."
24-
mkdir -p "${SD}data"
25-
for item in "${SD}"* "${SD}".[!.]*; do
26-
[ -e "$item" ] || continue
27-
name=$(basename "$item")
28-
[ "$name" != "data" ] && [ "$name" != ".scroll" ] && mv "$item" "${SD}data/"
29-
done
30-
mv "${SD}.scroll"/* "${SD}"
31-
rm -rf "${SD}.scroll"
32-
echo "Legacy migration complete"
33-
fi
34-
3518
echo "Druid Version: $(druid version)"
3619

37-
if [ ! -z "${DRUID_REGISTRY_HOST}" ] && [ ! -z "${DRUID_REGISTRY_USER}" ] && [ ! -z "${DRUID_REGISTRY_PASSWORD}" ];
38-
then
39-
echo "Logging into registry ${DRUID_REGISTRY_HOST}"
40-
druid registry login --host "${DRUID_REGISTRY_HOST}" -u "${DRUID_REGISTRY_USER}" -p "${DRUID_REGISTRY_PASSWORD}"
20+
if [ "$1" = "druid-coldstarter" ] || [ "$1" = "/usr/bin/druid-coldstarter" ]; then
21+
exec "$@"
4122
fi
4223

43-
if [ "${ENSURE_NIX}" = "true" ];
24+
if [ ! -z "${DRUID_REGISTRY_HOST}" ] && [ ! -z "${DRUID_REGISTRY_USER}" ] && [ ! -z "${DRUID_REGISTRY_PASSWORD}" ];
4425
then
45-
if [ ! -e "$HOME/.nix-profile" ];
46-
then
47-
echo "Installing Nix package manager"
48-
sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --no-daemon
49-
echo "Nix installed"
50-
fi
51-
nix-channel --update
26+
echo "Logging into registry ${DRUID_REGISTRY_HOST}"
27+
druid login --host "${DRUID_REGISTRY_HOST}" -u "${DRUID_REGISTRY_USER}" -p "${DRUID_REGISTRY_PASSWORD}"
5228
fi
5329

54-
#Check if we should serve as default or when only artifact is specified
55-
if [ -z "$input" ] || [[ $input =~ ([^/]+)/([^:]+):([^/]+) ]] && [[ $input != *" "* ]]; then artifact="${input}"
56-
if [ -z "${artifact}" ];
57-
then
58-
artifact=$DRUID_SCROLL_ARTIFACT
59-
fi
60-
61-
echo "Artifact: $artifact"
62-
63-
#Update command
64-
if [ "${DRUID_AUTO_UPDATE}" = "true" ] && [ -f "${SD}/scroll.yaml" ];
65-
then
66-
echo "Updating artifact"
67-
68-
# Build args for `druid update` so that global envs apply as well
69-
update_args=(update "${global_args[@]}")
70-
71-
druid "${update_args[@]}"
72-
echo "Updated artifact"
73-
fi
74-
75-
76-
#ignore-version-check otherwise we have missmatch after update
77-
args=(serve --ignore-version-check --additional-endpoints annotations)
78-
79-
if [ ! -z "${artifact}" ];
80-
then
81-
args+=($artifact)
82-
fi
83-
84-
# Map envs to args (--cwd = scroll dir, --config = path to .druid.yaml)
85-
if [ ! -z "${DRUID_JWKS_SERVER}" ];
86-
then
87-
args+=("--jwks-server" "${DRUID_JWKS_SERVER}")
88-
fi
89-
90-
if [ ! -z "${DRUID_USER_ID}" ];
91-
then
92-
args+=("--user-id" "${DRUID_USER_ID}")
93-
fi
94-
95-
if [ ! -z "${DRUID_PORT}" ];
96-
then
97-
args+=("--port" "${DRUID_PORT}")
98-
fi
99-
100-
if [ ! -z "${DRUID_IDLE}" ];
101-
then
102-
args+=("--idle=$DRUID_IDLE")
103-
fi
104-
if [ ! -z "${DRUID_WATCH_PORTS}" ];
105-
then
106-
args+=("--watch-ports=$DRUID_WATCH_PORTS")
107-
fi
108-
109-
if [ ! -z "${DRUID_WATCH_PORTS_INTERFACES}" ];
110-
then
111-
args+=("--watch-ports-interfaces" "${DRUID_WATCH_PORTS_INTERFACES}")
112-
fi
113-
114-
if [ ! -z "${DRUID_COLDSTARTER}" ];
115-
then
116-
args+=("--coldstarter=$DRUID_COLDSTARTER")
117-
fi
118-
119-
if [ ! -z "${DRUID_INIT_SNAPSHOT_URL}" ];
120-
then
121-
args+=("--init-snapshot-url=$DRUID_INIT_SNAPSHOT_URL")
122-
fi
123-
124-
if [ ! -z "${DRUID_SKIP_ARTIFACT_DOWNLOAD}" ];
125-
then
126-
args+=("--skip-artifact-download")
127-
fi
30+
# Daemon is the default container mode when no command is provided.
31+
if [ -z "$input" ]; then
32+
args=(daemon)
12833

12934
# Reuse global args (cwd/config) for serve as well
13035
args+=("${global_args[@]}")
131-
132-
if [ ! -z "${PPROF_BIND}" ];
133-
then
134-
args+=("--pprof=$PPROF_BIND")
135-
fi
13636

13737
echo "Running druid with args from env: ${args[@]}"
13838
exec druid "${args[@]}"
@@ -156,4 +56,4 @@ else
15656
done
15757

15858
exec druid "${args[@]}"
159-
fi
59+
fi

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
examples
22
__debug_bin*
3+
.git
4+
.runtime-state
5+
bin
6+
dist
7+
tmp
8+
*.db
9+
*.sock
10+
.DS_Store

.github/workflows/build.yml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ jobs:
99
- uses: actions/checkout@v4
1010
- uses: actions/setup-go@v5
1111
with:
12-
go-version: "^1.21"
13-
- run: make test-integration-docker
14-
name: Run integration tests inside Docker
12+
go-version: "^1.24"
13+
- uses: azure/setup-kubectl@v4
14+
- run: make test-integration
15+
name: Run CLI backend integration tests
1516
- run: make test
1617
name: Unit tests
1718

@@ -21,19 +22,16 @@ jobs:
2122
- uses: actions/checkout@v4
2223
- uses: actions/setup-go@v5
2324
with:
24-
go-version: "^1.21"
25+
go-version: "^1.24"
2526
- run: make build
2627
name: Build
27-
- run: make build-plugins
28-
name: Build plugins
2928
- uses: actions/upload-artifact@v4
3029
name: Upload build artifacts
3130
with:
3231
name: build-artifacts
3332
path: |
3433
bin/druid
35-
bin/druid_rcon
36-
bin/druid_rcon_web_rust
34+
bin/druid-coldstarter
3735
.docker/entrypoint.sh
3836
.docker/druid-install-command.sh
3937
@@ -57,8 +55,6 @@ jobs:
5755
name: Build
5856
env:
5957
VERSION: ${{ steps.version.outputs.version_tag }}
60-
- run: make build-plugins
61-
name: Build plugins
6258
- name: Release
6359
uses: softprops/action-gh-release@v2
6460
with:
@@ -67,8 +63,7 @@ jobs:
6763
make_latest: true
6864
files: |
6965
bin/druid
70-
bin/druid_rcon
71-
bin/druid_rcon_web_rust
66+
bin/druid-coldstarter
7267
.docker/entrypoint.sh
7368
.docker/druid-install-command.sh
7469

.github/workflows/docker-builds.yml

Lines changed: 1 addition & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Reusable workflow: all Docker image builds (base, manifests, steamcmd, nix).
1+
# Reusable workflow: all Docker image builds (base, manifests, steamcmd).
22
# Used by master build.yml and PR pr.yml to avoid duplication.
33
name: Docker builds (reusable)
44
on:
@@ -120,98 +120,3 @@ jobs:
120120
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
121121
DRUID_ARTIFACTS_REGISTRY_USERNAME: ${{ secrets.DRUID_ARTIFACTS_REGISTRY_USERNAME }}
122122
DRUID_ARTIFACTS_REGISTRY_TOKEN: ${{ secrets.DRUID_ARTIFACTS_REGISTRY_TOKEN }}
123-
124-
docker-nix-amd64:
125-
needs: [docker-base-manifest, docker-base-manifest-artifacts]
126-
uses: ./.github/workflows/docker-build-reusable.yml
127-
with:
128-
dockerfile: Dockerfile.nix
129-
runs_on: ubuntu-latest
130-
tags: |
131-
highcard/druid:${{ inputs.version_tag }}-nix-amd64
132-
artifacts.druid.gg/druid-team/druid:${{ inputs.version_tag }}-nix-amd64
133-
build_args: |
134-
VERSION=${{ inputs.version_tag }}
135-
secrets:
136-
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
137-
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
138-
DRUID_ARTIFACTS_REGISTRY_USERNAME: ${{ secrets.DRUID_ARTIFACTS_REGISTRY_USERNAME }}
139-
DRUID_ARTIFACTS_REGISTRY_TOKEN: ${{ secrets.DRUID_ARTIFACTS_REGISTRY_TOKEN }}
140-
141-
docker-nix-arm64:
142-
needs: [docker-base-manifest, docker-base-manifest-artifacts]
143-
uses: ./.github/workflows/docker-build-reusable.yml
144-
with:
145-
dockerfile: Dockerfile.nix
146-
runs_on: ubuntu-24.04-arm
147-
tags: |
148-
highcard/druid:${{ inputs.version_tag }}-nix-arm64
149-
artifacts.druid.gg/druid-team/druid:${{ inputs.version_tag }}-nix-arm64
150-
build_args: |
151-
VERSION=${{ inputs.version_tag }}
152-
secrets:
153-
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
154-
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
155-
DRUID_ARTIFACTS_REGISTRY_USERNAME: ${{ secrets.DRUID_ARTIFACTS_REGISTRY_USERNAME }}
156-
DRUID_ARTIFACTS_REGISTRY_TOKEN: ${{ secrets.DRUID_ARTIFACTS_REGISTRY_TOKEN }}
157-
158-
docker-nix-steamcmd:
159-
needs: [docker-steamcmd]
160-
uses: ./.github/workflows/docker-build-reusable.yml
161-
with:
162-
dockerfile: Dockerfile.nix
163-
tags: |
164-
highcard/druid:${{ inputs.version_tag }}-nix-steamcmd
165-
artifacts.druid.gg/druid-team/druid:${{ inputs.version_tag }}-nix-steamcmd
166-
${{ inputs.is_pr != true && format('highcard/druid:latest-nix-steamcmd') || '' }}
167-
${{ inputs.is_pr != true && format('highcard/druid:stable-nix-steamcmd') || '' }}
168-
${{ inputs.is_pr != true && format('highcard/druid:{0}-nix-steamcmd', inputs.version) || '' }}
169-
${{ inputs.is_pr != true && format('artifacts.druid.gg/druid-team/druid:latest-nix-steamcmd') || '' }}
170-
${{ inputs.is_pr != true && format('artifacts.druid.gg/druid-team/druid:stable-nix-steamcmd') || '' }}
171-
${{ inputs.is_pr != true && format('artifacts.druid.gg/druid-team/druid:{0}-nix-steamcmd', inputs.version) || '' }}
172-
build_args: |
173-
VERSION=${{ inputs.version_tag }}-steamcmd
174-
secrets:
175-
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
176-
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
177-
DRUID_ARTIFACTS_REGISTRY_USERNAME: ${{ secrets.DRUID_ARTIFACTS_REGISTRY_USERNAME }}
178-
DRUID_ARTIFACTS_REGISTRY_TOKEN: ${{ secrets.DRUID_ARTIFACTS_REGISTRY_TOKEN }}
179-
180-
docker-nix-manifest:
181-
name: Create multi-arch nix manifests
182-
needs: [docker-nix-amd64, docker-nix-arm64]
183-
runs-on: ubuntu-latest
184-
steps:
185-
- name: Login to Docker Hub
186-
uses: docker/login-action@v3
187-
with:
188-
username: ${{ secrets.DOCKERHUB_USERNAME }}
189-
password: ${{ secrets.DOCKERHUB_TOKEN }}
190-
- name: Create and push nix manifests
191-
uses: Noelware/docker-manifest-action@v1
192-
with:
193-
inputs: highcard/druid:${{ inputs.version_tag }}-nix-amd64,highcard/druid:${{ inputs.version_tag }}-nix-arm64
194-
tags: >-
195-
highcard/druid:${{ inputs.version }}-nix,
196-
highcard/druid:${{ inputs.version_tag }}-nix${{ inputs.is_pr != true && ',highcard/druid:latest-nix,highcard/druid:stable-nix' || '' }}
197-
push: true
198-
199-
docker-nix-manifest-artifacts:
200-
name: Create multi-arch nix manifests (artifacts registry)
201-
needs: [docker-nix-amd64, docker-nix-arm64]
202-
runs-on: ubuntu-latest
203-
steps:
204-
- name: Login to Artifacts Registry
205-
uses: docker/login-action@v3
206-
with:
207-
registry: artifacts.druid.gg
208-
username: ${{ secrets.DRUID_ARTIFACTS_REGISTRY_USERNAME }}
209-
password: ${{ secrets.DRUID_ARTIFACTS_REGISTRY_TOKEN }}
210-
- name: Create and push nix manifests (artifacts)
211-
uses: Noelware/docker-manifest-action@v1
212-
with:
213-
inputs: artifacts.druid.gg/druid-team/druid:${{ inputs.version_tag }}-nix-amd64,artifacts.druid.gg/druid-team/druid:${{ inputs.version_tag }}-nix-arm64
214-
tags: >-
215-
artifacts.druid.gg/druid-team/druid:${{ inputs.version }}-nix,
216-
artifacts.druid.gg/druid-team/druid:${{ inputs.version_tag }}-nix${{ inputs.is_pr != true && ',artifacts.druid.gg/druid-team/druid:latest-nix,artifacts.druid.gg/druid-team/druid:stable-nix' || '' }}
217-
push: true

.github/workflows/pr.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ jobs:
2020
- uses: actions/setup-go@v5
2121
with:
2222
go-version: "^1.24"
23-
- run: make test-integration-docker
24-
name: Run integration tests inside Docker
23+
- uses: azure/setup-kubectl@v4
24+
- run: make test-integration
25+
name: Run CLI backend integration tests
2526

2627
validate-api:
2728
runs-on: ubuntu-latest
@@ -42,15 +43,12 @@ jobs:
4243
go-version: "^1.24"
4344
- run: make build
4445
name: Build
45-
- run: make build-plugins
46-
name: Build Plugins
4746
- uses: actions/upload-artifact@v4
4847
with:
4948
name: build-artifacts
5049
path: |
5150
bin/druid
52-
bin/druid_rcon
53-
bin/druid_rcon_web_rust
51+
bin/druid-coldstarter
5452
.docker/entrypoint.sh
5553
.docker/druid-install-command.sh
5654
@@ -76,8 +74,7 @@ jobs:
7674
prerelease: true
7775
files: |
7876
bin/druid
79-
bin/druid_rcon
80-
bin/druid_rcon_web_rust
77+
bin/druid-coldstarter
8178
.docker/entrypoint.sh
8279
.docker/druid-install-command.sh
8380

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
*.tar.gz
55

66
druid**
7+
!apps/
8+
!apps/**
9+
!config/
10+
!config/**
711
dlv.log
812

913
.DS_Store
@@ -15,4 +19,5 @@ druid-cli-test
1519

1620
!.docker/**
1721

18-
.env
22+
.env
23+
.runtime-state

0 commit comments

Comments
 (0)