From 7629735334c2bb5c742bd1b4943d5e0ec73e7485 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Fri, 13 Sep 2024 01:32:51 +0200 Subject: [PATCH] init --- .dockerignore | 2 ++ .editorconfig | 16 +++++++++ .github/dependabot.yml | 11 ++++++ .github/workflows/build-publish.yml | 54 +++++++++++++++++++++++++++++ .github/workflows/test.yml | 32 +++++++++++++++++ .gitignore | 8 +++++ Dockerfile | 27 +++++++++++++++ cli.js | 40 +++++++++++++++++++++ eslint.config.mjs | 22 ++++++++++++ index.js | 1 + license.md | 5 +++ package.json | 50 ++++++++++++++++++++++++++ readme.md | 38 ++++++++++++++++++++ test/index.sh | 7 ++++ 14 files changed, 313 insertions(+) create mode 100644 .dockerignore create mode 100644 .editorconfig create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/build-publish.yml create mode 100644 .github/workflows/test.yml create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100755 cli.js create mode 100644 eslint.config.mjs create mode 100644 index.js create mode 100644 license.md create mode 100644 package.json create mode 100644 readme.md create mode 100755 test/index.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..85dcc16 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.git +node_modules diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..d9e8230 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +# editorconfig.org +root = true + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[**.{js, json}] +indent_style = tab +indent_size = 4 + +[**.{yml,yaml}] +indent_style = spaces +indent_size = 2 diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..fe2cf32 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +version: 2 +updates: + - package-ecosystem: npm + directory: '/' + schedule: + interval: weekly + commit-message: + include: scope + ignore: + - dependency-name: "*" + update-types: ["version-update:semver-patch", "version-update:semver-minor"] diff --git a/.github/workflows/build-publish.yml b/.github/workflows/build-publish.yml new file mode 100644 index 0000000..94dbac2 --- /dev/null +++ b/.github/workflows/build-publish.yml @@ -0,0 +1,54 @@ +name: build & publish Docker image + +on: + push: + tags: + - '*' + +jobs: + lint-test: + name: lint & test + uses: './.github/workflows/test.yml' + + build-publish: + name: build & publish Docker image + needs: + - lint-test + runs-on: ubuntu-latest + permissions: + packages: write + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: log into the GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} + + - name: compute Docker image OCI metadata from commit & repo + id: docker-metadata + uses: docker/metadata-action@v5 + with: + labels: | + org.opencontainers.image.version=${{ github.ref_name }} + + - name: set up Docker buildx + uses: docker/setup-buildx-action@v3 + - name: set up QEMU for cross-platform builds + uses: docker/setup-qemu-action@v3 + + - name: build and push Docker image + uses: docker/build-push-action@v5 + with: + push: true + tags: | + ghcr.io/${{ github.repository }}:latest + ghcr.io/${{ github.repository }}:${{ github.ref_name }} + labels: ${{ steps.docker-metadata.outputs.labels }} + platforms: linux/amd64,linux/arm64 + # https://docs.docker.com/build/ci/github-actions/cache/#cache-backend-api + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..6aa9b8a --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,32 @@ +name: lint & test + +on: + push: + branches: + - '*' + pull_request: + branches: + - '*' + # make this workflow callable from other workflows + workflow_call: + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: + - '20' + - '22' + + steps: + - name: checkout + uses: actions/checkout@v4 + - name: setup Node v${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + + - run: npm run lint + - run: npm test diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1685aa6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +Thumbs.db + +.nvm-version +node_modules + +/package-lock.json +/yarn.lock diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cb4c75e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +# syntax=docker/dockerfile:1.6 +# ^ needed for ADD --checksum=… + +FROM node:22-alpine as builder +WORKDIR /app + +RUN npm install --production + +# --- + +FROM node:22-alpine +WORKDIR /app + +LABEL org.opencontainers.image.title="nats-consuming-gtfs-rt-server" +LABEL org.opencontainers.image.description="Reads DIFFERENTIAL-mode GTFS Realtime data from NATS message broker, and serves it as FULL_DATASET via HTTP." +LABEL org.opencontainers.image.authors="Verkehrsverbund Berlin Brandenburg " + +# install dependencies +COPY --from=builder /app/node_modules ./node_modules + +# add source code +ADD . /app + +# CLI smoke test +RUN ./cli.js --help >/dev/null + +ENTRYPOINT [ "./cli.js"] diff --git a/cli.js b/cli.js new file mode 100755 index 0000000..f92c692 --- /dev/null +++ b/cli.js @@ -0,0 +1,40 @@ +#!/usr/bin/env node + +import {parseArgs} from 'node:util' + +// todo: use import assertions once they're supported by Node.js & ESLint +// https://github.com/tc39/proposal-import-assertions +import {createRequire} from 'node:module' +const require = createRequire(import.meta.url) +const pkg = require('./package.json') + +const { + values: flags, + positionals: args, +} = parseArgs({ + options: { + 'help': { + type: 'boolean', + short: 'h', + }, + 'version': { + type: 'boolean', + short: 'v', + }, + }, + allowPositionals: true, +}) + +if (flags.help) { + process.stdout.write(` +todo +\n`) + process.exit(0) +} + +if (flags.version) { + process.stdout.write(`${pkg.name} v${pkg.version}\n`) + process.exit(0) +} + +// todo diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..bf4b2e0 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,22 @@ +import eslint from '@eslint/js' +import globals from 'globals' + +export default [ + eslint.configs.recommended, + { + languageOptions: { + ecmaVersion: 2022, + globals: globals.node, + }, + rules: { + 'no-unused-vars': [ + 'error', + { + vars: 'all', + args: 'none', + ignoreRestSiblings: false + }, + ], + }, + }, +] diff --git a/index.js b/index.js new file mode 100644 index 0000000..65b3dba --- /dev/null +++ b/index.js @@ -0,0 +1 @@ +// todo diff --git a/license.md b/license.md new file mode 100644 index 0000000..732e7f5 --- /dev/null +++ b/license.md @@ -0,0 +1,5 @@ +Copyright (c) 2024, Jannis R + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/package.json b/package.json new file mode 100644 index 0000000..85bb198 --- /dev/null +++ b/package.json @@ -0,0 +1,50 @@ +{ + "name": "nats-consuming-gtfs-rt-server", + "description": "Reads DIFFERENTIAL-mode GTFS Realtime data from NATS message broker, and serves it as FULL_DATASET via HTTP.", + "version": "1.0.0", + "preferGlobal": true, + "type": "module", + "main": "index.js", + "bin": { + "send-vdv-453-data-to-nats": "./cli.js" + }, + "files": [ + "cli.js", + "index.js", + "lib" + ], + "keywords": [ + "vdv 453", + "vdv 454", + "realtime", + "public transport", + "transit", + "nats" + ], + "author": "Verkehrsverbund Berlin Brandenburg ", + "contributors": [ + "Jannis R " + ], + "homepage": "https://github.com/OpenDataVBB/nats-consuming-gtfs-rt-server", + "repository": { + "type": "git", + "url": "git+https://github.com/OpenDataVBB/nats-consuming-gtfs-rt-server.git" + }, + "bugs": "https://github.com/OpenDataVBB/nats-consuming-gtfs-rt-server/issues", + "license": "ISC", + "engines": { + "node": ">=22" + }, + "dependencies": { + }, + "devDependencies": { + "@eslint/js": "^9.0.0", + "eslint": "^9.0.0", + "globals": "^15.0.0" + }, + "scripts": { + "test": "./test/index.sh", + "lint": "eslint .", + "prepublishOnly": "npm run lint && npm test" + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..4579de6 --- /dev/null +++ b/readme.md @@ -0,0 +1,38 @@ +# nats-consuming-gtfs-rt-server + +**Reads a continuous stream of [GTFS Realtime (GTFS-RT)](https://developers.google.com/transit/gtfs-realtime/) data with [`DIFFERENTIAL` incrementality](https://gtfs.org/documentation/realtime/reference/#enum-incrementality), converts it into a single [`FULL_DATASET`](https://gtfs.org/documentation/realtime/reference/#enum-incrementality) GTFS-RT feed, and serves it via HTTP.** + +![ISC-licensed](https://img.shields.io/github/license/OpenDataVBB/nats-consuming-gtfs-rt-server.svg) + + +## Installation + +```shell +npm install -g OpenDataVBB/nats-consuming-gtfs-rt-server +``` + + +## Getting Started + +```shell +# todo +``` + + +## Usage + +``` +todo +``` + + +## Related + +- [`gtfs-rt-differential-to-full-dataset`](https://github.com/derhuerst/gtfs-rt-differential-to-full-dataset) – Transform a differential GTFS Realtime feed into a full dataset/dump. +- [`gtfs-rt-bindings`](https://github.com/derhuerst/gtfs-rt-bindings) – Parse and serialize GTFS Realtime data encoded as protocol buffers. (third-party) +- [`gtfs-realtime-bindings`](https://npmjs.com/package/gtfs-realtime-bindings) – Javascript classes generated from the GTFS-realtime protocol buffer specification. (official) + + +## Contributing + +If you have a question or need support using `nats-consuming-gtfs-rt-server`, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, use [the issues page](https://github.com/OpenDataVBB/nats-consuming-gtfs-rt-server/issues). diff --git a/test/index.sh b/test/index.sh new file mode 100755 index 0000000..b74de2a --- /dev/null +++ b/test/index.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -eu -o pipefail +cd "$(dirname $0)" +set -x + +# todo