Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
node_modules
npm-debug.log
yarn.lock
pnpm-lock.yaml
.git
.github
.vscode
.idea
.env
.env.*
coverage
*.log
dist
k6/results
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM node:20-alpine AS builder

WORKDIR /app

COPY package.json package-lock.json ./
RUN npm ci

COPY . .
RUN npm test

FROM node:20-alpine AS production

WORKDIR /app

ENV NODE_ENV=production

COPY package.json package-lock.json ./
RUN npm ci --omit=dev && npm cache clean --force

COPY --from=builder /app/index.js ./index.js
COPY --from=builder /app/src ./src
COPY --from=builder /app/scripts ./scripts

USER node

EXPOSE 3000

CMD ["node", "index.js"]
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,21 @@ npm ci --production
### Docker

```bash
docker build -t equipchain-backend .
docker run -p 3000:3000 --env-file .env equipchain-backend
docker build -t equipchain-backend:local .
docker run --rm -p 3000:3000 --env-file .env equipchain-backend:local
```

Run the full local stack (API + Redis) with Docker Compose:

```bash
docker compose up --build
```

Helper scripts:

```bash
sh scripts/docker-build.sh
sh scripts/docker-run.sh
```

---
Expand Down Expand Up @@ -603,12 +616,18 @@ Test results (HTML reports, JSON summaries) are stored in `k6/results/`. This di
### Docker (Recommended)

```bash
docker build -t equipchain-backend .
docker build -t equipchain-backend:local .
docker run -d \
--name equipchain-api \
-p 3000:3000 \
--env-file .env \
equipchain-backend
equipchain-backend:local
```

Docker Compose (API + Redis):

```bash
docker compose up -d --build
```

### Cloud Platforms
Expand Down
11 changes: 11 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:
api:
build:
target: builder
environment:
NODE_ENV: ${NODE_ENV:-development}
SKIP_SEED: ${SKIP_SEED:-1}
command: ["node", "--watch", "index.js"]
volumes:
- ./:/app
- /app/node_modules
49 changes: 49 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
services:
api:
build:
context: .
dockerfile: Dockerfile
target: production
image: equipchain-backend:local
environment:
NODE_ENV: ${NODE_ENV:-production}
PORT: ${PORT:-3000}
CONTRACT_ID: ${CONTRACT_ID:-CB7PSJZALNWNX7NLOAM6LOEL4OJZMFPQZJMIYO522ZSACYWXTZIDEDSS}
REDIS_URL: ${REDIS_URL:-redis://redis:6379}
SKIP_SEED: ${SKIP_SEED:-1}
ports:
- "${PORT:-3000}:3000"
depends_on:
redis:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://localhost:3000/api/health > /dev/null || exit 1"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
networks:
- equipchain

redis:
image: redis:7-alpine
command: ["redis-server", "--appendonly", "yes"]
ports:
- "${REDIS_PORT:-6379}:6379"
volumes:
- redis-data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
start_period: 5s
networks:
- equipchain

volumes:
redis-data:

networks:
equipchain:
driver: bridge
4 changes: 4 additions & 0 deletions scripts/docker-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
set -eu

docker build -t equipchain-backend:local .
8 changes: 8 additions & 0 deletions scripts/docker-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env sh
set -eu

if [ -f .env ]; then
docker run --rm -p 3000:3000 --env-file .env equipchain-backend:local
else
docker run --rm -p 3000:3000 equipchain-backend:local
fi
Loading