Compare commits
5 Commits
068cca32b4
...
v0.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
| cb37774a3a | |||
| 45350e7a2b | |||
| 8f522046aa | |||
| 5653aca823 | |||
| b1fcea7aea |
138
.dockerignore
Normal file
138
.dockerignore
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
# ---> Node
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
.pnpm-debug.log*
|
||||||
|
|
||||||
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
|
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
*.lcov
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules/
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# Snowpack dependency directory (https://snowpack.dev/)
|
||||||
|
web_modules/
|
||||||
|
|
||||||
|
# TypeScript cache
|
||||||
|
*.tsbuildinfo
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Optional stylelint cache
|
||||||
|
.stylelintcache
|
||||||
|
|
||||||
|
# Microbundle cache
|
||||||
|
.rpt2_cache/
|
||||||
|
.rts2_cache_cjs/
|
||||||
|
.rts2_cache_es/
|
||||||
|
.rts2_cache_umd/
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variable files
|
||||||
|
.env
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
.env.local
|
||||||
|
|
||||||
|
# parcel-bundler cache (https://parceljs.org/)
|
||||||
|
.cache
|
||||||
|
.parcel-cache
|
||||||
|
|
||||||
|
# Next.js build output
|
||||||
|
.next
|
||||||
|
out
|
||||||
|
|
||||||
|
# Nuxt.js build / generate output
|
||||||
|
.nuxt
|
||||||
|
dist
|
||||||
|
|
||||||
|
# Gatsby files
|
||||||
|
.cache/
|
||||||
|
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||||
|
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||||
|
# public
|
||||||
|
|
||||||
|
# vuepress build output
|
||||||
|
.vuepress/dist
|
||||||
|
|
||||||
|
# vuepress v2.x temp and cache directory
|
||||||
|
.temp
|
||||||
|
.cache
|
||||||
|
|
||||||
|
# vitepress build output
|
||||||
|
**/.vitepress/dist
|
||||||
|
|
||||||
|
# vitepress cache directory
|
||||||
|
**/.vitepress/cache
|
||||||
|
|
||||||
|
# Docusaurus cache and generated files
|
||||||
|
.docusaurus
|
||||||
|
|
||||||
|
# Serverless directories
|
||||||
|
.serverless/
|
||||||
|
|
||||||
|
# FuseBox cache
|
||||||
|
.fusebox/
|
||||||
|
|
||||||
|
# DynamoDB Local files
|
||||||
|
.dynamodb/
|
||||||
|
|
||||||
|
# TernJS port file
|
||||||
|
.tern-port
|
||||||
|
|
||||||
|
# Stores VSCode versions used for testing VSCode extensions
|
||||||
|
.vscode-test
|
||||||
|
|
||||||
|
# yarn v2
|
||||||
|
.yarn/cache
|
||||||
|
.yarn/unplugged
|
||||||
|
.yarn/build-state.yml
|
||||||
|
.yarn/install-state.gz
|
||||||
|
.pnp.*
|
||||||
|
|
||||||
39
.gitea/workflows/build-push.yaml
Normal file
39
.gitea/workflows/build-push.yaml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
name: Build and Push container image
|
||||||
|
run-name: ${{ gitea.actor }} is building and pushing
|
||||||
|
|
||||||
|
on:
|
||||||
|
create:
|
||||||
|
tags: "*"
|
||||||
|
|
||||||
|
env:
|
||||||
|
GITEA_DOMAIN: git.fjla.uk
|
||||||
|
GITEA_REGISTRY_USER: owlbot
|
||||||
|
RESULT_IMAGE_NAME: owlboard/data-ingress-pis
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push-image:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: catthehacker/ubuntu:act-latest
|
||||||
|
options: --privileged
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
- name: Login to Gitea Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ env.GITEA_DOMAIN }}
|
||||||
|
username: ${{ env.GITEA_REGISTRY_USER }}
|
||||||
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
- name: Build and Push image
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./Dockerfile
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
${{ env.GITEA_DOMAIN }}/${{ env.RESULT_IMAGE_NAME }}:${{ gitea.ref_name }}
|
||||||
|
${{ env.GITEA_DOMAIN }}/${{ env.RESULT_IMAGE_NAME }}:latest
|
||||||
27
Dockerfile
Normal file
27
Dockerfile
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
FROM node:25-slim AS builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY .npmrc ./
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
|
||||||
|
FROM node:25-slim AS runner
|
||||||
|
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm ci --omit=dev
|
||||||
|
|
||||||
|
COPY --from=builder /app/dist ./dist
|
||||||
|
|
||||||
|
USER node
|
||||||
|
|
||||||
|
CMD ["node", "dist/index.js"]
|
||||||
39
package-lock.json
generated
39
package-lock.json
generated
@@ -11,8 +11,9 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-s3": "^3.964.0",
|
"@aws-sdk/client-s3": "^3.964.0",
|
||||||
"@aws-sdk/lib-storage": "^3.964.0",
|
"@aws-sdk/lib-storage": "^3.964.0",
|
||||||
"@owlboard/backend-data-contracts": "^0.1.0",
|
"@owlboard/backend-data-contracts": "^0.1.9",
|
||||||
"mongodb": "^7.0.0",
|
"mongodb": "^7.0.0",
|
||||||
|
"nats": "^2.29.3",
|
||||||
"readline": "^1.3.0",
|
"readline": "^1.3.0",
|
||||||
"xxhashjs": "^0.2.2"
|
"xxhashjs": "^0.2.2"
|
||||||
},
|
},
|
||||||
@@ -1394,9 +1395,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@owlboard/backend-data-contracts": {
|
"node_modules/@owlboard/backend-data-contracts": {
|
||||||
"version": "0.1.0",
|
"version": "0.1.9",
|
||||||
"resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fbackend-data-contracts/-/0.1.0/backend-data-contracts-0.1.0.tgz",
|
"resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fbackend-data-contracts/-/0.1.9/backend-data-contracts-0.1.9.tgz",
|
||||||
"integrity": "sha512-6cJg7l7i8+iogU5nzvXct1+MQLmqgwcC3I7aS8MAHiDE3ymnLBhpaFKNfz6zkG39KQbA0XGhtoQD1dlKZzLXfw==",
|
"integrity": "sha512-sKIogfclUKSwIvcPFQmJfpVMGLR1XbqMhyL1qNlKFWqWqATCrgKdboArwj5AfTjEC8hDUp8x0ffaRL+hQphXoQ==",
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
"node_modules/@smithy/abort-controller": {
|
"node_modules/@smithy/abort-controller": {
|
||||||
@@ -2405,6 +2406,30 @@
|
|||||||
"node": ">=20.19.0"
|
"node": ">=20.19.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/nats": {
|
||||||
|
"version": "2.29.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/nats/-/nats-2.29.3.tgz",
|
||||||
|
"integrity": "sha512-tOQCRCwC74DgBTk4pWZ9V45sk4d7peoE2njVprMRCBXrhJ5q5cYM7i6W+Uvw2qUrcfOSnuisrX7bEx3b3Wx4QA==",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"dependencies": {
|
||||||
|
"nkeys.js": "1.1.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 14.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/nkeys.js": {
|
||||||
|
"version": "1.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/nkeys.js/-/nkeys.js-1.1.0.tgz",
|
||||||
|
"integrity": "sha512-tB/a0shZL5UZWSwsoeyqfTszONTt4k2YS0tuQioMOD180+MbombYVgzDUYHlx+gejYK6rgf08n/2Df99WY0Sxg==",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"dependencies": {
|
||||||
|
"tweetnacl": "1.0.3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/punycode": {
|
"node_modules/punycode": {
|
||||||
"version": "2.3.1",
|
"version": "2.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz",
|
||||||
@@ -2542,6 +2567,12 @@
|
|||||||
"fsevents": "~2.3.3"
|
"fsevents": "~2.3.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/tweetnacl": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz",
|
||||||
|
"integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==",
|
||||||
|
"license": "Unlicense"
|
||||||
|
},
|
||||||
"node_modules/typescript": {
|
"node_modules/typescript": {
|
||||||
"version": "5.9.3",
|
"version": "5.9.3",
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"prebuild": "rm -rf ./dist",
|
||||||
|
"build": "tsc",
|
||||||
|
"start": "node dist/index.js",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -21,8 +24,9 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-s3": "^3.964.0",
|
"@aws-sdk/client-s3": "^3.964.0",
|
||||||
"@aws-sdk/lib-storage": "^3.964.0",
|
"@aws-sdk/lib-storage": "^3.964.0",
|
||||||
"@owlboard/backend-data-contracts": "^0.1.0",
|
"@owlboard/backend-data-contracts": "^0.1.9",
|
||||||
"mongodb": "^7.0.0",
|
"mongodb": "^7.0.0",
|
||||||
|
"nats": "^2.29.3",
|
||||||
"readline": "^1.3.0",
|
"readline": "^1.3.0",
|
||||||
"xxhashjs": "^0.2.2"
|
"xxhashjs": "^0.2.2"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ import { log } from "./logger";
|
|||||||
|
|
||||||
const uri = process.env.MONGO_URI || "";
|
const uri = process.env.MONGO_URI || "";
|
||||||
const db = process.env.MONGO_DB || "";
|
const db = process.env.MONGO_DB || "";
|
||||||
const collection = process.env.MONGO_COLLECTION || "";
|
|
||||||
const user = process.env.MONGO_USER || "";
|
const user = process.env.MONGO_USER || "";
|
||||||
const pass = process.env.MONGO_PASS || "";
|
const pass = process.env.MONGO_PASS || "";
|
||||||
|
const collection = "data_ingress_meta";
|
||||||
|
|
||||||
if(!uri || !db || !collection || !user || !pass) {
|
if(!uri || !db || !user || !pass) {
|
||||||
log('ERROR', "Missing MONGO Configuration - EXIT CODE: 35");
|
log('ERROR', "Missing MONGO Configuration - EXIT CODE: 35");
|
||||||
process.exit(35);
|
process.exit(35);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
62
src/nats.ts
Normal file
62
src/nats.ts
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import { connect, JSONCodec } from "nats";
|
||||||
|
import type { ConnectionOptions, NatsConnection, Payload } from "nats";
|
||||||
|
import { log } from "./logger";
|
||||||
|
import { hostname } from "node:os";
|
||||||
|
import type { MQFileUpdate } from "@owlboard/backend-data-contracts/dist/data-ingress_mq-file-update";
|
||||||
|
|
||||||
|
const jc = JSONCodec();
|
||||||
|
|
||||||
|
async function getNatsConnection(): Promise<NatsConnection> {
|
||||||
|
const serverUrl = process.env.MQ_URL || "nats://localhost:4222";
|
||||||
|
|
||||||
|
const options: ConnectionOptions = {
|
||||||
|
servers: serverUrl,
|
||||||
|
name: hostname(),
|
||||||
|
reconnect: true,
|
||||||
|
maxReconnectAttempts: -1,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (process.env.MQ_USER && process.env.MQ_PASS) {
|
||||||
|
options.user = process.env.MQ_USER;
|
||||||
|
options.pass = process.env.MQ_PASS;
|
||||||
|
log("INFO", "NATS: Using username/password authentication");
|
||||||
|
} else {
|
||||||
|
log("INFO", "NATS: Connecting without authentication");
|
||||||
|
}
|
||||||
|
|
||||||
|
return await connect(options)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send Message Function here to send the message to NATS
|
||||||
|
export async function sendFileUpdateMessage(path: string, version: string): Promise<boolean> {
|
||||||
|
const serviceName: string = "pis-data-ingress";
|
||||||
|
const serviceId: string = hostname();
|
||||||
|
const message: MQFileUpdate = {
|
||||||
|
service_name: "pis-data-ingress",
|
||||||
|
service_id: serviceId,
|
||||||
|
sent_timestamp: Math.floor(Date.now() / 1000),
|
||||||
|
data_type: "file",
|
||||||
|
data_kind: "pis",
|
||||||
|
payload: {
|
||||||
|
version: version,
|
||||||
|
filepath: path,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let nats: NatsConnection | undefined;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const nats: NatsConnection = await getNatsConnection();
|
||||||
|
|
||||||
|
const subject = `ingress.file.${message.data_kind}`;
|
||||||
|
|
||||||
|
nats.publish(subject, jc.encode(message));
|
||||||
|
|
||||||
|
await nats.drain();
|
||||||
|
return true
|
||||||
|
} catch (err) {
|
||||||
|
log("ERROR", `NATS: Failed to send message: ${err}`);
|
||||||
|
if (nats) {nats.close()}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user