Skip to content

Commit 55ef103

Browse files
committed
Add dockerfile & compose file
1 parent 943b71e commit 55ef103

11 files changed

+117
-6
lines changed

.dockerignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# https://docs.docker.com/build/concepts/context/#dockerignore-files
2+
/.ackrc
3+
/.env
4+
/.github
5+
/.gitignore
6+
/apidoc.json
7+
/compose.yml
8+
/Dockerfile
9+
/.dockerignore
10+
/.editorconfig
11+
/node_modules
12+
/nodemon.json
13+
/.tool-versions

.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# https://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
indent_size = 2
8+
indent_style = space
9+
insert_final_newline = true

Dockerfile

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Builder image
2+
# =============
3+
4+
FROM node:22.11.0-alpine AS builder
5+
6+
WORKDIR /app
7+
8+
COPY package.json package-lock.json ./
9+
RUN npm ci
10+
11+
COPY prisma/ /app/prisma/
12+
RUN npx prisma generate
13+
14+
COPY . .
15+
RUN npm prune --production
16+
17+
# Production image
18+
# ================
19+
20+
FROM node:22.11.0-alpine
21+
22+
ENV NODE_ENV=production \
23+
PORT=3000
24+
25+
LABEL org.opencontainers.image.authors="[email protected]"
26+
27+
WORKDIR /app
28+
29+
RUN addgroup -S qimg && \
30+
adduser -D -G qimg -H -s /usr/bin/nologin -S qimg && \
31+
chown qimg:qimg /app
32+
33+
USER qimg:qimg
34+
35+
COPY docker/entrypoint /usr/local/bin/entrypoint
36+
COPY --chown=qimg:qimg --from=builder /app /app
37+
38+
ENTRYPOINT ["/usr/local/bin/entrypoint"]
39+
CMD ["node", "./bin/start.js"]
40+
41+
EXPOSE 3000

bin/start.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import http from "http";
55
import app from "../app.js";
66
import { port } from "../lib/config.js";
77

8-
const debug = createDebugger("q-img:server");
8+
const debug = createDebugger("qimg:server");
99

1010
app.set("port", port);
1111

compose.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: archioweb-qimg
2+
3+
services:
4+
app:
5+
build:
6+
context: .
7+
image: archioweb/qimg
8+
depends_on:
9+
- db
10+
environment:
11+
DEBUG: qimg:*
12+
QIMG_ADMIN_TOKEN:
13+
QIMG_BASE_URL:
14+
QIMG_DATABASE_URL: postgresql://qimg:${QIMG_DATABASE_PASSWORD}@db/qimg
15+
QIMG_IMAGE_MAX_SIZE:
16+
QIMG_IMAGE_QUOTA:
17+
init: true
18+
networks:
19+
- app
20+
- db
21+
ports:
22+
- '${QIMG_PORT:-3000}:3000'
23+
restart: on-failure
24+
25+
db:
26+
image: postgres:17.2-alpine
27+
environment:
28+
POSTGRES_PASSWORD: ${QIMG_DATABASE_PASSWORD}
29+
POSTGRES_USER: qimg
30+
POSTGRES_DB: qimg
31+
networks:
32+
- db
33+
restart: on-failure
34+
volumes:
35+
- db-data:/var/lib/postgresql/data
36+
37+
networks:
38+
app:
39+
db:
40+
41+
volumes:
42+
db-data:

docker/entrypoint

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#/bin/bash
2+
set -e
3+
cd /app
4+
npx prisma migrate deploy
5+
exec "$@"

lib/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ try {
55
// Do nothing if dotenv is not available
66
}
77

8-
dotenv.config();
8+
dotenv?.config();
99

1010
export const port = parseEnvPort('QIMG_PORT') ?? parseEnvPort('PORT') ?? 3000;
1111

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"type": "module",
66
"scripts": {
7-
"dev": "cross-env DEBUG=q-img:* nodemon",
7+
"dev": "cross-env DEBUG=qimg:* nodemon",
88
"deploy": "npm run migrate doc",
99
"migrate": "prisma migrate deploy",
1010
"doc": "apidoc -i ./ -o ./doc",

prisma/schema.prisma

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ datasource db {
44
}
55

66
generator client {
7-
provider = "prisma-client-js"
7+
provider = "prisma-client-js"
8+
binaryTargets = ["darwin", "linux-musl-openssl-3.0.x", "native"]
89
}
910

1011
model Token {

routes/images.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { upload } from "../lib/upload.js";
1010
import { asyncHandler, sendError } from "../lib/utils.js";
1111

1212
const router = express.Router();
13-
const debug = createDebugger("q-img:images");
13+
const debug = createDebugger("qimg:images");
1414

1515
/**
1616
* @api {get} /api/images/ Retrieve all images for a user

routes/tokens.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { authenticate, requireAdmin } from "../lib/auth.js";
88
import { asyncHandler, sendError } from "../lib/utils.js";
99

1010
const router = express.Router();
11-
const debug = createDebugger("q-img:tokens");
11+
const debug = createDebugger("qimg:tokens");
1212

1313
/**
1414
* @api {get} /api/tokens/ Retrieve all tokens

0 commit comments

Comments
 (0)