🐋 Docker and Gitea Workflow
All checks were successful
Deploy application / deploy (push) Successful in 19s

- Moved tsx to dependencies as node TS support is 💩
- Renamed start-once to run-once
- TODOs
This commit is contained in:
Martin Berg Alstad 2025-01-26 17:41:44 +01:00
parent 2e73baf98b
commit aaa85e99cb
Signed by: martials
GPG Key ID: A3824877B269F2E2
8 changed files with 89 additions and 7 deletions

10
.dockerignore Normal file
View File

@ -0,0 +1,10 @@
.cache
.idea
httpRequests
.env.*
*.sqlite
jest.config.ts
node_modules
.git
.gitignore
*.md

View File

@ -0,0 +1,34 @@
name: Deploy application
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: host
env:
# Actual budget
ACTUAL_BUDGET_ID: ${{ secrets.ACTUAL_BUDGET_ID }}
ACTUAL_SYNC_ID: ${{ secrets.ACTUAL_SYNC_ID }}
ACTUAL_SERVER_URL: ${{ secrets.ACTUAL_SERVER_URL }}
ACTUAL_PASSWORD: ${{ secrets.ACTUAL_PASSWORD }}
ACTUAL_ACCOUNT_IDS: ${{ secrets.ACTUAL_ACCOUNT_IDS }}
ACTUAL_DATA_DIR: ${{ var.ACTUAL_DATA_DIR }}
# Bank
BANK_INITIAL_REFRESH_TOKEN: ${{ secrets.BANK_INITIAL_REFRESH_TOKEN }}
BANK_OAUTH_CLIENT_ID: ${{ secrets.BANK_OAUTH_CLIENT_ID }}
BANK_OAUTH_CLIENT_SECRET: ${{ secrets.BANK_OAUTH_CLIENT_SECRET }}
BANK_OAUTH_STATE: ${{ secrets.BANK_OAUTH_STATE }}
BANK_OAUTH_REDIRECT_URI: ${{ secrets.BANK_OAUTH_REDIRECT_URI }}
BANK_ACCOUNT_IDS: ${{ secrets.BANK_ACCOUNT_IDS }}
# Configuration
LOG_LEVEL: ${{ var.LOG_LEVEL }}
DB_FILENAME: ${{ var.DB_FILENAME }}
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Run docker-compose
run: docker compose up -d --build

11
Dockerfile Normal file
View File

@ -0,0 +1,11 @@
FROM node:22-slim
LABEL authors="Martin Berg Alstad"
COPY . .
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
CMD ["pnpm", "start-prod"]

View File

@ -24,5 +24,5 @@ pnpm start
Start the application without a CronJob, it will run once, then shutdown.
```shell
pnpm start-once
pnpm run-once
```

22
docker-compose.yml Normal file
View File

@ -0,0 +1,22 @@
services:
# TODO Database in storage
server:
container_name: actual_budget_sparebank1
restart: no # TODO unless-stopped
build:
context: .
environment:
- ACTUAL_BUDGET_ID
- ACTUAL_SYNC_ID
- ACTUAL_SERVER_URL
- ACTUAL_PASSWORD
- ACTUAL_ACCOUNT_IDS
- ACTUAL_DATA_DIR
- BANK_INITIAL_REFRESH_TOKEN
- BANK_OAUTH_CLIENT_ID
- BANK_OAUTH_CLIENT_SECRET
- BANK_OAUTH_STATE
- BANK_OAUTH_REDIRECT_URI
- BANK_ACCOUNT_IDS
- LOG_LEVEL
- DB_FILENAME

View File

@ -6,7 +6,8 @@
"scripts": {
"preinstall": "npx only-allow pnpm",
"start": "dotenvx run --env-file=.env.local -- node --import=tsx ./src/main.ts | pino-pretty",
"start-once": "ONCE=true dotenvx run --env-file=.env.local -- node --import=tsx ./src/main.ts | pino-pretty",
"start-prod": "node --import=tsx ./src/main.ts",
"run-once": "ONCE=true dotenvx run --env-file=.env.local -- node --import=tsx ./src/main.ts | pino-pretty",
"test": "dotenvx run --env-file=.env.test.local -- node --experimental-vm-modules node_modules/jest/bin/jest.js | pino-pretty",
"format": "prettier --write \"./**/*.{js,mjs,ts,md,json}\""
},
@ -21,7 +22,8 @@
"dayjs": "^1.11.13",
"dotenv": "^16.4.7",
"pino": "^9.6.0",
"prettier": "^3.4.2"
"prettier": "^3.4.2",
"tsx": "^4.19.2"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
@ -32,7 +34,6 @@
"pino-pretty": "^13.0.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"tsx": "^4.19.2",
"typescript": "^5.7.3"
},
"prettier": {

6
pnpm-lock.yaml generated
View File

@ -32,6 +32,9 @@ importers:
prettier:
specifier: ^3.4.2
version: 3.4.2
tsx:
specifier: ^4.19.2
version: 4.19.2
devDependencies:
'@jest/globals':
specifier: ^29.7.0
@ -57,9 +60,6 @@ importers:
ts-node:
specifier: ^10.9.2
version: 10.9.2(@types/node@22.10.7)(typescript@5.7.3)
tsx:
specifier: ^4.19.2
version: 4.19.2
typescript:
specifier: ^5.7.3
version: 5.7.3

View File

@ -19,6 +19,10 @@ import * as fs from "node:fs"
import { CronJob } from "cron"
// TODO Transports api for pino https://github.com/pinojs/pino/blob/HEAD/docs/transports.md
// TODO create Dockerfile and docker-compose.yml
// TODO Gitea workflow
// TODO move tsx to devDependency. Requires ts support for Node with support for @ alias
// TODO global exception handler, log and graceful shutdown
export async function daily(actual: Actual, bank: Bank): Promise<void> {
// Fetch transactions from the bank