Compare commits
6 Commits
c11a7d47b7
...
1.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 00da4d2abc | |||
| 1bc4b0fb50 | |||
| 768359ad62 | |||
| cbb10361df | |||
| 23cdc27ffd | |||
| 5afd604e85 |
21
.dockerignore
Normal file
21
.dockerignore
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# ignore node_modules, build artifacts, git metadata
|
||||||
|
**/node_modules
|
||||||
|
frontend/dist
|
||||||
|
backend/node_modules
|
||||||
|
.git
|
||||||
|
.vscode
|
||||||
|
.idea
|
||||||
|
.env
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
Dockerfile*
|
||||||
|
docker-compose*.yml
|
||||||
|
|
||||||
|
# Do NOT include runtime backend data in the build context
|
||||||
|
backend/data/
|
||||||
|
backend/data/**
|
||||||
|
|
||||||
|
# keep local dev artifacts out
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
48
.gitea/workflows/publish.yaml
Normal file
48
.gitea/workflows/publish.yaml
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
name: Build and publish Docker image
|
||||||
|
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [published]
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: gitea.kanawave.net
|
||||||
|
REGISTRY_USERNAME: sebastas
|
||||||
|
IMAGE_NAME: ${{ gitea.repository }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
# Permissions are not yet supported in Gitea Actions -> https://github.com/go-gitea/gitea/issues/23642#issuecomment-2119876692
|
||||||
|
# permissions:
|
||||||
|
# contents: read
|
||||||
|
# packages: write
|
||||||
|
# attestations: write
|
||||||
|
# id-token: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Login to registry
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ env.REGISTRY_USERNAME }}
|
||||||
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract metadata (tags, labels)
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v4
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
id: push
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
# file: ./Dockerfile
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
38
Dockerfile
Normal file
38
Dockerfile
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# Build frontend in a dedicated stage
|
||||||
|
FROM node:24-alpine AS frontend-build
|
||||||
|
WORKDIR /app/frontend
|
||||||
|
COPY frontend/package*.json frontend/package-lock*.json ./
|
||||||
|
RUN npm ci --silent
|
||||||
|
COPY frontend/ .
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Final runtime image
|
||||||
|
FROM node:24-alpine
|
||||||
|
WORKDIR /app
|
||||||
|
# copy package manifests and install deps (leverage Docker cache)
|
||||||
|
COPY backend/package*.json backend/package-lock*.json ./backend/
|
||||||
|
RUN cd backend && npm ci --silent
|
||||||
|
# copy backend source (schema, migrations, source)
|
||||||
|
COPY backend ./backend
|
||||||
|
# generate Prisma client against a harmless temp DB path (does not apply migrations)
|
||||||
|
RUN cd backend && DATABASE_URL="file:./data/sqlite.db" npx prisma generate --schema=./prisma/schema.prisma || true
|
||||||
|
# remove devDependencies to slim image
|
||||||
|
RUN cd backend && npm prune --production --silent
|
||||||
|
# install prisma CLI into final image so entrypoint can run migrate deploy at runtime
|
||||||
|
RUN cd backend && npm i --no-audit --no-fund prisma --silent || true
|
||||||
|
# copy entrypoint and make executable
|
||||||
|
COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||||
|
RUN chmod +x /usr/local/bin/entrypoint.sh
|
||||||
|
# Copy built frontend into the expected location: /app/frontend/dist
|
||||||
|
COPY --from=frontend-build /app/frontend/dist ./frontend/dist
|
||||||
|
|
||||||
|
# runtime environment (DATA_DIR used at runtime; DATABASE_URL points to it)
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
ENV DATA_DIR=/data
|
||||||
|
ENV DATABASE_URL="file:${DATA_DIR}/sqlite.db"
|
||||||
|
|
||||||
|
WORKDIR /app/backend
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
||||||
|
CMD ["node", "server.js"]
|
||||||
16
README.md
Normal file
16
README.md
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
Here is example usage of `docker-compose.yml`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
service
|
||||||
|
tally-counter:
|
||||||
|
image: gitea.kanawave.net/sebastas/tally-counter:latest #this image
|
||||||
|
container_name: tally-counter
|
||||||
|
user: 2000:2000 #uid:gid
|
||||||
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
- proxy # traefik proxy network
|
||||||
|
volumes:
|
||||||
|
- ./tally-counter:/data # for persistant storage (db + uploads)
|
||||||
|
```
|
||||||
|
|
||||||
|
Quick and dirty setup!
|
||||||
@@ -7,7 +7,10 @@
|
|||||||
"dev": "nodemon server.js",
|
"dev": "nodemon server.js",
|
||||||
"start": "node server.js",
|
"start": "node server.js",
|
||||||
"prisma:generate": "prisma generate",
|
"prisma:generate": "prisma generate",
|
||||||
"prisma:migrate": "prisma migrate dev --name init"
|
"prisma:migrate-dev": "prisma migrate dev --name init",
|
||||||
|
"prisma:migrate-deploy": "prisma migrate deploy",
|
||||||
|
"prisma:studio": "prisma studio",
|
||||||
|
"prisma:deploy": "npx prisma migrate deploy && npx prisma generate"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@prisma/client": "^6.19.0",
|
"@prisma/client": "^6.19.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
datasource db {
|
datasource db {
|
||||||
provider = "sqlite"
|
provider = "sqlite"
|
||||||
url = "file:../data/sqlite.db"
|
url = env("DATABASE_URL")
|
||||||
}
|
}
|
||||||
|
|
||||||
generator client {
|
generator client {
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ const path = require('path')
|
|||||||
const cors = require('cors')
|
const cors = require('cors')
|
||||||
const { PrismaClient } = require('@prisma/client')
|
const { PrismaClient } = require('@prisma/client')
|
||||||
|
|
||||||
const prisma = new PrismaClient()
|
|
||||||
|
|
||||||
// small, configurable logger used across the app
|
// small, configurable logger used across the app
|
||||||
const LOG_LEVEL = (process.env.LOG_LEVEL || 'info').toLowerCase() // 'error'|'info'|'debug'
|
const LOG_LEVEL = (process.env.LOG_LEVEL || 'info').toLowerCase() // 'error'|'info'|'debug'
|
||||||
const levels = { error: 0, info: 1, debug: 2 }
|
const levels = { error: 0, info: 1, debug: 2 }
|
||||||
@@ -22,14 +20,25 @@ const log = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// store all runtime data under backend/data
|
// store runtime data under DATA_DIR env if provided, else backend/data
|
||||||
const DATA_DIR = path.join(__dirname, 'data')
|
const DATA_DIR = process.env.DATA_DIR
|
||||||
|
? path.resolve(process.env.DATA_DIR)
|
||||||
|
: path.join(__dirname, 'data')
|
||||||
|
|
||||||
const UPLOAD_DIR = path.join(DATA_DIR, 'uploads')
|
const UPLOAD_DIR = path.join(DATA_DIR, 'uploads')
|
||||||
|
|
||||||
// ensure data and upload dirs exist
|
// ensure data and upload dirs exist
|
||||||
if (!fs.existsSync(DATA_DIR)) fs.mkdirSync(DATA_DIR, { recursive: true })
|
if (!fs.existsSync(DATA_DIR)) fs.mkdirSync(DATA_DIR, { recursive: true })
|
||||||
if (!fs.existsSync(UPLOAD_DIR)) fs.mkdirSync(UPLOAD_DIR, { recursive: true })
|
if (!fs.existsSync(UPLOAD_DIR)) fs.mkdirSync(UPLOAD_DIR, { recursive: true })
|
||||||
|
|
||||||
|
// ensure DATABASE_URL points to the DB under DATA_DIR for Prisma at runtime
|
||||||
|
if (!process.env.DATABASE_URL) {
|
||||||
|
process.env.DATABASE_URL = `file:${path.join(DATA_DIR, 'sqlite.db')}`
|
||||||
|
}
|
||||||
|
|
||||||
|
// instantiate Prisma client AFTER DATA_DIR / DATABASE_URL are ready
|
||||||
|
const prisma = new PrismaClient()
|
||||||
|
|
||||||
const upload = multer({ dest: UPLOAD_DIR }) // local storage for uploads
|
const upload = multer({ dest: UPLOAD_DIR }) // local storage for uploads
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
|
|||||||
29
docker/entrypoint.sh
Normal file
29
docker/entrypoint.sh
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
DATA_DIR="${DATA_DIR:-/data}"
|
||||||
|
SCHEMA_PATH="./prisma/schema.prisma"
|
||||||
|
|
||||||
|
# ensure data dir exists and is writable
|
||||||
|
mkdir -p "$DATA_DIR"
|
||||||
|
chmod 0775 "$DATA_DIR" || true
|
||||||
|
|
||||||
|
# ensure DATABASE_URL is set to the runtime DATA_DIR
|
||||||
|
: "${DATABASE_URL:=file:${DATA_DIR}/sqlite.db}"
|
||||||
|
export DATABASE_URL
|
||||||
|
|
||||||
|
# create sqlite file if missing
|
||||||
|
SQLITE_DB_PATH="${DATA_DIR}/sqlite.db"
|
||||||
|
if [ ! -f "$SQLITE_DB_PATH" ]; then
|
||||||
|
touch "$SQLITE_DB_PATH"
|
||||||
|
chmod 0664 "$SQLITE_DB_PATH" || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# run non-interactive migrations if CLI available
|
||||||
|
if command -v npx >/dev/null 2>&1 && [ -f "$SCHEMA_PATH" ]; then
|
||||||
|
echo "Running prisma migrate deploy..."
|
||||||
|
npx prisma migrate deploy --schema="$SCHEMA_PATH" || echo "prisma migrate deploy failed or no migrations to apply"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# exec main process
|
||||||
|
exec "$@"
|
||||||
Reference in New Issue
Block a user