2026-08-03 15:50:24 +08:00
|
|
|
import { readFileSync } from 'node:fs'
|
|
|
|
|
import { resolve } from 'node:path'
|
|
|
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
|
|
|
|
|
|
const config = readFileSync(resolve(process.cwd(), 'nginx/default.conf.template'), 'utf8')
|
2026-08-21 11:20:09 +08:00
|
|
|
const testCompose = readFileSync(resolve(process.cwd(), 'docker-compose.test.yml'), 'utf8')
|
|
|
|
|
const developmentCompose = readFileSync(resolve(process.cwd(), 'docker-compose.development.yml'), 'utf8')
|
2026-08-24 14:00:55 +08:00
|
|
|
const jenkinsfile = readFileSync(resolve(process.cwd(), 'Jenkinsfile'), 'utf8')
|
2026-08-24 14:21:43 +08:00
|
|
|
const dockerfile = readFileSync(resolve(process.cwd(), 'Dockerfile'), 'utf8')
|
2026-08-03 15:50:24 +08:00
|
|
|
|
|
|
|
|
describe('admin nginx deployment config', () => {
|
2026-08-04 14:15:32 +08:00
|
|
|
it('allows qualification uploads with multipart overhead through the API proxy', () => {
|
2026-08-05 09:11:48 +08:00
|
|
|
expect(config).toContain('client_max_body_size 12m;')
|
2026-08-04 14:15:32 +08:00
|
|
|
})
|
|
|
|
|
|
2026-08-03 15:50:24 +08:00
|
|
|
it('prevents the application shell from retaining stale chunk references', () => {
|
|
|
|
|
expect(config).toContain('location = /index.html')
|
|
|
|
|
expect(config).toContain('Cache-Control "no-cache, no-store, must-revalidate"')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('serves hashed assets immutably and never falls back missing chunks to HTML', () => {
|
|
|
|
|
expect(config).toContain('location /assets/')
|
|
|
|
|
expect(config).toContain('try_files $uri =404;')
|
|
|
|
|
expect(config).toContain('Cache-Control "public, max-age=31536000, immutable"')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('keeps Vue history routes on the application shell without caching them', () => {
|
|
|
|
|
expect(config).toContain('try_files $uri $uri/ /index.html;')
|
|
|
|
|
expect(config).toContain('Cache-Control "no-cache"')
|
|
|
|
|
})
|
2026-08-21 11:20:09 +08:00
|
|
|
|
|
|
|
|
it('proxies overseas API requests to the gateway API prefix', () => {
|
|
|
|
|
expect(config).toContain('location /overseas-api/')
|
|
|
|
|
expect(config).toContain('rewrite ^/overseas-api/(.*)$ /api/$1 break;')
|
|
|
|
|
expect(config).toContain('proxy_pass ${OVERSEAS_API_UPSTREAM};')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('declares an explicit overseas gateway upstream in container deployments', () => {
|
|
|
|
|
expect(testCompose).toContain('OVERSEAS_API_UPSTREAM: "http://host.docker.internal:9300"')
|
|
|
|
|
expect(developmentCompose).toContain('OVERSEAS_API_UPSTREAM: "http://host.docker.internal:9300"')
|
|
|
|
|
})
|
2026-08-24 14:00:55 +08:00
|
|
|
|
|
|
|
|
it('runs each deployment on its target node without controller-local SSH files', () => {
|
|
|
|
|
expect(jenkinsfile).toContain("env.JOB_BASE_NAME?.endsWith('-dev') ? 'java-dev' : 'java-test'")
|
2026-08-24 14:44:38 +08:00
|
|
|
expect(jenkinsfile).toContain("DEVELOPMENT_COMPOSE_PROJECT = 'admin-web'")
|
|
|
|
|
expect(jenkinsfile).toContain('docker compose -p "$DEVELOPMENT_COMPOSE_PROJECT" -f "$DEVELOPMENT_COMPOSE_FILE" up -d')
|
2026-08-24 14:00:55 +08:00
|
|
|
expect(jenkinsfile).not.toContain('/var/jenkins_home/.ssh')
|
|
|
|
|
expect(jenkinsfile).not.toContain('docker save')
|
|
|
|
|
expect(jenkinsfile).not.toMatch(/\bssh\b/)
|
|
|
|
|
})
|
2026-08-24 14:21:43 +08:00
|
|
|
|
|
|
|
|
it('uses authenticated internal base images in CI instead of pulling from Docker Hub', () => {
|
|
|
|
|
expect(dockerfile).toContain('ARG NODE_IMAGE=node:22-alpine')
|
|
|
|
|
expect(dockerfile).toContain('ARG NGINX_IMAGE=nginx:1.27-alpine')
|
|
|
|
|
expect(dockerfile).toContain('FROM ${NODE_IMAGE} AS build')
|
|
|
|
|
expect(dockerfile).toContain('FROM ${NGINX_IMAGE}')
|
2026-08-24 14:37:55 +08:00
|
|
|
expect(jenkinsfile).toContain("NODE_BASE_IMAGE = '172.31.198.7:10082/java-project/node:22-alpine'")
|
|
|
|
|
expect(jenkinsfile).toContain("NGINX_BASE_IMAGE = '172.31.198.7:10082/java-project/nginx:1.27-alpine'")
|
2026-08-24 14:21:43 +08:00
|
|
|
expect(jenkinsfile).toContain('withCredentials([usernamePassword(')
|
|
|
|
|
expect(jenkinsfile).toContain('export DOCKER_CONFIG="${WORKSPACE}@tmp/docker-auth"')
|
|
|
|
|
})
|
2026-08-03 15:50:24 +08:00
|
|
|
})
|