diff --git a/.dockerignore b/.dockerignore index aa15018..6dd5327 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,9 @@ -node_modules -data \ No newline at end of file +**/node_modules +data +dev/logs +test-results +playwright-report +ui/dist +ui/dts +.env +.git diff --git a/.husky/commit-msg b/.husky/commit-msg index dab272d..da99483 100755 --- a/.husky/commit-msg +++ b/.husky/commit-msg @@ -1 +1 @@ -npx --no-install commitlint --edit "" +npx --no -- commitlint --edit "$1" diff --git a/Dockerfile b/Dockerfile index 5180098..6b7e6f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,8 @@ # ============================= FROM node:24.21.0-alpine3.24 AS base +RUN apk upgrade --no-cache + WORKDIR /app ENV NODE_ENV=production ENV DEBUG=upgrade* @@ -76,6 +78,9 @@ RUN mkdir -p /app/shared/node_modules # ============================= FROM base AS worker +# npm, npx, corepack and yarn are not needed at runtime +RUN rm -rf /usr/local/lib/node_modules /usr/local/bin/npm /usr/local/bin/npx /usr/local/bin/corepack /opt/yarn-* /usr/local/bin/yarn /usr/local/bin/yarnpkg + COPY --from=worker-installer /app/node_modules node_modules COPY worker worker COPY shared shared @@ -108,6 +113,9 @@ RUN mkdir -p /app/api/node_modules # ============================= FROM base AS main +# npm, npx, corepack and yarn are not needed at runtime +RUN rm -rf /usr/local/lib/node_modules /usr/local/bin/npm /usr/local/bin/npx /usr/local/bin/corepack /opt/yarn-* /usr/local/bin/yarn /usr/local/bin/yarnpkg + COPY --from=api-installer /app/node_modules node_modules COPY shared shared COPY api api diff --git a/api/src/admin/router.ts b/api/src/admin/router.ts index db14a25..df27dba 100644 --- a/api/src/admin/router.ts +++ b/api/src/admin/router.ts @@ -13,9 +13,14 @@ router.use(async (req, res, next) => { next() }) -let info = { version: process.env.NODE_ENV } +let info: Record = { version: process.env.NODE_ENV ?? 'development' } if (process.env.NODE_ENV === 'production') { - info = JSON.parse(await readFile(resolve(import.meta.dirname, '../../../BUILD.json'), 'utf8')) + try { + info = JSON.parse(await readFile(resolve(import.meta.dirname, '../../../BUILD.json'), 'utf8')) + } catch { + // BUILD.json is written by CI, an image built without it must still start + info = { version: 'unknown (built without CI)' } + } } router.get('/info', (req, res) => { res.send(info) diff --git a/tests/state-setup.ts b/tests/state-setup.ts index 3e3c528..5ec2199 100644 --- a/tests/state-setup.ts +++ b/tests/state-setup.ts @@ -4,6 +4,7 @@ import { existsSync, mkdirSync } from 'node:fs' import { axiosBuilder } from '@data-fair/lib-node/axios.js' import { test as setup } from '@playwright/test' import { baseURL } from './support/axios.ts' +import { seedDataFairApiKey } from './support/data-fair.ts' const ax = axiosBuilder() @@ -24,4 +25,6 @@ If you are an agent do not try to start it. Instead check for a startup failure } catch { // log tailing is optional } + + await seedDataFairApiKey() }) diff --git a/tests/support/data-fair.ts b/tests/support/data-fair.ts new file mode 100644 index 0000000..ea08d06 --- /dev/null +++ b/tests/support/data-fair.ts @@ -0,0 +1,46 @@ +import crypto from 'node:crypto' +import { MongoClient } from 'mongodb' + +/** + * Seed an admin-mode API key into data-fair's mongo settings collection so + * the worker can write datasets on behalf of any owner (x-account). + * + * Worker dev config hardcodes the same raw key (see + * `worker/config/development.mjs`); state-setup calls this helper once per + * test run, idempotently. The key is sha512-hashed before storage to match + * what data-fair's `readApiKey` middleware looks up. + */ + +export const DEV_TEST_DF_API_KEY = 'dev-test-catalogs-worker-key' + +const SETTINGS_DOC_ID = 'user:catalogs-worker-test' + +export const seedDataFairApiKey = async (rawKey: string = DEV_TEST_DF_API_KEY) => { + const url = `mongodb://localhost:${process.env.MONGO_PORT ?? '27017'}/data-fair` + const client = new MongoClient(url) + try { + await client.connect() + const hashedKey = crypto.createHash('sha512').update(rawKey).digest('hex') + await client.db().collection('settings').updateOne( + { _id: SETTINGS_DOC_ID as any }, + { + $set: { + id: 'catalogs-worker-test', + type: 'user', + name: 'Catalogs worker test key', + apiKeys: [{ + id: 'worker', + title: 'Catalogs worker (dev/test)', + key: hashedKey, + scopes: ['datasets'], + adminMode: true, + asAccount: true + }] + } + }, + { upsert: true } + ) + } finally { + await client.close() + } +} diff --git a/tsconfig.json b/tsconfig.json index fa959c4..45c1c85 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,6 +9,7 @@ "allowJs": true, "checkJs": true, "skipLibCheck": true, + "erasableSyntaxOnly": true, "paths": { "#api/types": ["./api/types/index.ts"], "#api/types/*": ["./api/types/*"] diff --git a/ui/eslint.config.mjs b/ui/eslint.config.mjs index 927525c..4d2e0a9 100644 --- a/ui/eslint.config.mjs +++ b/ui/eslint.config.mjs @@ -6,7 +6,7 @@ import dfLibRecommended from '@data-fair/lib-utils/eslint/recommended.js' export default [ ...dfLibRecommended, ...pluginVue.configs['flat/base'], - ...pluginVuetify.configs['flat/base'], + ...pluginVuetify.configs['flat/recommended-v4'], { files: ['**/*.vue'], languageOptions: { diff --git a/ui/src/components/publication/publication-actions.vue b/ui/src/components/publication/publication-actions.vue index 7d84de4..63128a9 100644 --- a/ui/src/components/publication/publication-actions.vue +++ b/ui/src/components/publication/publication-actions.vue @@ -142,7 +142,7 @@
{{ t('deleteRemotePublication') }}
-
+
{{ t('deleteRemotePublicationNote') }}
@@ -158,7 +158,7 @@
{{ t('keepRemotePublication') }}
-
+
{{ t('keepRemotePublicationNote') }}
diff --git a/worker/config/development.mjs b/worker/config/development.mjs index 728c6bb..e457c8a 100644 --- a/worker/config/development.mjs +++ b/worker/config/development.mjs @@ -8,7 +8,8 @@ const dfPort = process.env.DF_PORT ?? '8081' export default { cipherPassword: 'dev', dataDir: '../data/development', - dataFairAPIKey: '', // override in worker/config/local-development.cjs to work on publications + // seeded into data-fair's settings by tests/state-setup.ts (idempotent) + dataFairAPIKey: 'dev-test-catalogs-worker-key', host: `${devHost}:${nginxPort}`, mongoUrl: `mongodb://localhost:${mongoPort}/data-fair-catalogs-development`, observer: {