feat(writer-pipeline): newsproject.bitreport.pt writer cycle and WP env split
Tests / writer-pipeline tests (push) Failing after 5s
Tests / bridge tests (push) Failing after 6s
Tests / frontend lib tests (push) Successful in 14s
Tests / writer-pipeline tests (pull_request) Successful in 11s
Tests / bridge tests (pull_request) Successful in 13s
Tests / frontend lib tests (pull_request) Successful in 14s
Tests / writer-pipeline tests (push) Failing after 5s
Tests / bridge tests (push) Failing after 6s
Tests / frontend lib tests (push) Successful in 14s
Tests / writer-pipeline tests (pull_request) Successful in 11s
Tests / bridge tests (pull_request) Successful in 13s
Tests / frontend lib tests (pull_request) Successful in 14s
Add site-scoped WP credentials (NEWSPROJECT_* vs ANDEBOL_*), RSS sources config, systemd oneshot/timer offset from andebol, env template, and deployment docs so BIT-22288 covers both stacks. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
9d03d489e0
commit
7c0a515368
8 files changed
+224
-11
No files matched your search
@@ -0,0 +1,17 @@
|
||||
[Unit]
|
||||
Description=News Platform — Writer Pipeline (newsproject.bitreport.pt) single cycle
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
User=www-data
|
||||
Group=www-data
|
||||
WorkingDirectory=/opt/news-platform/writer-pipeline
|
||||
EnvironmentFile=/etc/news-platform/writer-newsproject.env
|
||||
ExecStart=/usr/bin/node dist/run-cycle.js --site newsproject.bitreport.pt --publish-max 2 --shortlist 8
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
SyslogIdentifier=news-writer-newsproject
|
||||
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=News Platform — Writer Pipeline (newsproject.bitreport.pt) daily timer
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* 06:45:00
|
||||
RandomizedDelaySec=300
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
@@ -0,0 +1,22 @@
|
||||
# Writer Pipeline — newsproject.bitreport.pt environment
|
||||
# Deploy to /etc/news-platform/writer-newsproject.env on the LXC
|
||||
# Secrets (WP app password) must be kept out of version control.
|
||||
|
||||
NODE_ENV=production
|
||||
|
||||
# WordPress REST API base (Docker compose default stack — port 8080)
|
||||
NEWSPROJECT_WP_BASE=http://127.0.0.1:8080/wp-json
|
||||
|
||||
# WordPress application credentials — generate in WP Users → Application Passwords
|
||||
NEWSPROJECT_WP_USER=writer-bot
|
||||
NEWSPROJECT_WP_APP_PASSWORD=xxxx xxxx xxxx xxxx xxxx xxxx
|
||||
|
||||
# Optional — public hostname for X-Site-Domain when the REST stack is multi-tenant
|
||||
# NEWSPROJECT_WP_SITE_DOMAIN=https://newsproject.bitreport.pt
|
||||
|
||||
# Optional — same WebDAV federation archive as andebol when enabled on the host (BIT-22292)
|
||||
# WRITER_WEBDAV_ENABLED=1
|
||||
# WRITER_WEBDAV_BASE_URL=https://…/remote.php/dav/files/<user>/<folder>/
|
||||
# WRITER_WEBDAV_USER=
|
||||
# WRITER_WEBDAV_PASSWORD=
|
||||
# WRITER_WEBDAV_DEFAULT_CREDIT=Foto: …
|
||||
@@ -288,6 +288,46 @@ Cycle output (metrics JSON) is also appended to `/opt/news-platform/writer-pipel
|
||||
|
||||
---
|
||||
|
||||
## Writer Pipeline — newsproject.bitreport.pt (systemd timer)
|
||||
|
||||
Same `run-cycle.js` binary as andebol.net, with **`--site newsproject.bitreport.pt`** and WordPress credentials from **`NEWSPROJECT_WP_*`** env vars (defaults to `http://127.0.0.1:8080/wp-json`). Source list: `writer-pipeline/config/newsproject.bitreport.pt.sources.json`.
|
||||
|
||||
The timer is offset from the andebol unit (**06:45** vs **06:00**) to reduce concurrent writes to the shared `var/aggregated-items.json` store.
|
||||
|
||||
### Files
|
||||
|
||||
| Repo path | CT destination |
|
||||
|-----------|----------------|
|
||||
| `deploy/systemd/news-writer-newsproject.service` | `/etc/systemd/system/news-writer-newsproject.service` |
|
||||
| `deploy/systemd/news-writer-newsproject.timer` | `/etc/systemd/system/news-writer-newsproject.timer` |
|
||||
| `deploy/systemd/writer-newsproject.env.example` | `/etc/news-platform/writer-newsproject.env` (fill secrets) |
|
||||
|
||||
### Install on the CT
|
||||
|
||||
```bash
|
||||
sudo cp /opt/news-platform/deploy/systemd/writer-newsproject.env.example \
|
||||
/etc/news-platform/writer-newsproject.env
|
||||
sudo chmod 640 /etc/news-platform/writer-newsproject.env
|
||||
sudo chown root:www-data /etc/news-platform/writer-newsproject.env
|
||||
# Edit NEWSPROJECT_WP_USER and NEWSPROJECT_WP_APP_PASSWORD
|
||||
|
||||
sudo cp /opt/news-platform/deploy/systemd/news-writer-newsproject.service \
|
||||
/etc/systemd/system/
|
||||
sudo cp /opt/news-platform/deploy/systemd/news-writer-newsproject.timer \
|
||||
/etc/systemd/system/
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable --now news-writer-newsproject.timer
|
||||
```
|
||||
|
||||
### Manual test run
|
||||
|
||||
```bash
|
||||
sudo systemctl start news-writer-newsproject.service
|
||||
journalctl -u news-writer-newsproject.service -n 50
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Future: Multi-Container
|
||||
|
||||
When the platform scales beyond a single test container, each service moves to its own LXC or VM:
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"site": "newsproject.bitreport.pt",
|
||||
"sources": [
|
||||
{
|
||||
"id": "record_pt_main",
|
||||
"kind": "rss",
|
||||
"url": "https://www.record.pt/rss/",
|
||||
"enabled": true,
|
||||
"maxItems": 20,
|
||||
"topics": ["pt", "sports", "media"],
|
||||
"note": "newsproject.bitreport.pt — general PT sports demo; not the andebol-only policy (see andebol.net.sources.json)."
|
||||
},
|
||||
{
|
||||
"id": "sapo_noticias",
|
||||
"kind": "rss",
|
||||
"url": "https://noticias.sapo.pt/rss",
|
||||
"enabled": true,
|
||||
"maxItems": 25,
|
||||
"topics": ["pt", "national", "international", "media"],
|
||||
"note": "SAPO highlights; editorial rewrite PT-PT when publishing."
|
||||
},
|
||||
{
|
||||
"id": "bbc_football",
|
||||
"kind": "rss",
|
||||
"url": "https://feeds.bbci.co.uk/sport/football/rss.xml",
|
||||
"enabled": true,
|
||||
"maxItems": 15,
|
||||
"topics": ["football", "international", "en"],
|
||||
"note": "BBC Sport football (EN); site locale is pt-PT — translate in downstream writer."
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
} from './token-metrics.js';
|
||||
import type { AggregatedItem, CycleMetrics } from './types.js';
|
||||
import { createDraftFromAggregatedItem } from './wp-publish.js';
|
||||
import { wpCredentialsForSite } from './wp-site-env.js';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const PKG_ROOT = path.resolve(__dirname, '..');
|
||||
@@ -84,19 +85,17 @@ async function main(): Promise<void> {
|
||||
const errors = [...ingest.errors];
|
||||
let draftsCreated = 0;
|
||||
|
||||
const wpBase = process.env.ANDEBOL_WP_BASE ?? 'http://127.0.0.1:8081/wp-json';
|
||||
const wpUser = process.env.ANDEBOL_WP_USER ?? '';
|
||||
const wpPass = process.env.ANDEBOL_WP_APP_PASSWORD ?? '';
|
||||
const wp = wpCredentialsForSite(site);
|
||||
|
||||
if (!dryRun && publishMax > 0 && wpUser && wpPass) {
|
||||
if (!dryRun && publishMax > 0 && wp.wpUser && wp.wpPass) {
|
||||
const toPublish = list.slice(0, publishMax);
|
||||
for (const item of toPublish) {
|
||||
try {
|
||||
const { id } = await createDraftFromAggregatedItem(item, {
|
||||
wpBase,
|
||||
username: wpUser,
|
||||
appPassword: wpPass,
|
||||
siteDomain: process.env.ANDEBOL_WP_SITE_DOMAIN,
|
||||
wpBase: wp.wpBase,
|
||||
username: wp.wpUser,
|
||||
appPassword: wp.wpPass,
|
||||
siteDomain: wp.siteDomain,
|
||||
});
|
||||
draftsCreated += 1;
|
||||
const updated: AggregatedItem = { ...item, wpDraftId: id };
|
||||
@@ -107,9 +106,7 @@ async function main(): Promise<void> {
|
||||
}
|
||||
await saveStore(storePath, store);
|
||||
} else if (!dryRun && publishMax > 0) {
|
||||
errors.push(
|
||||
'Skipping WP publish: set ANDEBOL_WP_USER and ANDEBOL_WP_APP_PASSWORD (optional ANDEBOL_WP_BASE)',
|
||||
);
|
||||
errors.push(`Skipping WP publish: set ${wp.envHint}`);
|
||||
}
|
||||
|
||||
const finishedAt = new Date().toISOString();
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { wpCredentialsForSite } from './wp-site-env.js';
|
||||
|
||||
const keysNews = [
|
||||
'NEWSPROJECT_WP_BASE',
|
||||
'NEWSPROJECT_WP_USER',
|
||||
'NEWSPROJECT_WP_APP_PASSWORD',
|
||||
'NEWSPROJECT_WP_SITE_DOMAIN',
|
||||
] as const;
|
||||
const keysAndebol = ['ANDEBOL_WP_BASE', 'ANDEBOL_WP_USER', 'ANDEBOL_WP_APP_PASSWORD'] as const;
|
||||
|
||||
function snapshotEnv<K extends string>(keys: readonly K[]): Record<K, string | undefined> {
|
||||
const o = {} as Record<K, string | undefined>;
|
||||
for (const k of keys) o[k] = process.env[k];
|
||||
return o;
|
||||
}
|
||||
|
||||
function restoreEnv<K extends string>(snap: Record<K, string | undefined>) {
|
||||
for (const k of Object.keys(snap) as K[]) {
|
||||
const v = snap[k];
|
||||
if (v === undefined) delete process.env[k];
|
||||
else process.env[k] = v;
|
||||
}
|
||||
}
|
||||
|
||||
test('wpCredentialsForSite uses NEWSPROJECT_* for newsproject.bitreport.pt', () => {
|
||||
const snap = snapshotEnv(keysNews);
|
||||
try {
|
||||
process.env.NEWSPROJECT_WP_BASE = 'http://example/wp-json';
|
||||
process.env.NEWSPROJECT_WP_USER = 'u';
|
||||
process.env.NEWSPROJECT_WP_APP_PASSWORD = 'p';
|
||||
process.env.NEWSPROJECT_WP_SITE_DOMAIN = 'https://newsproject.bitreport.pt';
|
||||
const c = wpCredentialsForSite('newsproject.bitreport.pt');
|
||||
assert.equal(c.wpBase, 'http://example/wp-json');
|
||||
assert.equal(c.wpUser, 'u');
|
||||
assert.equal(c.wpPass, 'p');
|
||||
assert.equal(c.siteDomain, 'https://newsproject.bitreport.pt');
|
||||
} finally {
|
||||
restoreEnv(snap);
|
||||
}
|
||||
});
|
||||
|
||||
test('wpCredentialsForSite defaults andebol WP base to 8081', () => {
|
||||
const snap = snapshotEnv(keysAndebol);
|
||||
try {
|
||||
delete process.env.ANDEBOL_WP_BASE;
|
||||
delete process.env.ANDEBOL_WP_USER;
|
||||
const c = wpCredentialsForSite('andebol.net');
|
||||
assert.equal(c.wpBase, 'http://127.0.0.1:8081/wp-json');
|
||||
} finally {
|
||||
restoreEnv(snap);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* WordPress REST credentials per writer `--site` (BIT-22288: andebol.net + newsproject).
|
||||
*/
|
||||
|
||||
export interface WpSiteCredentials {
|
||||
wpBase: string;
|
||||
wpUser: string;
|
||||
wpPass: string;
|
||||
siteDomain: string | undefined;
|
||||
/** Shown when publish is skipped due to missing secrets */
|
||||
envHint: string;
|
||||
}
|
||||
|
||||
export function wpCredentialsForSite(site: string): WpSiteCredentials {
|
||||
if (site === 'newsproject.bitreport.pt') {
|
||||
const wpBase =
|
||||
(process.env.NEWSPROJECT_WP_BASE ?? '').trim() || 'http://127.0.0.1:8080/wp-json';
|
||||
const wpUser = (process.env.NEWSPROJECT_WP_USER ?? '').trim();
|
||||
const wpPass = (process.env.NEWSPROJECT_WP_APP_PASSWORD ?? '').trim();
|
||||
const siteDomain = (process.env.NEWSPROJECT_WP_SITE_DOMAIN ?? '').trim() || undefined;
|
||||
return {
|
||||
wpBase,
|
||||
wpUser,
|
||||
wpPass,
|
||||
siteDomain,
|
||||
envHint: 'NEWSPROJECT_WP_USER and NEWSPROJECT_WP_APP_PASSWORD (optional NEWSPROJECT_WP_BASE, NEWSPROJECT_WP_SITE_DOMAIN)',
|
||||
};
|
||||
}
|
||||
|
||||
const wpBase = (process.env.ANDEBOL_WP_BASE ?? '').trim() || 'http://127.0.0.1:8081/wp-json';
|
||||
const wpUser = (process.env.ANDEBOL_WP_USER ?? '').trim();
|
||||
const wpPass = (process.env.ANDEBOL_WP_APP_PASSWORD ?? '').trim();
|
||||
const siteDomain = (process.env.ANDEBOL_WP_SITE_DOMAIN ?? '').trim() || undefined;
|
||||
return {
|
||||
wpBase,
|
||||
wpUser,
|
||||
wpPass,
|
||||
siteDomain,
|
||||
envHint: 'ANDEBOL_WP_USER and ANDEBOL_WP_APP_PASSWORD (optional ANDEBOL_WP_BASE, ANDEBOL_WP_SITE_DOMAIN)',
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user