Skip to content

Commit

Permalink
Use Task and Bun workspaces instead of nx
Browse files Browse the repository at this point in the history
  • Loading branch information
unkhz committed Aug 4, 2024
1 parent e4e7d3a commit 179c560
Show file tree
Hide file tree
Showing 53 changed files with 165 additions and 17,146 deletions.
8 changes: 8 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Shared
TENANT_ID=dev
REDIS_HOST=localhost
REDIS_PORT=6379

# Gatherer STDIN
INFLUXDB_MEASUREMENT=ruuvipuserrin-rH48dag03

# Postgres
PG_HOST=127.0.0.1
PG_PORT=5432
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ jobs:
- configurator
- gatherer-http
- gatherer-stdin
- listener
- publisher
node-version: [20]

steps:
- uses: actions/checkout@v4
- uses: arduino/setup-task@v2
with:
version: 2.x
version: 3.38.0
- uses: oven-sh/setup-bun@v1
with:
bun-version: 1.1.20
Expand All @@ -45,7 +43,7 @@ jobs:
matrix:
args:
- context: .
image: ghcr.io/unkhz/ruuvipuserrin-base-node
image: ghcr.io/unkhz/ruuvipuserrin-base-bun

uses: ./.github/workflows/build-package.yml
with:
Expand Down Expand Up @@ -96,7 +94,7 @@ jobs:
git add $file
}
update_version_tag ./packages/base-node/.khz-k3s/kustomization.yaml
update_version_tag ./packages/base-bun/.khz-k3s/kustomization.yaml
update_version_tag ./packages/archive/.khz-k3s/kustomization.yaml
update_version_tag ./packages/configurator/.khz-k3s/kustomization.yaml
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Thumbs.db
# Bun
node_modules.bun

# Nx
# Tasks
.env.local

*-secret.yaml
Expand Down
37 changes: 15 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
FROM node:lts-alpine AS buildtime
FROM oven/bun:1.1.20-alpine
WORKDIR /app
COPY package*.json nx.json /app/
COPY package.json bun.lockb /app/

# Add any node packages
COPY packages/archive/*.json /app/packages/archive/
COPY packages/configurator/*.json /app/packages/configurator/
COPY packages/base-node/*.json /app/packages/base-node/
COPY packages/common-archive-client/*.json /app/packages/common-archive-client/
COPY packages/common-data/*.json /app/packages/common-data/
COPY packages/common-postgres/*.json /app/packages/common-postgres/
# Add bun install dependencies
COPY packages/archive/package.json /app/
COPY packages/base-bun/package.json /app/
COPY packages/configurator/package.json /app/
COPY packages/common-archive-client/package.json /app/
COPY packages/common-data/package.json /app/
COPY packages/common-postgres/package.json /app/
COPY packages/gatherer-http/package.json /app/
COPY packages/gatherer-stdin/package.json /app/
COPY packages/publisher/package.json /app/

# Install dev deps for buildtime
RUN npm ci
# Install deps
RUN bun install --frozen-lockfile --production

# Copy source code
COPY packages/archive /app/packages/archive/
COPY packages/configurator /app/packages/configurator/
COPY packages/base-node /app/packages/base-node/
COPY packages/base-bun /app/packages/base-bun/
COPY packages/common-archive-client /app/packages/common-archive-client/
COPY packages/common-data /app/packages/common-data/
COPY packages/common-postgres /app/packages/common-postgres/

# Build any node packages
RUN npx nx run-many --target=node:build --all

# Clean slate for runtime
FROM node:lts-alpine AS runtime
WORKDIR /app
COPY --link --from=buildtime /app/package*.json /app/nx.json /app/
COPY --link --from=buildtime /app/packages /app/packages

# Remove dev deps for runtime
RUN npm ci --omit=dev
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Following shiny tools are used

- [Redis Streams](https://redis.io/docs/data-types/streams/) for durable processing of measurements
- [TimescaleDb](https://www.timescale.com/) for SQL based long term storage of time series data
- [Nx (package based)](https://nx.dev) for monorepo organization and task running
- [Task](https://taskfile.dev/) for task running
- [Bun workspaces](https://bun.sh/docs/install/workspaces) for monorepo organization
- [Bun](https://bun.sh) TypeScript runtime for faster microservices (where necessary APIs are supported)
- [tRPC](https://trpc.io/) type-safe API for exposing database to serverless functions and apps
- [ruuvitag-listener](https://github.com/lautis/ruuvitag-listener) fast readings from Ruuvitag devices, written in Rust
Expand All @@ -28,27 +29,28 @@ Following shiny tools are used
Ensure you have installed following tools in your gateway box (e.g. raspberry pi).

- [Rust](https://rustup.rs/)
- [Node](https://nodejs.org/en/download/)
- [Bun](https://bun.sh/)
- [Redis](https://redis.io/docs/getting-started/installation/install-redis-on-linux/)

Install monorepo dependencies

```
npm install
bun install
```

Run package specific setup scripts

```
npm run setup
task common-data:setup
task infra-redis:setup
```

### Running

Run gateway functionality in gateway box

```
npm run start-gateway
task start-gateway
```

## Architecture
Expand Down
49 changes: 36 additions & 13 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,43 @@
version: '3'

dotenv:
- ../../.env
- ../../.env.local
- .env.local
- .env

includes:
archive: packages/archive/Taskfile.yml
common-archive-client: packages/common-archive-client/Taskfile.yml
common-data: packages/common-data/Taskfile.yml
common-postgres: packages/common-postgres/Taskfile.yml
configurator: packages/configurator/Taskfile.yml
gatherer-stdin: packages/gatherer-stdin/Taskfile.yml
gatherer-http: packages/gatherer-http/Taskfile.yml
infra-postgres: packages/infra-postgres/Taskfile.yml
infra-redis: packages/infra-redis/Taskfile.yml
listener: packages/listener/Taskfile.yml
publisher: packages/publisher/Taskfile.yml
archive:
taskfile: packages/archive/Taskfile.yml
dir: packages/archive
common-archive-client:
taskfile: packages/common-archive-client/Taskfile.yml
dir: packages/common-archive-client
common-data:
taskfile: packages/common-data/Taskfile.yml
dir: packages/common-data
common-postgres:
taskfile: packages/common-postgres/Taskfile.yml
dir: packages/common-postgres
configurator:
taskfile: packages/configurator/Taskfile.yml
dir: packages/configurator
gatherer-stdin:
taskfile: packages/gatherer-stdin/Taskfile.yml
dir: packages/gatherer-stdin
gatherer-http:
taskfile: packages/gatherer-http/Taskfile.yml
dir: packages/gatherer-http
infra-postgres:
taskfile: packages/infra-postgres/Taskfile.yml
dir: packages/infra-postgres
infra-redis:
taskfile: packages/infra-redis/Taskfile.yml
dir: packages/infra-redis
listener:
taskfile: packages/listener/Taskfile.yml
dir: packages/listener
publisher:
taskfile: packages/publisher/Taskfile.yml
dir: packages/publisher

tasks:
run_parallel:
Expand All @@ -38,6 +60,7 @@ tasks:
- task: run_parallel
vars:
TASKS: >
listener:start
gatherer-stdin:start
gatherer-http:start
publisher:start
Expand Down
Binary file added bun.lockb
Binary file not shown.
31 changes: 0 additions & 31 deletions nx.json

This file was deleted.

Loading

0 comments on commit 179c560

Please sign in to comment.