Compare commits

...

20 Commits

Author SHA1 Message Date
9d0a0a9cab Fixed path issues
All checks were successful
Build and publish / Git Tag (push) Successful in 3s
Build and publish / Build Container (push) Successful in 18s
2025-04-17 12:21:41 -04:00
f89b1721f9 Fixed environment setup
All checks were successful
Build and publish / Git Tag (push) Successful in 3s
Build and publish / Build Container (push) Successful in 20s
2025-04-17 12:19:56 -04:00
b3206a9874 Fixed environment setup 2025-04-17 12:19:14 -04:00
78b9522d03 cleanup
All checks were successful
Build and publish / Git Tag (push) Successful in 3s
Build and publish / Build Container (push) Successful in 18s
2025-04-17 12:12:40 -04:00
a5f809eca5 Finalizing
All checks were successful
Build and publish / Git Tag (push) Successful in 3s
Build and publish / Build Container (push) Successful in 19s
2025-04-17 12:08:52 -04:00
26d16fe0a4 Renamed build
All checks were successful
Build and publish / Git Tag (push) Successful in 3s
Build and publish / Build Container (push) Successful in 19s
2025-04-17 11:49:06 -04:00
f38d22026f Fix missing quotation
All checks were successful
Build Container / Git Tag (push) Successful in 3s
Build Container / Build Container (push) Successful in 19s
2025-04-17 11:43:58 -04:00
f79af61bb5 Fixed version number
Some checks failed
Build Container / Git Tag (push) Successful in 3s
Build Container / Build Container (push) Failing after 15s
2025-04-17 11:42:01 -04:00
50b3b50e07 Fixed version number
Some checks failed
Build Container / Git Tag (push) Successful in 2s
Build Container / Build Container (push) Failing after 16s
2025-04-17 11:37:12 -04:00
57698eca18 Actions: formatting
Some checks failed
Build Container / Git Tag (push) Successful in 2s
Build Container / Build Container (push) Failing after 17s
2025-04-17 11:36:23 -04:00
ca343a95a0 Fixed tag step
All checks were successful
Build Container / Git Tag (push) Successful in 2s
Build Container / Build Container (push) Successful in 19s
2025-04-17 11:35:37 -04:00
0ec98a0793 Actions: Fix version grep
All checks were successful
Build Container / Build Container (push) Successful in 19s
2025-04-17 11:32:42 -04:00
8bf3bd68da Actions: Fix clone
Some checks failed
Build Container / Build Container (push) Failing after 2s
2025-04-17 11:31:33 -04:00
064cb62168 Actions: Better??
Some checks failed
Build Container / Build Container (push) Failing after 2s
2025-04-17 11:30:10 -04:00
7d714cb406 Actions: Fixing git url
All checks were successful
Build Container / Build Container (push) Successful in 2s
Build Container / Git Tag (push) Successful in 2s
2025-04-17 11:10:49 -04:00
969ccb88f8 setting up builds
Some checks failed
Build Container / Build Container (push) Failing after 2s
Build Container / Git Tag (push) Failing after 2s
2025-04-17 11:05:58 -04:00
be145d538a Fixed action directory
Some checks failed
Build Container / Build Container (push) Failing after 2s
Build Container / Git Tag (push) Failing after 2s
2025-04-17 10:55:52 -04:00
19b2c197ad Added actions 2025-04-17 10:54:55 -04:00
96e1d23396 Merge pull request 'Finished exporter' (#1) from development into master
Reviewed-on: #1
2025-04-17 10:40:13 -04:00
e7b80c56cf Finished exporter 2025-04-17 10:39:14 -04:00
10 changed files with 98 additions and 13 deletions

9
.dockerignore Normal file
View File

@ -0,0 +1,9 @@
.github
.idea
vscode
node_modules
Dockerfile
docker-compose.yml
.env*
.dockerignore
.gitignore

1
.env Normal file
View File

@ -0,0 +1 @@
TICKERS=AAPL,GOLD,GOOG,NASD,NVDA

57
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,57 @@
name: Build and publish
run-name: Build and publish
on:
push:
jobs:
container:
name: Build Container
runs-on: ubuntu-latest
container: docker
steps:
- name: Build Container
run: |
git clone -b "${{github.ref_name}}" "$(echo ${{github.server_url}}/${{github.repository}}.git | sed s%://%://${{github.token}}@% )" .
DOCKER_HUB=$([ -n "${{secrets.DOCKER_HUB_USER}}" ] && [ -n "${{secrets.DOCKER_HUB_TOKEN}}" ] && [ -n "${{secrets.DOCKER_HUB_IMAGE}}" ] && echo "true" || echo "false")
REGISTRY="$(echo "${{github.server_url}}" | sed -E 's|https?://||')"
VERSION="$(cat package.json | grep 'version' | grep -Eo '([0-9]+\.?)+(-[0-9a-zA-Z\-\.]+)?')"
docker login -u "${{github.repository_owner}}" -p "${{secrets.DEPLOY_TOKEN}}" "$REGISTRY"
if [ "$DOCKER_HUB" = "true" ]; then docker login -u "${{secrets.DOCKER_HUB_USER}}" -p "${{secrets.DOCKER_HUB_TOKEN}}" docker.io; fi
docker build -t "$REGISTRY/${{github.repository}}:${{github.ref_name}}" .
docker push "$REGISTRY/${{github.repository}}:${{github.ref_name}}"
if [ "$DOCKER_HUB" = "true" ]; then
docker tag "$REGISTRY/${{github.repository}}:${{github.ref_name}}" "docker.io/${{secrets.DOCKER_HUB_IMAGE}}:${{github.ref_name}}"
docker push "docker.io/${{secrets.DOCKER_HUB_IMAGE}}:${{github.ref_name}}"
fi
if [ "${{github.ref_name}}" = "master" ]; then
docker tag "$REGISTRY/${{github.repository}}:${{github.ref_name}}" "$REGISTRY/${{github.repository}}:$VERSION"
docker push "$REGISTRY/${{github.repository}}:$VERSION"
if [ "$DOCKER_HUB" = "true" ]; then
docker tag "$REGISTRY/${{github.repository}}:${{github.ref_name}}" "docker.io/${{secrets.DOCKER_HUB_IMAGE}}:$VERSION"
docker push "docker.io/${{secrets.DOCKER_HUB_IMAGE}}:$VERSION"
fi
docker tag "$REGISTRY/${{github.repository}}:${{github.ref_name}}" "$REGISTRY/${{github.repository}}:latest"
docker push "$REGISTRY/${{github.repository}}:latest"
if [ "$DOCKER_HUB" = "true" ]; then
docker tag "$REGISTRY/${{github.repository}}:${{github.ref_name}}" "docker.io/${{secrets.DOCKER_HUB_IMAGE}}:latest"
docker push "docker.io/${{secrets.DOCKER_HUB_IMAGE}}:latest"
fi
fi
tag:
name: Git Tag
runs-on: ubuntu-latest
container: docker
steps:
- name: Git Tag
run: |
git clone -b "${{github.ref_name}}" "$(echo ${{github.server_url}}/${{github.repository}}.git | sed s%://%://${{github.token}}@% )" .
VERSION="$(cat package.json | grep 'version' | grep -Eo '([0-9]+\.?)+(-[0-9a-zA-Z\-\.]+)?')"
git tag -f $VERSION ${{github.sha}}
git push -f origin $VERSION

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.idea
vscode
node_modules
.env.local

View File

@ -1,10 +1,10 @@
FROM node:alpine
ARG PORT
ARG PORT="3000"
ENV PORT=$PORT
COPY . .
RUN npm install && npm run build
RUN npm install && npm run build && rm -rf src
CMD ["node", "dist/main.js"]
EXPOSE $PORT

0
README.md Normal file
View File

12
package-lock.json generated
View File

@ -12,6 +12,7 @@
"@ztimson/utils": "^0.23.22",
"compression": "^1.7.5",
"cors": "^2.8.5",
"dotenv": "^16.5.0",
"express": "^4.21.2"
},
"devDependencies": {
@ -468,6 +469,17 @@
"node": ">=0.3.1"
}
},
"node_modules/dotenv": {
"version": "16.5.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.5.0.tgz",
"integrity": "sha512-m/C+AwOAr9/W1UOIZUo232ejMNnJAJtYQjUbHoNTBNTJSvqzzDh7vnrei3o3r3m9blf6ZoDkvcw0VmozNRFJxg==",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/dunder-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",

View File

@ -13,6 +13,7 @@
"@ztimson/utils": "^0.23.22",
"compression": "^1.7.5",
"cors": "^2.8.5",
"dotenv": "^16.5.0",
"express": "^4.21.2"
},
"devDependencies": {

View File

@ -1,10 +1,15 @@
import packageJson from '../package.json';
import process from 'node:process';
import * as dotenv from 'dotenv';
// Load `.env`
dotenv.config();
dotenv.config({path: '.env.local', override: true});
export const environment = {
port: process.env['port'] ?? 3000,
port: process.env['PORT'] ? +process.env['PORT'] : 3000,
production: !process.env.NODE_ENV || ['prod', 'production'].includes(process.env.NODE_ENV.toLowerCase()),
tickers: process.env['tickers']?.split(',') ?? [],
token: process.env['token'],
tickers: process.env['TICKERS']?.split(',') || [],
token: process.env['TOKEN'],
version: packageJson.version
}

View File

@ -1,7 +1,8 @@
import compression from 'compression';
import cors from 'cors';
import express from 'express';
import http from 'node:http';
import * as process from 'node:process';
import process from 'node:process';
import {environment} from './environment';
import {errorHandler, errorMiddleware} from './error.middleware';
import {loggerMiddleware} from './logger.middleware';
@ -11,6 +12,7 @@ if(!environment.tickers.length) throw new Error('Please provide a CSV list of ti
const app = express();
const httpServer: http.Server = http.createServer(app);
app.use(cors({origin: '*'}))
app.use(compression());
app.use(loggerMiddleware);
@ -21,20 +23,17 @@ let shuttingDown = false;
if(shuttingDown) return; // Already shutting down
shuttingDown = true;
console.warn(`${signal} Received, shutting down...`);
httpServer.close(() => setTimeout(() => process.exit(128 + value), 1000));
httpServer.close(() => process.exit(128 + value));
});
});
app.get('/', errorHandler(async (req, res) => {
app.get('*', errorHandler(async (req, res) => {
const results = await Promise.all(environment.tickers.map(ticker =>
fetch(`https://finnhub.io/api/v1/quote?symbol=${ticker}&token=${environment.token}`)
.then(resp => resp.json())));
// const metrics = results.map(r => `# HELP stock_price_${result.symbol} Stock price for ${result.symbol}
// # TYPE stock_price_${result.symbol} gauge
// stock_price_${result.symbol} ${result.c}`).join('\n');
const metrics = JSON.stringify(results);
let metrics = '# HELP stock_price Current stock price\n# TYPE stock_price gauge\n';
metrics += results.map((r, i) => `stock_price{ticker="${environment.tickers[i]}"} ${r.c}`).join('\n');
res.contentType('text/plain').send(metrics);
}));