Skip to content

Commit 2801910

Browse files
authored
feat: web-parser as service (#5)
* feat: web-parser as service * chore: k8s * fix: path
1 parent 51dee73 commit 2801910

8 files changed

Lines changed: 126 additions & 7 deletions

File tree

.github/workflows/docker-nightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Set matrix
2727
id: set-matrix
2828
run: |
29-
APPS=("web-app" "web-storefront")
29+
APPS=("web-app" "web-storefront" "web-parser")
3030
CHANGED=()
3131
3232
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then

.github/workflows/docker-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Set package in env
3434
id: set-package
3535
run: |
36-
APPS=("web-app" "web-storefront")
36+
APPS=("web-app" "web-storefront" "web-parser")
3737
MATCH="${{ steps.regex-match.outputs.match }}"
3838
3939
if [ -z "$MATCH" ]; then
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { repository } from '@roll-stack/database'
2+
3+
export default defineEventHandler(async () => {
4+
try {
5+
await repository.checkHealth()
6+
7+
return { ok: true }
8+
} catch (error) {
9+
throw errorResolver(error)
10+
}
11+
})

apps/web-parser/server/routes/index.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

docker/web-parser/Dockerfile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
FROM node:22.17.1-alpine AS base
2+
ENV NODE_OPTIONS="--max_old_space_size=4096"
3+
4+
# Builder stage
5+
FROM base AS builder
6+
WORKDIR /app
7+
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc ./
8+
COPY packages ./packages
9+
COPY apps/web-parser ./apps/web-parser
10+
RUN npm install --ignore-scripts -g pnpm && \
11+
pnpm i --frozen-lockfile && \
12+
pnpm build --filter @roll-stack/web-parser
13+
14+
# Production stage
15+
FROM base AS production
16+
RUN apk add --no-cache curl
17+
WORKDIR /app
18+
19+
# Copy built artifacts from builder
20+
COPY --from=builder /app/apps/web-parser/.output .
21+
COPY docker/web-parser/health-check.sh ./
22+
23+
# Running as non-root is a security best practice
24+
# Make the Health check script executable
25+
RUN addgroup -S appgroup && \
26+
adduser -S appuser -G appgroup && \
27+
chmod +x ./health-check.sh
28+
USER appuser
29+
30+
# Configuration
31+
ARG VERSION=nightly
32+
LABEL maintainer="hmbanan666@hotmail.com" \
33+
description="WebParser" \
34+
version=${VERSION}
35+
ENV VERSION=${VERSION} \
36+
NODE_ENV=production \
37+
PORT=3000 \
38+
HOST=0.0.0.0
39+
40+
EXPOSE 3000
41+
42+
# Health check using exec form
43+
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s \
44+
CMD ["/app/health-check.sh"]
45+
46+
# Run the application
47+
ENTRYPOINT ["node"]
48+
CMD ["/app/server/index.mjs"]

docker/web-parser/health-check.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
curl -f http://localhost:3000/api/health || exit 1

k8s/web-parser/deployment.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: web-parser
5+
namespace: sushi
6+
spec:
7+
selector:
8+
matchLabels:
9+
app: web-parser
10+
replicas: 1
11+
revisionHistoryLimit: 1
12+
minReadySeconds: 20
13+
template:
14+
metadata:
15+
labels:
16+
app: web-parser
17+
spec:
18+
automountServiceAccountToken: false
19+
securityContext:
20+
runAsUser: 1001
21+
fsGroup: 1001
22+
imagePullSecrets:
23+
- name: registry-secret
24+
containers:
25+
- name: web-parser
26+
image: sushi-love.registry.twcstorage.ru/roll-stack/web-parser:nightly
27+
imagePullPolicy: Always
28+
ports:
29+
- containerPort: 3000
30+
envFrom:
31+
- secretRef:
32+
name: web-parser
33+
resources:
34+
limits:
35+
cpu: 1000m
36+
memory: 512Mi
37+
ephemeral-storage: 2Gi
38+
requests:
39+
cpu: 50m
40+
memory: 128Mi
41+
ephemeral-storage: 1Gi
42+
livenessProbe:
43+
httpGet:
44+
port: 3000
45+
path: /api/health
46+
initialDelaySeconds: 60
47+
periodSeconds: 60
48+
timeoutSeconds: 10
49+
securityContext:
50+
allowPrivilegeEscalation: false
51+
readOnlyRootFilesystem: false
52+
runAsNonRoot: true
53+
capabilities:
54+
drop:
55+
- ALL

k8s/web-parser/secret.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: web-parser
5+
namespace: sushi
6+
type: Opaque
7+
stringData:
8+
DATABASE_URL: ''

0 commit comments

Comments
 (0)