From 105e5c5da309a6ca21b6ce35cbf2662c6b6a24e0 Mon Sep 17 00:00:00 2001 From: Ricardo-binZzz <285964759+Ricardo-binZzz@users.noreply.github.com> Date: Wed, 29 Jul 2026 06:45:30 +0800 Subject: [PATCH] fix(release): include pricing fallback resources --- .github/workflows/backend-ci.yml | 1 + .goreleaser.simple.yaml | 1 + .goreleaser.yaml | 4 +++ Dockerfile.goreleaser | 3 +- deploy/Dockerfile | 3 +- deploy/tests/docker-runtime-resources-test.sh | 34 +++++++++++++++++++ 6 files changed, 44 insertions(+), 2 deletions(-) create mode 100755 deploy/tests/docker-runtime-resources-test.sh diff --git a/.github/workflows/backend-ci.yml b/.github/workflows/backend-ci.yml index 77729863d..21a4fea79 100644 --- a/.github/workflows/backend-ci.yml +++ b/.github/workflows/backend-ci.yml @@ -17,6 +17,7 @@ jobs: /bin/bash -n deploy/apple-container.sh /bin/bash deploy/tests/apple-container-test.sh /bin/sh deploy/tests/docker-compose-security-test.sh + /bin/sh deploy/tests/docker-runtime-resources-test.sh /bin/sh deploy/test-caddyfile-cache.sh test: diff --git a/.goreleaser.simple.yaml b/.goreleaser.simple.yaml index 14f67fd1c..b25df6e3b 100644 --- a/.goreleaser.simple.yaml +++ b/.goreleaser.simple.yaml @@ -49,6 +49,7 @@ dockers: use: buildx extra_files: - deploy/docker-entrypoint.sh + - backend/resources build_flag_templates: - "--platform=linux/amd64" - "--label=org.opencontainers.image.version={{ .Version }}" diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 41f9a5559..19adfdf6d 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -65,6 +65,7 @@ dockers: use: buildx extra_files: - deploy/docker-entrypoint.sh + - backend/resources build_flag_templates: - "--platform=linux/amd64" - "--label=org.opencontainers.image.version={{ .Version }}" @@ -80,6 +81,7 @@ dockers: use: buildx extra_files: - deploy/docker-entrypoint.sh + - backend/resources build_flag_templates: - "--platform=linux/arm64" - "--label=org.opencontainers.image.version={{ .Version }}" @@ -95,6 +97,7 @@ dockers: use: buildx extra_files: - deploy/docker-entrypoint.sh + - backend/resources build_flag_templates: - "--platform=linux/amd64" - "--label=org.opencontainers.image.version={{ .Version }}" @@ -110,6 +113,7 @@ dockers: use: buildx extra_files: - deploy/docker-entrypoint.sh + - backend/resources build_flag_templates: - "--platform=linux/arm64" - "--label=org.opencontainers.image.version={{ .Version }}" diff --git a/Dockerfile.goreleaser b/Dockerfile.goreleaser index f251d154c..804fb05e0 100644 --- a/Dockerfile.goreleaser +++ b/Dockerfile.goreleaser @@ -42,8 +42,9 @@ RUN addgroup -g 1000 sub2api && \ WORKDIR /app -# Copy pre-built binary from GoReleaser +# Copy the pre-built binary and runtime fallback resources from GoReleaser COPY sub2api /app/sub2api +COPY --chown=sub2api:sub2api backend/resources /app/resources # Create data directory RUN mkdir -p /app/data && chown -R sub2api:sub2api /app diff --git a/deploy/Dockerfile b/deploy/Dockerfile index 88d364a7f..325520f30 100644 --- a/deploy/Dockerfile +++ b/deploy/Dockerfile @@ -103,8 +103,9 @@ RUN addgroup -g 1000 sub2api && \ # Set working directory WORKDIR /app -# Copy binary from builder +# Copy binary and runtime fallback resources from builder COPY --from=backend-builder /app/sub2api /app/sub2api +COPY --from=backend-builder --chown=sub2api:sub2api /app/backend/resources /app/resources # Create data directory RUN mkdir -p /app/data && chown -R sub2api:sub2api /app diff --git a/deploy/tests/docker-runtime-resources-test.sh b/deploy/tests/docker-runtime-resources-test.sh new file mode 100755 index 000000000..4e7480d4d --- /dev/null +++ b/deploy/tests/docker-runtime-resources-test.sh @@ -0,0 +1,34 @@ +#!/bin/sh +set -eu + +repo_root=$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd) +cd "$repo_root" + +fail() { + printf 'docker runtime resources test failed: %s\n' "$1" >&2 + exit 1 +} + +assert_line() { + file=$1 + line=$2 + grep -Fqx "$line" "$file" || fail "$file is missing: $line" +} + +assert_count() { + file=$1 + line=$2 + expected=$3 + actual=$(grep -Fxc "$line" "$file" || true) + [ "$actual" -eq "$expected" ] || fail "$file has $actual occurrences of '$line', expected $expected" +} + +test -s backend/resources/model-pricing/model_prices_and_context_window.json || \ + fail 'fallback pricing data is missing or empty' + +assert_line Dockerfile.goreleaser 'COPY --chown=sub2api:sub2api backend/resources /app/resources' +assert_line deploy/Dockerfile 'COPY --from=backend-builder --chown=sub2api:sub2api /app/backend/resources /app/resources' +assert_count .goreleaser.yaml ' - backend/resources' 4 +assert_count .goreleaser.simple.yaml ' - backend/resources' 1 + +printf 'docker runtime resources test passed\n'