omgkit 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/plugin/skills/databases/postgresql/SKILL.md +494 -18
- package/plugin/skills/devops/docker/SKILL.md +466 -18
- package/plugin/skills/frameworks/nextjs/SKILL.md +407 -44
- package/plugin/skills/frameworks/react/SKILL.md +1006 -32
- package/plugin/skills/languages/python/SKILL.md +489 -25
- package/plugin/skills/languages/typescript/SKILL.md +379 -30
|
@@ -1,12 +1,41 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: docker
|
|
3
|
-
description: Docker containerization
|
|
3
|
+
description: Docker containerization with best practices for builds, compose, and production deployment
|
|
4
|
+
category: devops
|
|
5
|
+
triggers:
|
|
6
|
+
- docker
|
|
7
|
+
- dockerfile
|
|
8
|
+
- container
|
|
9
|
+
- docker-compose
|
|
10
|
+
- image
|
|
4
11
|
---
|
|
5
12
|
|
|
6
|
-
# Docker
|
|
13
|
+
# Docker
|
|
14
|
+
|
|
15
|
+
Production-grade **Docker containerization** following industry best practices. This skill covers efficient Dockerfiles, multi-stage builds, compose configurations, and deployment patterns.
|
|
16
|
+
|
|
17
|
+
## Purpose
|
|
18
|
+
|
|
19
|
+
Build and deploy containerized applications:
|
|
20
|
+
|
|
21
|
+
- Create efficient Docker images
|
|
22
|
+
- Implement multi-stage builds
|
|
23
|
+
- Configure Docker Compose
|
|
24
|
+
- Handle secrets securely
|
|
25
|
+
- Optimize for production
|
|
26
|
+
- Implement health checks
|
|
27
|
+
|
|
28
|
+
## Features
|
|
29
|
+
|
|
30
|
+
### 1. Multi-Stage Builds
|
|
7
31
|
|
|
8
|
-
## Multi-stage Build
|
|
9
32
|
```dockerfile
|
|
33
|
+
# Node.js Application
|
|
34
|
+
FROM node:20-alpine AS deps
|
|
35
|
+
WORKDIR /app
|
|
36
|
+
COPY package*.json ./
|
|
37
|
+
RUN npm ci --only=production
|
|
38
|
+
|
|
10
39
|
FROM node:20-alpine AS builder
|
|
11
40
|
WORKDIR /app
|
|
12
41
|
COPY package*.json ./
|
|
@@ -14,41 +43,460 @@ RUN npm ci
|
|
|
14
43
|
COPY . .
|
|
15
44
|
RUN npm run build
|
|
16
45
|
|
|
17
|
-
FROM node:20-alpine
|
|
46
|
+
FROM node:20-alpine AS runner
|
|
18
47
|
WORKDIR /app
|
|
19
|
-
|
|
20
|
-
|
|
48
|
+
ENV NODE_ENV=production
|
|
49
|
+
|
|
50
|
+
# Create non-root user
|
|
51
|
+
RUN addgroup --system --gid 1001 nodejs \
|
|
52
|
+
&& adduser --system --uid 1001 nodeuser
|
|
53
|
+
|
|
54
|
+
COPY --from=deps --chown=nodeuser:nodejs /app/node_modules ./node_modules
|
|
55
|
+
COPY --from=builder --chown=nodeuser:nodejs /app/dist ./dist
|
|
56
|
+
COPY --from=builder --chown=nodeuser:nodejs /app/package.json ./
|
|
57
|
+
|
|
58
|
+
USER nodeuser
|
|
21
59
|
EXPOSE 3000
|
|
60
|
+
|
|
61
|
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
62
|
+
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1
|
|
63
|
+
|
|
22
64
|
CMD ["node", "dist/index.js"]
|
|
23
65
|
```
|
|
24
66
|
|
|
25
|
-
|
|
67
|
+
```dockerfile
|
|
68
|
+
# Python Application
|
|
69
|
+
FROM python:3.12-slim AS builder
|
|
70
|
+
WORKDIR /app
|
|
71
|
+
|
|
72
|
+
# Install build dependencies
|
|
73
|
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
74
|
+
build-essential \
|
|
75
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
76
|
+
|
|
77
|
+
# Create virtual environment
|
|
78
|
+
RUN python -m venv /opt/venv
|
|
79
|
+
ENV PATH="/opt/venv/bin:$PATH"
|
|
80
|
+
|
|
81
|
+
COPY requirements.txt .
|
|
82
|
+
RUN pip install --no-cache-dir -r requirements.txt
|
|
83
|
+
|
|
84
|
+
FROM python:3.12-slim AS runner
|
|
85
|
+
WORKDIR /app
|
|
86
|
+
|
|
87
|
+
# Copy virtual environment
|
|
88
|
+
COPY --from=builder /opt/venv /opt/venv
|
|
89
|
+
ENV PATH="/opt/venv/bin:$PATH"
|
|
90
|
+
|
|
91
|
+
# Create non-root user
|
|
92
|
+
RUN useradd --create-home --shell /bin/bash appuser
|
|
93
|
+
USER appuser
|
|
94
|
+
|
|
95
|
+
COPY --chown=appuser:appuser . .
|
|
96
|
+
|
|
97
|
+
EXPOSE 8000
|
|
98
|
+
|
|
99
|
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
100
|
+
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1
|
|
101
|
+
|
|
102
|
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
```dockerfile
|
|
106
|
+
# Go Application
|
|
107
|
+
FROM golang:1.22-alpine AS builder
|
|
108
|
+
WORKDIR /app
|
|
109
|
+
|
|
110
|
+
# Download dependencies
|
|
111
|
+
COPY go.mod go.sum ./
|
|
112
|
+
RUN go mod download
|
|
113
|
+
|
|
114
|
+
COPY . .
|
|
115
|
+
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o /app/server ./cmd/server
|
|
116
|
+
|
|
117
|
+
FROM scratch
|
|
118
|
+
COPY --from=builder /app/server /server
|
|
119
|
+
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
|
120
|
+
|
|
121
|
+
EXPOSE 8080
|
|
122
|
+
ENTRYPOINT ["/server"]
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### 2. Docker Compose
|
|
126
|
+
|
|
26
127
|
```yaml
|
|
128
|
+
# docker-compose.yml
|
|
27
129
|
version: '3.8'
|
|
130
|
+
|
|
28
131
|
services:
|
|
29
132
|
app:
|
|
30
|
-
build:
|
|
133
|
+
build:
|
|
134
|
+
context: .
|
|
135
|
+
dockerfile: Dockerfile
|
|
136
|
+
target: runner
|
|
31
137
|
ports:
|
|
32
138
|
- "3000:3000"
|
|
33
139
|
environment:
|
|
34
|
-
-
|
|
140
|
+
- NODE_ENV=production
|
|
141
|
+
- DATABASE_URL=postgres://postgres:password@db:5432/myapp
|
|
142
|
+
- REDIS_URL=redis://redis:6379
|
|
35
143
|
depends_on:
|
|
36
|
-
|
|
144
|
+
db:
|
|
145
|
+
condition: service_healthy
|
|
146
|
+
redis:
|
|
147
|
+
condition: service_started
|
|
148
|
+
healthcheck:
|
|
149
|
+
test: ["CMD", "wget", "--spider", "-q", "http://localhost:3000/health"]
|
|
150
|
+
interval: 30s
|
|
151
|
+
timeout: 10s
|
|
152
|
+
retries: 3
|
|
153
|
+
start_period: 10s
|
|
154
|
+
restart: unless-stopped
|
|
155
|
+
networks:
|
|
156
|
+
- backend
|
|
157
|
+
deploy:
|
|
158
|
+
resources:
|
|
159
|
+
limits:
|
|
160
|
+
cpus: '1'
|
|
161
|
+
memory: 512M
|
|
162
|
+
reservations:
|
|
163
|
+
cpus: '0.25'
|
|
164
|
+
memory: 128M
|
|
37
165
|
|
|
38
166
|
db:
|
|
39
|
-
image: postgres:
|
|
167
|
+
image: postgres:16-alpine
|
|
40
168
|
environment:
|
|
41
|
-
|
|
169
|
+
POSTGRES_DB: myapp
|
|
170
|
+
POSTGRES_USER: postgres
|
|
171
|
+
POSTGRES_PASSWORD: password
|
|
172
|
+
volumes:
|
|
173
|
+
- postgres_data:/var/lib/postgresql/data
|
|
174
|
+
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
|
|
175
|
+
healthcheck:
|
|
176
|
+
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
|
177
|
+
interval: 10s
|
|
178
|
+
timeout: 5s
|
|
179
|
+
retries: 5
|
|
180
|
+
restart: unless-stopped
|
|
181
|
+
networks:
|
|
182
|
+
- backend
|
|
183
|
+
|
|
184
|
+
redis:
|
|
185
|
+
image: redis:7-alpine
|
|
186
|
+
command: redis-server --appendonly yes
|
|
187
|
+
volumes:
|
|
188
|
+
- redis_data:/data
|
|
189
|
+
healthcheck:
|
|
190
|
+
test: ["CMD", "redis-cli", "ping"]
|
|
191
|
+
interval: 10s
|
|
192
|
+
timeout: 5s
|
|
193
|
+
retries: 5
|
|
194
|
+
restart: unless-stopped
|
|
195
|
+
networks:
|
|
196
|
+
- backend
|
|
197
|
+
|
|
198
|
+
nginx:
|
|
199
|
+
image: nginx:alpine
|
|
200
|
+
ports:
|
|
201
|
+
- "80:80"
|
|
202
|
+
- "443:443"
|
|
42
203
|
volumes:
|
|
43
|
-
-
|
|
204
|
+
- ./nginx.conf:/etc/nginx/nginx.conf:ro
|
|
205
|
+
- ./certs:/etc/nginx/certs:ro
|
|
206
|
+
depends_on:
|
|
207
|
+
- app
|
|
208
|
+
restart: unless-stopped
|
|
209
|
+
networks:
|
|
210
|
+
- backend
|
|
211
|
+
|
|
212
|
+
networks:
|
|
213
|
+
backend:
|
|
214
|
+
driver: bridge
|
|
44
215
|
|
|
45
216
|
volumes:
|
|
46
|
-
|
|
217
|
+
postgres_data:
|
|
218
|
+
redis_data:
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### 3. Development vs Production
|
|
222
|
+
|
|
223
|
+
```yaml
|
|
224
|
+
# docker-compose.override.yml (development)
|
|
225
|
+
version: '3.8'
|
|
226
|
+
|
|
227
|
+
services:
|
|
228
|
+
app:
|
|
229
|
+
build:
|
|
230
|
+
target: builder
|
|
231
|
+
volumes:
|
|
232
|
+
- .:/app
|
|
233
|
+
- /app/node_modules
|
|
234
|
+
environment:
|
|
235
|
+
- NODE_ENV=development
|
|
236
|
+
command: npm run dev
|
|
237
|
+
|
|
238
|
+
db:
|
|
239
|
+
ports:
|
|
240
|
+
- "5432:5432"
|
|
241
|
+
|
|
242
|
+
redis:
|
|
243
|
+
ports:
|
|
244
|
+
- "6379:6379"
|
|
245
|
+
|
|
246
|
+
mailhog:
|
|
247
|
+
image: mailhog/mailhog
|
|
248
|
+
ports:
|
|
249
|
+
- "1025:1025"
|
|
250
|
+
- "8025:8025"
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
```yaml
|
|
254
|
+
# docker-compose.prod.yml
|
|
255
|
+
version: '3.8'
|
|
256
|
+
|
|
257
|
+
services:
|
|
258
|
+
app:
|
|
259
|
+
image: myregistry/myapp:${VERSION:-latest}
|
|
260
|
+
environment:
|
|
261
|
+
- NODE_ENV=production
|
|
262
|
+
deploy:
|
|
263
|
+
replicas: 3
|
|
264
|
+
update_config:
|
|
265
|
+
parallelism: 1
|
|
266
|
+
delay: 10s
|
|
267
|
+
rollback_config:
|
|
268
|
+
parallelism: 1
|
|
269
|
+
delay: 10s
|
|
270
|
+
restart_policy:
|
|
271
|
+
condition: on-failure
|
|
272
|
+
delay: 5s
|
|
273
|
+
max_attempts: 3
|
|
274
|
+
|
|
275
|
+
db:
|
|
276
|
+
environment:
|
|
277
|
+
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
|
|
278
|
+
secrets:
|
|
279
|
+
- db_password
|
|
280
|
+
|
|
281
|
+
secrets:
|
|
282
|
+
db_password:
|
|
283
|
+
external: true
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### 4. Best Practices Dockerfile
|
|
287
|
+
|
|
288
|
+
```dockerfile
|
|
289
|
+
# Use specific version tags
|
|
290
|
+
FROM node:20.10.0-alpine3.19
|
|
291
|
+
|
|
292
|
+
# Set working directory early
|
|
293
|
+
WORKDIR /app
|
|
294
|
+
|
|
295
|
+
# Add metadata labels
|
|
296
|
+
LABEL org.opencontainers.image.source="https://github.com/org/repo" \
|
|
297
|
+
org.opencontainers.image.authors="team@example.com" \
|
|
298
|
+
org.opencontainers.image.version="1.0.0"
|
|
299
|
+
|
|
300
|
+
# Install dependencies first (better caching)
|
|
301
|
+
COPY package*.json ./
|
|
302
|
+
RUN npm ci --only=production \
|
|
303
|
+
&& npm cache clean --force
|
|
304
|
+
|
|
305
|
+
# Copy source code
|
|
306
|
+
COPY . .
|
|
307
|
+
|
|
308
|
+
# Create non-root user
|
|
309
|
+
RUN addgroup --system --gid 1001 appgroup \
|
|
310
|
+
&& adduser --system --uid 1001 --ingroup appgroup appuser \
|
|
311
|
+
&& chown -R appuser:appgroup /app
|
|
312
|
+
|
|
313
|
+
# Switch to non-root user
|
|
314
|
+
USER appuser
|
|
315
|
+
|
|
316
|
+
# Expose port
|
|
317
|
+
EXPOSE 3000
|
|
318
|
+
|
|
319
|
+
# Health check
|
|
320
|
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
321
|
+
CMD node healthcheck.js
|
|
322
|
+
|
|
323
|
+
# Use exec form for CMD
|
|
324
|
+
CMD ["node", "dist/index.js"]
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### 5. .dockerignore
|
|
328
|
+
|
|
329
|
+
```
|
|
330
|
+
# Dependencies
|
|
331
|
+
node_modules
|
|
332
|
+
.npm
|
|
333
|
+
|
|
334
|
+
# Build artifacts
|
|
335
|
+
dist
|
|
336
|
+
build
|
|
337
|
+
.next
|
|
338
|
+
out
|
|
339
|
+
|
|
340
|
+
# Development files
|
|
341
|
+
.git
|
|
342
|
+
.gitignore
|
|
343
|
+
*.md
|
|
344
|
+
docs
|
|
345
|
+
|
|
346
|
+
# IDE
|
|
347
|
+
.vscode
|
|
348
|
+
.idea
|
|
349
|
+
*.swp
|
|
350
|
+
*.swo
|
|
351
|
+
|
|
352
|
+
# Environment
|
|
353
|
+
.env
|
|
354
|
+
.env.*
|
|
355
|
+
!.env.example
|
|
356
|
+
|
|
357
|
+
# Testing
|
|
358
|
+
coverage
|
|
359
|
+
.nyc_output
|
|
360
|
+
*.test.js
|
|
361
|
+
*.spec.js
|
|
362
|
+
__tests__
|
|
363
|
+
|
|
364
|
+
# Docker
|
|
365
|
+
Dockerfile*
|
|
366
|
+
docker-compose*
|
|
367
|
+
.docker
|
|
368
|
+
|
|
369
|
+
# OS
|
|
370
|
+
.DS_Store
|
|
371
|
+
Thumbs.db
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
### 6. Security Scanning
|
|
375
|
+
|
|
376
|
+
```yaml
|
|
377
|
+
# GitHub Actions workflow
|
|
378
|
+
name: Docker Security
|
|
379
|
+
|
|
380
|
+
on:
|
|
381
|
+
push:
|
|
382
|
+
branches: [main]
|
|
383
|
+
pull_request:
|
|
384
|
+
branches: [main]
|
|
385
|
+
|
|
386
|
+
jobs:
|
|
387
|
+
scan:
|
|
388
|
+
runs-on: ubuntu-latest
|
|
389
|
+
steps:
|
|
390
|
+
- uses: actions/checkout@v4
|
|
391
|
+
|
|
392
|
+
- name: Build image
|
|
393
|
+
run: docker build -t myapp:${{ github.sha }} .
|
|
394
|
+
|
|
395
|
+
- name: Run Trivy vulnerability scanner
|
|
396
|
+
uses: aquasecurity/trivy-action@master
|
|
397
|
+
with:
|
|
398
|
+
image-ref: myapp:${{ github.sha }}
|
|
399
|
+
format: 'sarif'
|
|
400
|
+
output: 'trivy-results.sarif'
|
|
401
|
+
severity: 'CRITICAL,HIGH'
|
|
402
|
+
|
|
403
|
+
- name: Upload scan results
|
|
404
|
+
uses: github/codeql-action/upload-sarif@v2
|
|
405
|
+
with:
|
|
406
|
+
sarif_file: 'trivy-results.sarif'
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### 7. Registry and Deployment
|
|
410
|
+
|
|
411
|
+
```bash
|
|
412
|
+
# Build and push
|
|
413
|
+
docker build -t myregistry/myapp:1.0.0 .
|
|
414
|
+
docker push myregistry/myapp:1.0.0
|
|
415
|
+
|
|
416
|
+
# Multi-platform build
|
|
417
|
+
docker buildx build \
|
|
418
|
+
--platform linux/amd64,linux/arm64 \
|
|
419
|
+
-t myregistry/myapp:1.0.0 \
|
|
420
|
+
--push .
|
|
421
|
+
|
|
422
|
+
# Deploy with zero downtime
|
|
423
|
+
docker compose -f docker-compose.prod.yml up -d --no-deps --scale app=3 app
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
## Use Cases
|
|
427
|
+
|
|
428
|
+
### Microservices Setup
|
|
429
|
+
```yaml
|
|
430
|
+
services:
|
|
431
|
+
api-gateway:
|
|
432
|
+
image: nginx:alpine
|
|
433
|
+
ports:
|
|
434
|
+
- "80:80"
|
|
435
|
+
volumes:
|
|
436
|
+
- ./nginx.conf:/etc/nginx/nginx.conf
|
|
437
|
+
|
|
438
|
+
user-service:
|
|
439
|
+
build: ./services/user
|
|
440
|
+
environment:
|
|
441
|
+
- DB_HOST=user-db
|
|
442
|
+
depends_on:
|
|
443
|
+
- user-db
|
|
444
|
+
|
|
445
|
+
order-service:
|
|
446
|
+
build: ./services/order
|
|
447
|
+
environment:
|
|
448
|
+
- DB_HOST=order-db
|
|
449
|
+
- KAFKA_BROKERS=kafka:9092
|
|
450
|
+
depends_on:
|
|
451
|
+
- order-db
|
|
452
|
+
- kafka
|
|
453
|
+
|
|
454
|
+
user-db:
|
|
455
|
+
image: postgres:16-alpine
|
|
456
|
+
|
|
457
|
+
order-db:
|
|
458
|
+
image: postgres:16-alpine
|
|
459
|
+
|
|
460
|
+
kafka:
|
|
461
|
+
image: confluentinc/cp-kafka:latest
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
### CI/CD Pipeline
|
|
465
|
+
```yaml
|
|
466
|
+
build:
|
|
467
|
+
stage: build
|
|
468
|
+
script:
|
|
469
|
+
- docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .
|
|
470
|
+
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
|
|
471
|
+
|
|
472
|
+
deploy:
|
|
473
|
+
stage: deploy
|
|
474
|
+
script:
|
|
475
|
+
- docker stack deploy -c docker-compose.prod.yml myapp
|
|
47
476
|
```
|
|
48
477
|
|
|
49
478
|
## Best Practices
|
|
479
|
+
|
|
480
|
+
### Do's
|
|
50
481
|
- Use specific base image tags
|
|
51
|
-
-
|
|
52
|
-
-
|
|
53
|
-
-
|
|
54
|
-
-
|
|
482
|
+
- Implement multi-stage builds
|
|
483
|
+
- Run as non-root user
|
|
484
|
+
- Add health checks
|
|
485
|
+
- Use .dockerignore
|
|
486
|
+
- Minimize layers
|
|
487
|
+
- Scan for vulnerabilities
|
|
488
|
+
|
|
489
|
+
### Don'ts
|
|
490
|
+
- Don't use latest tag
|
|
491
|
+
- Don't run as root
|
|
492
|
+
- Don't store secrets in images
|
|
493
|
+
- Don't include dev dependencies
|
|
494
|
+
- Don't ignore build cache
|
|
495
|
+
- Don't skip security scans
|
|
496
|
+
|
|
497
|
+
## References
|
|
498
|
+
|
|
499
|
+
- [Docker Documentation](https://docs.docker.com/)
|
|
500
|
+
- [Docker Best Practices](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/)
|
|
501
|
+
- [Docker Compose](https://docs.docker.com/compose/)
|
|
502
|
+
- [Container Security](https://cheatsheetseries.owasp.org/cheatsheets/Docker_Security_Cheat_Sheet.html)
|