Собирать игру в Linux-контейнере и доставлять образом

Windows-сборка (Node SEA, quiz.exe, .cmd для брандмауэра) удалена: целевая
среда одна — Linux в контейнере. Сервер бандлится esbuild-ом в один CJS-файл,
интерфейс собирает Vite; в рантайме нет node_modules, образ около 70 МБ
в сжатом виде.

Доставка — образ в registry того же сервера, где лежит git
(git.realmanual.ru/pub/fly-quiz): scripts/publish-image.sh собирает
linux/amd64 через buildx, на сервере docker compose pull && up -d.

В compose два роутера Traefik: quiz (весь сайт) и quiz-admin с basic auth на
/host, /import, /api/import и /api/packs/apply. QUIZ_ADMIN_USERS обязателен:
без него compose не стартует — иначе пульт и запись файлов молча оказались бы
открыты всему интернету.

Попутно исправлено: пустая переменная compose больше не считается значением
(env()/envPath()), корень проекта ищется по фактическому наличию content/packs
(npm start из dist/ раньше искал его в /), content/ и examples/ копируются в
стадию build, чтобы тесты проверяли медиа внутри образа.
This commit is contained in:
vasyansk committed 2026-11-23 16:32:43 +07:00
1 parent 4c41f54c79
commit a3bdd30314
27 files changed
+1274 -765

No files matched your search

+20
View File
@@ -12,6 +12,26 @@ export function rememberRoom(code: string): void {
}
}
/**
* Базовый адрес для ссылок и QR.
*
* Берём с сервера: за прокси (Traefik) табло могут открыть по localhost или
* внутреннему адресу, а телефону нужен публичный домен. Если сервер ничего не
* знает — остаётся текущий origin.
*/
export async function publicBase(): Promise<string> {
try {
const response = await fetch('/api/room')
if (response.ok) {
const data = (await response.json()) as { publicUrl?: string | null }
if (data.publicUrl) return data.publicUrl.replace(/\/+$/, '')
}
} catch {
// Сервер не ответил — ссылки останутся относительными, это переживём.
}
return window.location.origin
}
export async function resolveRoom(fromQuery: unknown): Promise<string> {
if (typeof fromQuery === 'string' && fromQuery.trim()) return normalizeRoomCode(fromQuery)
+7 -2
View File
@@ -16,7 +16,7 @@ import QuestionMedia from '../components/QuestionMedia.vue'
import ScoreBar from '../components/ScoreBar.vue'
import { disableSound, enableSound, loadSfx, preferredSound, sfx } from '../audio/sfx'
import { game, reportMedia } from '../net/game'
import { rememberRoom, resolveRoom } from '../net/room'
import { publicBase, rememberRoom, resolveRoom } from '../net/room'
const QUESTION_PHASES = ['question', 'cat_nominate', 'auction', 'answering', 'reveal']
@@ -50,7 +50,11 @@ const answererName = computed(
const ranked = computed(() =>
[...(state.value?.players ?? [])].sort((left, right) => right.score - left.score),
)
const playUrl = computed(() => `${window.location.origin}/play?room=${room.value}`)
/** Публичный адрес: с сервера (домен за прокси) или текущий origin. */
const baseUrl = ref('')
const playUrl = computed(
() => `${baseUrl.value || window.location.origin}/play?room=${room.value}`,
)
const tags = computed(() => {
const kind = active.value?.kind
if (kind === 'super') return ['супер']
@@ -117,6 +121,7 @@ onMounted(async () => {
return
}
rememberRoom(room.value)
baseUrl.value = await publicBase()
game.connect({ role: 'board', room: room.value })
// Файловые звуки из content/sfx подхватываются до первого вопроса.
void loadSfx()
+1 -1
View File
@@ -25,7 +25,7 @@ onMounted(async () => {
<p class="note">
Пульт ведущего открывается по адресу с токеном — его печатает сервер при
запуске: <code>http://&lt;адрес&gt;:5173/host/&lt;токен&gt;</code>
запуске: <code>/host/&lt;токен&gt;</code>
</p>
</main>
</div>
+7 -4
View File
@@ -3,6 +3,9 @@ import vue from '@vitejs/plugin-vue'
import { defineConfig } from 'vite'
const repoRoot = fileURLToPath(new URL('../..', import.meta.url))
// Сервер может жить в другом контейнере или на хосте: адрес прокси задаётся
// снаружи, иначе dev-режим ломается на ECONNREFUSED.
const serverTarget = process.env.QUIZ_SERVER_URL ?? 'http://127.0.0.1:3000'
export default defineConfig({
plugins: [vue()],
@@ -22,10 +25,10 @@ export default defineConfig({
fs: { allow: [repoRoot] },
proxy: {
// Один сервер на одном порту; в dev сокеты и API проксируются на него.
'/socket.io': { target: 'http://127.0.0.1:3000', ws: true },
'/api': { target: 'http://127.0.0.1:3000' },
'/media': { target: 'http://127.0.0.1:3000' },
'/sfx': { target: 'http://127.0.0.1:3000' },
'/socket.io': { target: serverTarget, ws: true },
'/api': { target: serverTarget },
'/media': { target: serverTarget },
'/sfx': { target: serverTarget },
},
},
})