diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..e9050286 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +node_modules +npm-debug.log +.git +.gitignore +.env +.env.local +*.md +tests/ +k6/ +coverage +.nyc_output diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..3c48fd1e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +# Stage 1 +FROM node:20-slim AS deps +WORKDIR /app +COPY package*.json ./ +RUN npm ci --omit-dev --no-audit --no-fund || npm install --omit-dev --no-audit --no-fund + +# Stage 2 +FROM node:20-slim AS production +RUN apt-get update && apt-get install -y --no-install-recommends dumb-init && rm -rf /var/lib/apt/lists/* +RUN groupadd -r appuser && useradd -r -g appuser appuser +COPY --from=deps /app/node_modules ./node_modules +COPY . . +ENV NODE_ENV=production +ENV PORT=3000 +HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 CMD node -e "require(http).get(http://localhost:3000/health,r=>process.exit(r.statusCode===200?0:1))" +USER appuser +EXPOSE 3000 +ENTRYPOINT ["dumb-init","--"] +CMD ["node","index.js"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..5e3a3150 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +version: 3.8 +services: + app: + build: + context: . + dockerfile: Dockerfile + ports: + - "3000:3000" + environment: + - NODE_ENV=production + - REDIS_URL=redis://redis:6379 + depends_on: + redis: + condition: service_healthy + restart: unless-stopped + redis: + image: redis:7-alpine + ports: + - "6379:6379" + healthcheck: + test: ["CMD","redis-cli","ping"] + interval: 10s + timeout: 3s + retries: 5 + restart: unless-stopped