Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
node_modules
data
**/node_modules
data
dev/logs
test-results
playwright-report
ui/dist
ui/dts
.env
.git
2 changes: 1 addition & 1 deletion .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
npx --no-install commitlint --edit ""
npx --no -- commitlint --edit "$1"
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions api/src/admin/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ router.use(async (req, res, next) => {
next()
})

let info = { version: process.env.NODE_ENV }
let info: Record<string, string> = { 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)
Expand Down
3 changes: 3 additions & 0 deletions tests/state-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()
})
46 changes: 46 additions & 0 deletions tests/support/data-fair.ts
Original file line number Diff line number Diff line change
@@ -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()
}
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"allowJs": true,
"checkJs": true,
"skipLibCheck": true,
"erasableSyntaxOnly": true,
"paths": {
"#api/types": ["./api/types/index.ts"],
"#api/types/*": ["./api/types/*"]
Expand Down
2 changes: 1 addition & 1 deletion ui/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
4 changes: 2 additions & 2 deletions ui/src/components/publication/publication-actions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
<div class="font-weight-medium">
{{ t('deleteRemotePublication') }}
</div>
<div class="text-caption font-italic">
<div class="text-body-small font-italic">
{{ t('deleteRemotePublicationNote') }}
</div>
</div>
Expand All @@ -158,7 +158,7 @@
<div class="font-weight-medium">
{{ t('keepRemotePublication') }}
</div>
<div class="text-caption font-italic">
<div class="text-body-small font-italic">
{{ t('keepRemotePublicationNote') }}
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion worker/config/development.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Loading