Author SHA1 Message Date
Sluijsens 39c2ae6024 Merge pull request 'Pipeline: new names for variables and secrets, monitoring from the build environment, SSH key login' (#23) from feature/asf-pipeline-names into master
Continuous Integration / check (push) Successful in 4m21s
Continuous Integration / build-test (push) Successful in 1m41s
Continuous Integration / lighthouse (push) Successful in 10m20s
Continuous Integration / deploy-production (push) Skipped
Continuous Integration / deploy-test (push) Successful in 1m31s
2026-11-18 21:23:37 +01:00
11 changed files with 35 additions and 473 deletions
+6 -8
View File
@@ -369,16 +369,14 @@ jobs:
name: dist
path: web/dist
# Gewone FTP (het productiepakket biedt geen FTPS) naar de map met
# voorgerenderde pagina's van de CMS-host, in drie rondes (zie
# deploy/upload-production.sh): eerst alles behalve HTML, dan alle HTML,
# en pas daarna oude bestanden opruimen. Zo verwijst een bezoeker nooit
# naar een bestand dat er nog niet staat. De host zelf en zijn web.config
# komen uit de CMS-pijplijn. Deze job kan pas draaien als er een webhost is.
- name: Upload naar productie (gewone FTP)
# FTP met TLS (verplicht) naar de webhoster, in drie rondes (zie
# deploy/upload-production.sh): eerst alles behalve HTML en web.config,
# dan web.config en alle HTML, en pas daarna oude bestanden opruimen. Zo
# verwijst een bezoeker nooit naar een bestand dat er nog niet staat.
# Deze job kan pas draaien als er een webhost is.
- name: Upload naar productie (FTPS)
env:
FTP_HOST: ${{ secrets.PROD_HOST_ADDRESS }}
FTP_PORT: ${{ secrets.PROD_HOST_PORT }}
FTP_USER: ${{ secrets.PROD_HOST_USERNAME }}
LFTP_PASSWORD: ${{ secrets.PROD_HOST_PASSWORD }}
FTP_DIR: ${{ vars.PROD_DEPLOY_PATH || 'wwwroot' }}
+1 -1
View File
@@ -51,7 +51,7 @@ The hero of the homepage comes from the CMS hero module (`GET /api/v1/hero`); th
Decision (Bryan, 2026-11-15): the hosting package has one entry per website. The CMS host (Kestrel) is that entry and serves the website itself (the prerendered pages), `/admin` and `/api/v1/*`. In production IIS (or the proxy) therefore passes **all** requests to the CMS host, not only `/api/v1/*`, and serves no static files or HTML cache of its own. This holds for the test host and for ASF production alike.
- **Test (ASF):** nginx on the proxy Pi forwards everything for `test.andreaslop.nl` to the CMS host (`web/deploy/nginx/test.andreaslop.nl.proxy.conf`), which serves the site files and the API. Nothing to add.
- **Production: not in place yet.** The FTP upload (`web/deploy/upload-production.sh`) is now plain FTP into the CMS host's prerendered-pages folder and no longer puts a `web.config` on the server (the host's own `web.config` comes from the CMS pipeline). The generated `web/deploy/iis/web.config` still describes the old idea of IIS serving the files and has to change with the production hosting: IIS keeps only the redirects (www, HTTPS) and the pass-through to the CMS host, and the prerendered `dist/` goes to the CMS host's prerendered-pages folder as on test. Security headers then come from the CMS host (as on test). This is part of the production hosting work, not of the packages feature. Until then production builds use the committed snapshot and the live calls fail safely (the baked list stays; the browser console shows a 404 for the API). Change generated server files only in `web/config/serverConfig.ts` and run `pnpm server-config`.
- **Production: not in place yet.** The generated `web/deploy/iis/web.config` and the FTP upload of static files (`web/deploy/upload-production.sh`) still describe the old idea of IIS serving the files. They have to change with the production hosting: IIS keeps only the redirects (www, HTTPS) and the pass-through to the CMS host, and the prerendered `dist/` goes to the CMS host's prerendered-pages folder as on test. Security headers then come from the CMS host (as on test). This is part of the production hosting work, not of the packages feature. Until then production builds use the committed snapshot and the live calls fail safely (the baked list stays; the browser console shows a 404 for the API). Change generated server files only in `web/config/serverConfig.ts` and run `pnpm server-config`.
- **Host injection (built in the site; the host side is the CMS repo's work):** the build leaves markers in the prerendered pages and the CMS host fills them from live data, so a CMS change is visible to search engines at once without a rebuild. Contract and plan: `aidlc-docs/features/asf-cms-host-injection/plan.md`; golden files for the list HTML: `web/contract/host-injection/`.
- Markers: `<!--CMS:DATA-->` + `<script type="application/json" id="cms-data">` (root document, every page), `<!--CMS:OFFERINGS-HTML-->`, `<!--CMS:BANNER-TOP-HTML-->` and `<!--CMS:BANNER-BOTTOM-HTML-->` regions (home page), `<!--CMS:OFFER-JSON-LD slug="...">` before the ld+json block of the newborn, zwangerschap and gezin pages, and `<span data-cms-price="slug">` in their price block.
- In the page: `CmsRegion` renders the plain HTML between the markers (`lib/cmsHtml.ts`, styled by `.cms-*` rules in `theme.ts`) and React leaves it alone until hydration, so a host that wrote different data causes no hydration mismatch; after hydration the styled components take over. `PackagesProvider` reads the data block in the first render after hydration (`hostCmsData`); a block with `"source":"build"` is the baked one and counts as "no host data", so the page asks the API as before. The site address comes from `siteUrl` in the block (`setSiteUrl` in `client.tsx`), because the script files cannot be rewritten per host.
-4
View File
@@ -72,7 +72,3 @@ Format `{ENV}_{GROUP}_{NAME}` with `ENV` = `TEST` or `PROD`, no app part (this r
Removed: `PI_MAIN_*` (the SSH password login; the old secrets are deleted by Bryan after a green run), `DEPLOY_PATH_TEST`, `HEALTH_CHECK_URL_TEST`, `HEALTH_CHECK_URL_PRODUCTION`, `FTP_REMOTE_DIR`, `FTP_HOST`, `FTP_USERNAME`, `FTP_PASSWORD` (renamed), `ASF_OFFERINGS_URL_TEST` and `ASF_TEST_SERVED_BY_CMS` (no longer needed). The old names in the repo are removed by SLS after a green run.
**Monitoring per build.** Sentry and Umami settings are no longer in the code (`src/monitoring/config.ts`): every build gets them for its own environment and measures only on that environment's host (production build on `andreaslop.nl`, test build on `test.andreaslop.nl`; any other host measures nothing). The CSP origins for Umami and Sentry (`config/securityHeaders.ts`) come from the same variables, so a build without them has neither a measurement nor those origins; the build steps fail when a variable is empty. Unit and browser tests use the production values from `config/monitoringTestEnv.ts` (public values, the same as the variables); `pnpm server-config` does too, so the committed generated files carry the production CSP. The CMS host has its own copy of the origins in its environment (CMS repo).
## Plain FTP to production
The production package only offers plain FTP, no FTPS or SFTP. `deploy/upload-production.sh` therefore never tries TLS (`ftp:ssl-allow no`, passive mode) and sends the user name, the password and the files unencrypted. Measures: a separate FTP account with rights only on the folder of the prerendered pages, a unique strong password that only exists as the secret `PROD_HOST_PASSWORD`, rotating it after the first rollout, and asking the host whether SFTP or explicit FTPS can be switched on. The script uploads in three rounds (everything except HTML, then all HTML, then cleaning up old files) into the prerendered-pages folder of the CMS host (`PROD_DEPLOY_PATH`, the exact folder is still open, see `aidlc-docs/features/asf-production-iis/plan.md`, A2). It does not put a `web.config` there and deletes nothing outside that folder; the host and its `web.config` come from the CMS pipeline. `PROD_HOST_PORT` is optional (default 21).
-48
View File
@@ -1,48 +0,0 @@
# Redirects of the old WordPress addresses (redirects.json)
The old site of andreaslop.nl was a WordPress site. Its addresses that are still indexed get a redirect (or "gone") on the new site. The site is the source of the list; the CMS host reads it and applies it the same on test and on production. The inventory of the old addresses is in `aidlc-docs/features/asf-production-iis/oude-urls.md`.
## Where it comes from
- The list is in code: `web/config/redirectRules.ts` (with tests in `redirectRules.test.ts`).
- `pnpm build` ends with `web/config/writeRedirects.ts`, which writes `dist/client/redirects.json`, next to `index.html`. The deploy puts it in the prerendered-pages folder of the host (on test with the rest of `dist-test`, on production with the FTP upload). `deploy/check-artifact.sh` refuses a build without it.
- Change the list only in `redirectRules.ts`; the file is never edited by hand.
## Format (agreed with the CMS session, design of 2026-11-18)
```json
{
"version": 1,
"redirects": [
{ "from": "/portfolio-item/decoration", "to": "/portfolio", "status": 301 },
{ "from": "/feed", "status": 410 }
]
}
```
- `from`: a path with one leading slash, without query string, fragment or `..`. The first segment is never `admin`, `health` or `api`. The host matches it case insensitive and with or without a slash at the end, so a path is given once (both forms count as a duplicate).
- `status`: `301`, `404` or `410`.
- `to`: required for a 301 (a path of this site, or an absolute `https://` address; this list only uses paths) and not allowed for 404 and 410. It is never the same as `from`, and never itself a rule (no chains).
- No patterns, no wildcards, no query-string rules (decision of Bryan: only plain paths). At most 5000 rules and 1 MB.
- The host answers a 301 with `Location` and `Cache-Control: max-age=3600`, a 404 or 410 with the 404 page of the site as the body. A rule wins over an existing file. Only GET and HEAD. `redirects.json` itself is not served.
## What is in the list
| Old address | Answer |
| ---------------------------------------------------------------------------------------- | --------------------- |
| `/sitemap_index.xml`, `/wp-sitemap.xml` and the five old sub-sitemaps | 301 to `/sitemap.xml` |
| `/portfolio-item` and the 15 items of the old sitemap | 301 to `/portfolio` |
| `/portfolio-tag/{homepage,portfolio-gallerij,simple}` | 301 to `/portfolio` |
| `/testimonials-category/photo` | 301 to `/` |
| `/masonry-gallery-category/test-masonry-gallery` (theme demo), `/feed`, `/comments/feed` | 410 |
Not in the list on purpose:
- The real pages (`/over-mij/`, `/portfolio/`, `/soorten-fotoshoots/`, `/contact/`): the host redirects the slash, case and `.html` variants canonically (`web/config/canonicalUrls.ts`); the slugs are the same as on the new site.
- Query-string addresses (`/?page_id=17`, `/?s=...`): decision of Bryan.
- Addresses that are a 404 anyway: `/wp-admin`, `/wp-login.php`, `/xmlrpc.php`, `/wp-json`, `/wp-content`, `/category`, `/tag`, `/author`. A path without a rule gives the 404 page already.
## Open
- Whether to check Google Search Console and external links (Instagram, Google Business Profile) for other old addresses before the old site is switched off; if there are any, add them to `redirectRules.ts`.
- After the host reads the file (CMS repo, small PR of SMC): add a check to `deploy/verify-deployment.sh --cms` that `/portfolio-item/decoration/` gives a 301 to `/portfolio`.
-173
View File
@@ -1,173 +0,0 @@
import { describe, expect, it } from 'vitest';
import {
MAX_REDIRECTS,
REDIRECT_FORMAT_VERSION,
redirectProblems,
redirectRules,
redirectTargets,
redirectsJson,
type RedirectRule,
} from './redirectRules';
// What the host does with the file (the format is in docs/redirect-rules.md);
// the host has its own implementation and tests
function resolve(rules: readonly RedirectRule[], rawPath: string) {
const path = rawPath.toLowerCase().replace(/\/+$/, '') || '/';
return rules.find((rule) => rule.from.toLowerCase() === path);
}
describe('redirectRules', () => {
it('has no problems', () => {
expect(redirectProblems(redirectRules)).toEqual([]);
});
it('sends every 301 to a page of the site or the sitemap', () => {
for (const rule of redirectRules.filter((r) => r.status === 301)) {
expect(redirectTargets).toContain(rule.to);
}
});
it.each([
['/sitemap_index.xml', 301, '/sitemap.xml'],
['/wp-sitemap.xml', 301, '/sitemap.xml'],
['/page-sitemap.xml', 301, '/sitemap.xml'],
['/portfolio-item-sitemap.xml', 301, '/sitemap.xml'],
['/masonry-gallery-category-sitemap.xml', 301, '/sitemap.xml'],
['/portfolio-tag-sitemap.xml', 301, '/sitemap.xml'],
['/testimonials-category-sitemap.xml', 301, '/sitemap.xml'],
['/portfolio-item/', 301, '/portfolio'],
['/portfolio-item/decoration/', 301, '/portfolio'],
['/portfolio-item/wedding-dress/', 301, '/portfolio'],
['/portfolio-item/best-girls/', 301, '/portfolio'],
['/portfolio-item/mm-1/', 301, '/portfolio'],
['/portfolio-item/wedding-cake/', 301, '/portfolio'],
['/portfolio-item/mm2/', 301, '/portfolio'],
['/portfolio-item/cake-smash-1/', 301, '/portfolio'],
['/portfolio-item/hairstyles/', 301, '/portfolio'],
['/portfolio-item/360/', 301, '/portfolio'],
['/portfolio-item/366/', 301, '/portfolio'],
['/portfolio-item/353/', 301, '/portfolio'],
['/portfolio-item/homepage-foto/', 301, '/portfolio'],
['/portfolio-item/getting-ready/', 301, '/portfolio'],
['/portfolio-item/m1/', 301, '/portfolio'],
['/portfolio-item/f1/', 301, '/portfolio'],
['/Portfolio-Item/MM1', undefined, undefined],
['/portfolio-item/MM-1', 301, '/portfolio'],
['/portfolio-tag/homepage/', 301, '/portfolio'],
['/portfolio-tag/portfolio-gallerij/', 301, '/portfolio'],
['/portfolio-tag/simple/', 301, '/portfolio'],
['/testimonials-category/photo/', 301, '/'],
['/masonry-gallery-category/test-masonry-gallery/', 410, undefined],
['/feed/', 410, undefined],
['/comments/feed/', 410, undefined],
])('%s gives %s %s', (path, status, to) => {
const rule = resolve(redirectRules, path);
expect(rule?.status).toBe(status);
expect(rule?.to).toBe(to);
});
it('leaves the real pages and their canonical variants to the host', () => {
for (const path of [
'/',
'/over-mij',
'/over-mij/',
'/portfolio',
'/soorten-fotoshoots/newborn',
'/contact',
'/robots.txt',
'/sitemap.xml',
'/assets/index-abc.js',
'/admin/',
'/api/v1/offerings',
'/wp-login.php',
]) {
expect(resolve(redirectRules, path)).toBeUndefined();
}
});
});
describe('redirectProblems', () => {
const rule = (extra: Partial<RedirectRule>): RedirectRule => ({
from: '/a',
to: '/b',
status: 301,
...extra,
});
it.each([
[rule({ from: 'a' }), 'not a usable path'],
[rule({ from: '/' }), 'not a usable path'],
[rule({ from: '//a' }), 'not a usable path'],
[rule({ from: '/a/../b' }), 'not a usable path'],
[rule({ from: '/a?x=1' }), 'not a usable path'],
[rule({ from: '/a#b' }), 'not a usable path'],
[rule({ from: '/Admin/x' }), 'answered by the host'],
[rule({ from: '/api/v1' }), 'answered by the host'],
[rule({ from: '/health' }), 'answered by the host'],
[rule({ to: undefined }), 'needs a path'],
[rule({ to: 'https://evil.example/' }), 'needs a path'],
[rule({ to: '//evil.example' }), 'needs a path'],
[rule({ to: '/A/' }), 'the same'],
[rule({ status: 410 }), 'only a 301 has a target'],
[rule({ status: 404 }), 'only a 301 has a target'],
])('flags %j', (bad, text) => {
expect(redirectProblems([bad]).join()).toContain(text);
});
it('flags a duplicate, also in another case or with a slash', () => {
expect(redirectProblems([rule({}), rule({})]).join()).toContain(
'duplicate',
);
expect(
redirectProblems([
rule({ from: '/A' }),
rule({ from: '/a/' }),
]).join(),
).toContain('duplicate');
});
it('flags a chain', () => {
expect(
redirectProblems([
rule({ from: '/a', to: '/b' }),
rule({ from: '/b', to: '/c' }),
]).join(),
).toContain('is a rule too');
});
it('flags too many rules', () => {
const many = Array.from({ length: MAX_REDIRECTS + 1 }, (_, i) =>
rule({ from: `/p${i}`, to: '/x' }),
);
expect(redirectProblems(many).join()).toContain('more than');
});
it('accepts a 404 and a 410 without a target', () => {
expect(
redirectProblems([
rule({ status: 404, to: undefined }),
rule({ from: '/b', status: 410, to: undefined }),
]),
).toEqual([]);
});
});
describe('redirectsJson', () => {
it('writes the version and the redirects', () => {
const parsed = JSON.parse(redirectsJson());
expect(parsed.version).toBe(REDIRECT_FORMAT_VERSION);
expect(parsed.redirects).toEqual(redirectRules);
expect(Object.keys(parsed)).toEqual(['version', 'redirects']);
expect(redirectsJson().endsWith('\n')).toBe(true);
});
it('stays far below the size limit of the host', () => {
expect(redirectsJson().length).toBeLessThan(100_000);
});
it('refuses a list with problems', () => {
expect(() => redirectsJson([{ from: 'x', status: 404 }])).toThrow(
'Invalid redirect rules',
);
});
});
-155
View File
@@ -1,155 +0,0 @@
// Redirects for the old WordPress addresses of andreaslop.nl (decision of
// Bryan, 2026-11-18; the inventory is aidlc-docs/features/asf-production-iis/
// oude-urls.md). The site is the source: this list is written into the build
// as redirects.json and the CMS host reads it, the same on test and on
// production. The format is the one of the host (design of SMC, 2026-11-18):
// exact paths only, no patterns; see docs/redirect-rules.md.
//
// Not in this list: the slash, case and .html variants of the real pages
// (/over-mij/ and so on; the host redirects those canonically, see
// config/canonicalUrls.ts), query-string addresses (?page_id=, decision of
// Bryan) and addresses that are a 404 anyway (/wp-admin, /wp-login.php,
// /xmlrpc.php, /wp-json, /wp-content, /category, /tag, /author, /?s=): an
// unknown path gives the 404 page without a rule.
import { pagePaths } from './canonicalUrls.ts';
export type RedirectStatus = 301 | 404 | 410;
export interface RedirectRule {
// A path with one leading slash. The host matches it case insensitive and
// with or without a slash at the end (so give it once).
from: string;
// Only for 301: a path of this site
to?: string;
status: RedirectStatus;
}
export const REDIRECT_FORMAT_VERSION = 1;
export const MAX_REDIRECTS = 5000;
// The host answers these paths itself; a rule there would never be read
const RESERVED_FIRST_SEGMENTS = ['admin', 'health', 'api'];
const permanent = (from: string, to: string): RedirectRule => ({
from,
to,
status: 301,
});
const gone = (from: string): RedirectRule => ({ from, status: 410 });
// The old sitemaps: search engines find the new one
const sitemaps = [
'/sitemap_index.xml',
'/wp-sitemap.xml',
'/page-sitemap.xml',
'/portfolio-item-sitemap.xml',
'/masonry-gallery-category-sitemap.xml',
'/portfolio-tag-sitemap.xml',
'/testimonials-category-sitemap.xml',
];
// The gallery items of the theme (from the old sitemap, 2026-11-18): the
// portfolio is the nearest page
const portfolioItems = [
'decoration',
'wedding-dress',
'best-girls',
'mm-1',
'wedding-cake',
'mm2',
'cake-smash-1',
'hairstyles',
'360',
'366',
'353',
'homepage-foto',
'getting-ready',
'm1',
'f1',
];
const portfolioTags = ['homepage', 'portfolio-gallerij', 'simple'];
export const redirectRules: readonly RedirectRule[] = [
...sitemaps.map((from) => permanent(from, '/sitemap.xml')),
permanent('/portfolio-item', '/portfolio'),
...portfolioItems.map((name) =>
permanent(`/portfolio-item/${name}`, '/portfolio'),
),
...portfolioTags.map((name) =>
permanent(`/portfolio-tag/${name}`, '/portfolio'),
),
// The theme archive of testimonials: they are on the home page
permanent('/testimonials-category/photo', '/'),
// Theme demo content and the feeds: no equivalent and no berichten
gone('/masonry-gallery-category/test-masonry-gallery'),
gone('/feed'),
gone('/comments/feed'),
];
const pathPattern = /^\/[A-Za-z0-9._~/%-]*$/;
const isPath = (value: string): boolean =>
pathPattern.test(value) && !value.startsWith('//') && !value.includes('..');
// What the host compares: lower case, without a slash at the end
const key = (path: string): string =>
path.toLowerCase().replace(/\/+$/, '') || '/';
// The reasons a rule list is not usable; empty when it is. The host validates
// the file again; the tests check this list and what is written from it.
export function redirectProblems(rules: readonly RedirectRule[]): string[] {
const problems: string[] = [];
if (rules.length > MAX_REDIRECTS) {
problems.push(`more than ${MAX_REDIRECTS} rules`);
}
const froms = new Map<string, RedirectRule>();
rules.forEach((rule, index) => {
const label = `rule ${index + 1} (${rule.from})`;
if (!isPath(rule.from) || rule.from === '/') {
problems.push(`${label}: from is not a usable path`);
return;
}
const first = key(rule.from).split('/')[1];
if (RESERVED_FIRST_SEGMENTS.includes(first)) {
problems.push(`${label}: ${first} is answered by the host itself`);
}
if (froms.has(key(rule.from))) problems.push(`${label}: duplicate`);
froms.set(key(rule.from), rule);
if (rule.status === 301) {
if (!rule.to || !isPath(rule.to)) {
problems.push(
`${label}: a 301 needs a path of this site in to`,
);
} else if (key(rule.to) === key(rule.from)) {
problems.push(`${label}: from and to are the same`);
}
} else if (rule.to !== undefined) {
problems.push(`${label}: only a 301 has a target`);
}
});
// No chains: a target is never itself a rule (the host would flatten it,
// or it is gone)
for (const rule of rules) {
if (rule.status === 301 && rule.to && froms.has(key(rule.to))) {
problems.push(
`rule ${rule.from}: the target ${rule.to} is a rule too`,
);
}
}
return problems;
}
// The pages a 301 may point to: every page of the site and the sitemap
export const redirectTargets: readonly string[] = [
...pagePaths,
'/sitemap.xml',
];
export function redirectsJson(
rules: readonly RedirectRule[] = redirectRules,
): string {
const problems = redirectProblems(rules);
if (problems.length > 0) {
throw new Error(`Invalid redirect rules:\n${problems.join('\n')}`);
}
return `${JSON.stringify({ version: REDIRECT_FORMAT_VERSION, redirects: rules }, null, 2)}\n`;
}
-10
View File
@@ -1,10 +0,0 @@
// Writes redirects.json next to the pages of the build (the last step of
// pnpm build, after externalizeInlineScripts). Runs directly with Node.
import { mkdirSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { redirectsJson } from './redirectRules.ts';
const outDir = process.argv[2] ?? join('dist', 'client');
mkdirSync(outDir, { recursive: true });
writeFileSync(join(outDir, 'redirects.json'), redirectsJson());
console.log(`redirects.json written to ${outDir}`);
+1 -1
View File
@@ -22,7 +22,7 @@ fail() {
failures=$((failures + 1))
}
for file in index.html 404.html over-mij.html redirects.json; do
for file in index.html 404.html over-mij.html; do
if [ -f "$dist/$file" ]; then
echo "gevonden: $file"
else
+13 -21
View File
@@ -1,13 +1,7 @@
#!/usr/bin/env bash
# Upload naar productie in drie rondes (BR-HST-14, 15; FR-PR-18).
# Gebruik: upload-production.sh <dist-map> <doelmap-op-de-server>
# De doelmap is de map met voorgerenderde pagina's van de CMS-host; de host
# (en zijn web.config) staat er los van en wordt door de CMS-pijplijn gedeployd.
# Verbinding: FTP_HOST, FTP_USER en LFTP_PASSWORD uit de omgeving, optioneel
# FTP_PORT. Gewone FTP, geen FTPS: het productiepakket biedt alleen dat. De
# gegevens gaan dus onversleuteld over het netwerk (zie docs/deploy-and-ci.md,
# "Plain FTP"); daarom nooit TLS proberen en een eigen FTP-account met rechten
# alleen op deze map.
# Verbinding: FTP_HOST, FTP_USER en LFTP_PASSWORD uit de omgeving (FTPS).
# Alleen voor de test: LFTP_OPEN (bijvoorbeeld file:///) vervangt de
# verbinding, en UPLOAD_PASS=1|2|3 voert maar één ronde uit.
set -euo pipefail
@@ -42,6 +36,7 @@ done
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
bash "$here/check-artifact.sh" "$dist"
cp "$here/iis/web.config" "$dist/web.config"
pass="${UPLOAD_PASS:-all}"
case "$pass" in
@@ -53,7 +48,7 @@ wants() { [ "$pass" = all ] || [ "$pass" = "$1" ]; }
# Geen back-ups: lftp zet standaard een kopie met een tijdstempel
# (web.config~20261101221045~) naast elk bestand dat het overschrijft. Op de
# host zou elke deploy er een achterlaten, bereikbaar voor wie de naam raadt.
settings="set ftp:ssl-allow no; set ftp:passive-mode on; set net:max-retries 3; set xfer:make-backup no;"
settings="set ftp:ssl-force true; set ftp:ssl-protect-data true; set net:max-retries 3; set xfer:make-backup no;"
# Elke opdracht krijgt een eigen lftp-sessie, zodat het script bij een mislukte
# ronde stopt (set -e) voordat de volgende ronde begint: de HTML gaat nooit
@@ -65,25 +60,22 @@ run_lftp() {
else
: "${FTP_HOST:?FTP_HOST ontbreekt}" "${FTP_USER:?FTP_USER ontbreekt}"
: "${LFTP_PASSWORD:?LFTP_PASSWORD ontbreekt}"
local port=()
if [ -n "${FTP_PORT:-}" ]; then
[[ "$FTP_PORT" =~ ^[0-9]+$ ]] || { echo "Ongeldige FTP_PORT" >&2; exit 2; }
port=(-p "$FTP_PORT")
fi
lftp --env-password -u "$FTP_USER" "${port[@]}" "$FTP_HOST" -e "$commands"
lftp --env-password -u "$FTP_USER" "$FTP_HOST" -e "$commands"
fi
}
# Ronde 1: alles behalve HTML, dus ook /assets. Nieuwe bestanden met hash in
# de naam storen de oude release niet.
# Ronde 1: alles behalve HTML en web.config, dus ook /assets. Nieuwe
# bestanden met hash in de naam storen de oude release niet.
if wants 1; then
echo "== Ronde 1: alles behalve HTML"
run_lftp "mirror --reverse --verbose --exclude-glob '*.html' $dist/ $remote/;"
echo "== Ronde 1: alles behalve HTML en web.config"
run_lftp "mirror --reverse --verbose --exclude-glob '*.html' --exclude-glob web.config $dist/ $remote/;"
fi
# Ronde 2: alle HTML, ook de geneste pagina's en 404.html. Pas nu verwijst
# iets naar de nieuwe assets.
# Ronde 2: web.config vlak voor de HTML (de regels passen bij de nieuwe
# bestanden), dan alle HTML, ook de geneste pagina's en 404.html. Pas nu
# verwijst iets naar de nieuwe assets.
if wants 2; then
echo "== Ronde 2: alle HTML"
echo "== Ronde 2: web.config en alle HTML"
run_lftp "put -O $remote $dist/web.config;"
run_lftp "mirror --reverse --verbose --include-glob '*.html' $dist/ $remote/;"
fi
# Ronde 3: opruimen als laatste, zodat bezoekers met de oude HTML hun oude
+13 -51
View File
@@ -539,6 +539,7 @@ describe.skipIf(toolsMissing || lftpMissing)('upload-production.sh', () => {
'robots.txt',
'soorten-fotoshoots/newborn.html',
'stale.txt',
'web.config',
]);
const third = await upload(dist, target, '3');
@@ -550,6 +551,7 @@ describe.skipIf(toolsMissing || lftpMissing)('upload-production.sh', () => {
'over-mij.html',
'robots.txt',
'soorten-fotoshoots/newborn.html',
'web.config',
]);
});
@@ -565,18 +567,19 @@ describe.skipIf(toolsMissing || lftpMissing)('upload-production.sh', () => {
);
expect(rounds).toEqual(['1', '2', '3']);
const expected = [...validFiles].sort();
const expected = [...validFiles, 'web.config'].sort();
expect(await tree(target)).toEqual(expected);
});
it('laat bij een tweede deploy geen back-upbestanden met ~ achter', async () => {
const { dist, target } = await setup();
expect((await upload(dist, target)).code).toBe(0);
// Nu bestaat alles al op de host en wordt het overschreven
// Nu bestaat web.config al op de host, en alles wordt overschreven
await write(dist, 'robots.txt', 'nieuwe inhoud');
expect((await upload(dist, target)).code).toBe(0);
const files = await tree(target);
expect(files.filter((file) => file.includes('~'))).toEqual([]);
expect(files).toContain('web.config');
});
it('weigert een ongeldige build en uploadt dan niets', async () => {
@@ -587,12 +590,13 @@ describe.skipIf(toolsMissing || lftpMissing)('upload-production.sh', () => {
expect(await tree(target)).toEqual(['stale.txt']);
});
it('zet geen web.config op de server: die hoort bij de CMS-host', async () => {
it('neemt de web.config uit deploy/iis over', async () => {
const { dist, target } = await setup();
const run = await upload(dist, target);
expect(run.code).toBe(0);
expect(existsSync(join(target, 'web.config'))).toBe(false);
expect(existsSync(join(dist, 'web.config'))).toBe(false);
expect(await readFile(join(target, 'web.config'), 'utf8')).toBe(
await readFile(join(deployDir, 'iis/web.config'), 'utf8'),
);
});
});
@@ -662,7 +666,7 @@ touch '${slash(marker)}'
},
);
it('zet in elke lftp-sessie de back-ups uit en TLS uit (gewone FTP)', async () => {
it('zet in elke lftp-sessie de back-ups uit en de TLS-eisen aan', async () => {
const dist = await makeDist();
const bin = await makeTemp('andreaslop-fakebin-');
const log = join(bin, 'opdrachten');
@@ -686,53 +690,11 @@ printf '%s\\n' "$2" >> '${slash(log)}'
const sessions = (await readFile(log, 'utf8'))
.split('\n')
.filter(Boolean);
// Ronde 1, ronde 2 (HTML) en ronde 3
expect(sessions).toHaveLength(3);
// Ronde 1, web.config, ronde 2 (HTML) en ronde 3
expect(sessions).toHaveLength(4);
for (const commands of sessions) {
expect(commands).toContain('set xfer:make-backup no;');
expect(commands).toContain('set ftp:ssl-allow no;');
expect(commands).toContain('set ftp:passive-mode on;');
expect(commands).not.toContain('ssl-force');
}
});
it('geeft FTP_PORT door aan lftp en weigert een ongeldige poort', async () => {
const dist = await makeDist();
const bin = await makeTemp('andreaslop-fakebin-');
const log = join(bin, 'argumenten');
await writeFile(
join(bin, 'lftp'),
`#!/bin/sh
printf '%s\n' "$*" >> '${slash(log)}'
`,
{ mode: 0o755 },
);
const env = {
PATH: `${bin}${delimiter}${process.env.PATH ?? ''}`,
FTP_HOST: 'ftp.example.test',
FTP_USER: 'gebruiker',
LFTP_PASSWORD: 'geheim',
};
const bad = await runScript(
'upload-production.sh',
[basename(dist), 'wwwroot'],
{ ...env, FTP_PORT: '21; rm -rf' },
dirname(dist),
);
expect(bad.code).toBe(2);
expect(existsSync(log)).toBe(false);
const good = await runScript(
'upload-production.sh',
[basename(dist), 'wwwroot'],
{ ...env, FTP_PORT: '2121' },
dirname(dist),
);
expect(good.code).toBe(0);
for (const line of (await readFile(log, 'utf8'))
.split('\n')
.filter(Boolean)) {
expect(line).toContain('-u gebruiker -p 2121 ftp.example.test');
expect(commands).toContain('set ftp:ssl-force true;');
}
});
+1 -1
View File
@@ -6,7 +6,7 @@
"packageManager": "pnpm@12.11.2",
"scripts": {
"dev": "vite",
"build": "node config/fetchOfferings.ts && tsc && vite build && node config/externalizeInlineScripts.ts && node config/writeRedirects.ts",
"build": "node config/fetchOfferings.ts && tsc && vite build && node config/externalizeInlineScripts.ts",
"preview": "node config/previewServer.ts",
"e2e": "vitest run --config vitest.e2e.config.ts",
"postinstall": "chakra typegen ./src/theme.ts",